Skip to content

Commit c9a3093

Browse files
authored
Merge pull request #388 from microsoftgraph/14.0.0-preview
14.0.0 preview
2 parents cd8f557 + ad37299 commit c9a3093

31 files changed

+509
-157
lines changed

src/Microsoft.Graph.Core/Exceptions/ErrorConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal static class Codes
2222

2323
internal static string TooManyRetries = "tooManyRetries";
2424

25-
25+
internal static string MaximumValueExceeded = "MaximumValueExceeded";
2626
}
2727

2828
internal static class Messages
@@ -53,6 +53,7 @@ internal static class Messages
5353

5454
internal static string UnexpectedExceptionResponse = "Unexpected exception returned from the service.";
5555

56+
internal static string MaximumValueExceeded = "{0} exceeds the maximum value of {1}.";
5657
}
5758
}
5859
}

src/Microsoft.Graph.Core/Extensions/BaseRequestExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public static T WithPerRequestAuthProvider<T>(this T baseRequest) where T : IBas
6262
}
6363

6464
/// <summary>
65-
/// Sets a ShouldRetry <see cref="Func{HttpResponseMessage, Boolean}"/> delegate to the default Retry Middleware Handler for this request.
65+
/// Sets a ShouldRetry <see cref="Func{HttpResponseMessage httpResponseMessage, Boolean}"/> delegate to the default Retry Middleware Handler for this request.
6666
/// This only works with the default Retry Middleware Handler.
6767
/// If you use a custom Retry Middleware Handler, you have to handle it's retreival in your implementation.
6868
/// </summary>
6969
/// <typeparam name="T"></typeparam>
7070
/// <param name="baseRequest">The <see cref="BaseRequest"/> for the request.</param>
7171
/// <param name="shouldRetry">A <see cref="Func{HttpResponseMessage, Boolean}"/> for the request.</param>
7272
/// <returns></returns>
73-
public static T WithShouldRetry<T>(this T baseRequest, Func<HttpResponseMessage, bool> shouldRetry) where T : IBaseRequest
73+
public static T WithShouldRetry<T>(this T baseRequest, Func<int, int, HttpResponseMessage, bool> shouldRetry) where T : IBaseRequest
7474
{
7575
string retryOptionKey = typeof(RetryHandlerOption).ToString();
7676
if (baseRequest.MiddlewareOptions.ContainsKey(retryOptionKey))
@@ -121,11 +121,11 @@ public static T WithMaxRedirects<T>(this T baseRequest, int maxRedirects) where
121121
string redirectOptionKey = typeof(RedirectHandlerOption).ToString();
122122
if (baseRequest.MiddlewareOptions.ContainsKey(redirectOptionKey))
123123
{
124-
(baseRequest.MiddlewareOptions[redirectOptionKey] as RedirectHandlerOption).MaxRedirects = maxRedirects;
124+
(baseRequest.MiddlewareOptions[redirectOptionKey] as RedirectHandlerOption).MaxRedirect = maxRedirects;
125125
}
126126
else
127127
{
128-
baseRequest.MiddlewareOptions.Add(redirectOptionKey, new RedirectHandlerOption { MaxRedirects = maxRedirects });
128+
baseRequest.MiddlewareOptions.Add(redirectOptionKey, new RedirectHandlerOption { MaxRedirect = maxRedirects });
129129
}
130130
return baseRequest;
131131
}

src/Microsoft.Graph.Core/Microsoft.Graph.Core.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
<Description>Microsoft Graph Core Client Library implements core functionality used by Microsoft Graph Client Libraries.</Description>
44
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
55
<AssemblyTitle>Microsoft Graph Core Client Library</AssemblyTitle>
6-
<VersionPrefix>1.13.0</VersionPrefix>
7-
<FileVersion>1.13.0</FileVersion>
8-
<AssemblyVersion>1.13.0</AssemblyVersion>
6+
<VersionPrefix>1.14.0</VersionPrefix>
7+
<FileVersion>1.14.0</FileVersion>
8+
<AssemblyVersion>1.14.0</AssemblyVersion>
99
<Authors>Microsoft</Authors>
1010
<TargetFrameworks>netstandard1.1;net45</TargetFrameworks>
1111
<PreserveCompilationContext>false</PreserveCompilationContext>
1212
<AssemblyName>Microsoft.Graph.Core</AssemblyName>
1313
<PackageId>Microsoft.Graph.Core</PackageId>
1414
<PackageTags>Microsoft Office365;Graph;GraphServiceClient;Outlook;OneDrive;AzureAD;GraphAPI;Productivity;SharePoint;Intune;SDK</PackageTags>
1515
<PackageReleaseNotes>
16-
January 2019 Release Summary (version 1.13.0)
16+
February 2019 Release Summary (version 1.14.0-preview)
1717

1818
- Authentication handler added.
1919
- Removed Newtonsoft.Json package reference upper bound limitation.
@@ -38,7 +38,7 @@ January 2019 Release Summary (version 1.13.0)
3838
<DelaySign>false</DelaySign>
3939
<AssemblyOriginatorKeyFile>35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
4040
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
41-
<Version>1.13.0</Version>
41+
<Version>1.14.0-preview</Version>
4242
</PropertyGroup>
4343
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.1|AnyCPU'">
4444
<DocumentationFile>bin\Release\netstandard1.1\Microsoft.Graph.Core.xml</DocumentationFile>

src/Microsoft.Graph.Core/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
//
2525
// You can specify all the values or you can default the Build and Revision Numbers
2626
// by using the '*' as shown below:
27-
[assembly: AssemblyVersion("1.13.0")]
28-
[assembly: AssemblyFileVersion("1.13.0.0")]
27+
[assembly: AssemblyVersion("1.14.0")]
28+
[assembly: AssemblyFileVersion("1.14.0.0")]
2929

3030
#if DEBUG
3131
[assembly: InternalsVisibleTo("Microsoft.Graph.Core.Test")]

src/Microsoft.Graph.Core/Requests/GraphRequestContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,10 @@ public class GraphRequestContext
3131
/// A FeatureUsage property
3232
/// </summary>
3333
public FeatureFlag FeatureUsage { get; set; }
34+
35+
/// <summary>
36+
/// A <see cref="GraphUserAccount"/> property representing the logged in user
37+
/// </summary>
38+
public GraphUserAccount User { get; set; }
3439
}
3540
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
namespace Microsoft.Graph
6+
{
7+
/// <summary>
8+
/// Class representing the logged in MS graph user
9+
/// </summary>
10+
public class GraphUserAccount
11+
{
12+
/// <summary>
13+
/// The users email address
14+
/// </summary>
15+
public string Email { get; set; }
16+
17+
/// <summary>
18+
/// The identity provider url
19+
/// </summary>
20+
public string Environment { get; set; }
21+
22+
/// <summary>
23+
/// Users tenant id
24+
/// </summary>
25+
public string TenantId { get; set; }
26+
27+
/// <summary>
28+
/// Users id in a tenant
29+
/// </summary>
30+
public string ObjectId { get; set; }
31+
}
32+
}

src/Microsoft.Graph.Core/Requests/MiddlewareOptions/AuthenticationHandlerOption.cs renamed to src/Microsoft.Graph.Core/Requests/Middleware/Options/AuthenticationHandlerOption.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ namespace Microsoft.Graph
1010
public class AuthenticationHandlerOption : IMiddlewareOption
1111
{
1212
/// <summary>
13-
/// An Authentication Provider
13+
/// An authentication provider
1414
/// </summary>
1515
internal IAuthenticationProvider AuthenticationProvider { get; set; }
1616

1717
/// <summary>
18-
/// An auth provider option property
18+
/// An authentication provider option.
1919
/// </summary>
20-
public IAuthProviderOption AuthProviderOption { get; set; }
20+
public IAuthenticationProviderOption AuthenticationProviderOption { get; set; }
2121
}
2222
}

src/Microsoft.Graph.Core/Requests/MiddlewareOptions/IAuthProviderOption.cs renamed to src/Microsoft.Graph.Core/Requests/Middleware/Options/IAuthenticationProviderOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.Graph
88
/// An interface used to pass auth provider options in a request.
99
/// Auth providers will be incharge of implementing this interface and providing <see cref="IBaseRequest"/> extensions to set it's values.
1010
/// </summary>
11-
public interface IAuthProviderOption
11+
public interface IAuthenticationProviderOption
1212
{
1313
/// <summary>
1414
/// Microsoft Graph scopes property.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
using System;
6+
using System.Net.Http;
7+
8+
namespace Microsoft.Graph
9+
{
10+
/// <summary>
11+
/// The redirect middleware option class
12+
/// </summary>
13+
public class RedirectHandlerOption : IMiddlewareOption
14+
{
15+
internal const int DEFAULT_MAX_REDIRECT = 5;
16+
internal const int MAX_MAX_REDIRECT = 20;
17+
/// <summary>
18+
/// Constructs a new <see cref="RedirectHandlerOption"/>
19+
/// </summary>
20+
public RedirectHandlerOption()
21+
{
22+
23+
}
24+
25+
26+
private int _maxRedirect = DEFAULT_MAX_REDIRECT;
27+
28+
/// <summary>
29+
/// The maximum number of redirects with a maximum value of 20. This defaults to 5 redirects.
30+
/// </summary>
31+
public int MaxRedirect
32+
{
33+
get { return _maxRedirect; }
34+
set
35+
{
36+
if (value > MAX_MAX_REDIRECT)
37+
{
38+
throw new ServiceException(
39+
new Error
40+
{
41+
Code = ErrorConstants.Codes.MaximumValueExceeded,
42+
Message = string.Format(ErrorConstants.Messages.MaximumValueExceeded, "MaxRedirect", MAX_MAX_REDIRECT)
43+
});
44+
}
45+
_maxRedirect = value;
46+
}
47+
}
48+
49+
/// <summary>
50+
/// A delegate that's called to determine whether a response should be redirected or not. The delegate method should accept <see cref="HttpResponseMessage"/> as it's parameter and return a <see cref="bool"/>. This defaults to true.
51+
/// </summary>
52+
public Func<HttpResponseMessage, bool> ShouldRedirect { get; set; } = (response) => true;
53+
}
54+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
namespace Microsoft.Graph
6+
{
7+
using System;
8+
using System.Net.Http;
9+
10+
/// <summary>
11+
/// The retry middleware option class
12+
/// </summary>
13+
public class RetryHandlerOption : IMiddlewareOption
14+
{
15+
internal const int DEFAULT_DELAY = 3;
16+
internal const int DEFAULT_MAX_RETRY = 3;
17+
internal const int MAX_MAX_RETRY = 10;
18+
internal const int MAX_DELAY = 180;
19+
20+
/// <summary>
21+
/// Constructs a new <see cref="RetryHandlerOption"/>
22+
/// </summary>
23+
public RetryHandlerOption()
24+
{
25+
}
26+
27+
private int _delay = DEFAULT_DELAY;
28+
/// <summary>
29+
/// The waiting time in seconds before retrying a request with a maximum value of 180 seconds. This defaults to 3 seconds.
30+
/// </summary>
31+
public int Delay
32+
{
33+
get { return _delay; }
34+
set
35+
{
36+
if (value > MAX_DELAY)
37+
{
38+
throw new ServiceException(
39+
new Error
40+
{
41+
Code = ErrorConstants.Codes.MaximumValueExceeded,
42+
Message = string.Format(ErrorConstants.Messages.MaximumValueExceeded, "Delay", MAX_DELAY)
43+
});
44+
}
45+
46+
_delay = value;
47+
}
48+
}
49+
50+
private int _maxRetry = DEFAULT_MAX_RETRY;
51+
/// <summary>
52+
/// The maximum number of retries for a request with a maximum value of 10. This defaults to 3.
53+
/// </summary>
54+
public int MaxRetry
55+
{
56+
get
57+
{
58+
return _maxRetry;
59+
}
60+
set
61+
{
62+
if (value > MAX_MAX_RETRY)
63+
{
64+
throw new ServiceException(
65+
new Error
66+
{
67+
Code = ErrorConstants.Codes.MaximumValueExceeded,
68+
Message = string.Format(ErrorConstants.Messages.MaximumValueExceeded, "MaxRetry", MAX_MAX_RETRY)
69+
});
70+
}
71+
_maxRetry = value;
72+
}
73+
}
74+
75+
/// <summary>
76+
/// A delegate that's called to determine whether a request should be retried or not.
77+
/// The delegate method should accept a delay time in seconds of, number of retry attempts and <see cref="HttpResponseMessage"/> as it's parameters and return a <see cref="bool"/>. This defaults to true
78+
/// </summary>
79+
public Func<int, int, HttpResponseMessage, bool> ShouldRetry { get; set; } = (delay, attempt, response) => true;
80+
}
81+
}

src/Microsoft.Graph.Core/Requests/Handlers/RedirectHandler.cs renamed to src/Microsoft.Graph.Core/Requests/Middleware/RedirectHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
5353
// send request first time to get response
5454
var response = await base.SendAsync(request, cancellationToken);
5555

56-
// check response status code
57-
if (IsRedirect(response.StatusCode))
56+
// check response status code and redirect handler option
57+
if (IsRedirect(response.StatusCode) && RedirectOption.ShouldRedirect(response) && RedirectOption.MaxRedirect > 0)
5858
{
5959
if (response.Headers.Location == null)
6060
{
@@ -68,7 +68,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
6868

6969
var redirectCount = 0;
7070

71-
while (redirectCount < RedirectOption.MaxRedirects)
71+
while (redirectCount < RedirectOption.MaxRedirect)
7272
{
7373
// general clone request with internal CloneAsync (see CloneAsync for details) extension method
7474
var newRequest = await response.RequestMessage.CloneAsync();
@@ -100,6 +100,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
100100
}
101101
redirectCount++;
102102
}
103+
103104
throw new ServiceException(
104105
new Error
105106
{

0 commit comments

Comments
 (0)