Skip to content

Commit

Permalink
Merge pull request #388 from microsoftgraph/14.0.0-preview
Browse files Browse the repository at this point in the history
14.0.0 preview
  • Loading branch information
peombwa authored Feb 25, 2019
2 parents cd8f557 + ad37299 commit c9a3093
Show file tree
Hide file tree
Showing 31 changed files with 509 additions and 157 deletions.
3 changes: 2 additions & 1 deletion src/Microsoft.Graph.Core/Exceptions/ErrorConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class Codes

internal static string TooManyRetries = "tooManyRetries";


internal static string MaximumValueExceeded = "MaximumValueExceeded";
}

internal static class Messages
Expand Down Expand Up @@ -53,6 +53,7 @@ internal static class Messages

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

internal static string MaximumValueExceeded = "{0} exceeds the maximum value of {1}.";
}
}
}
8 changes: 4 additions & 4 deletions src/Microsoft.Graph.Core/Extensions/BaseRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public static T WithPerRequestAuthProvider<T>(this T baseRequest) where T : IBas
}

/// <summary>
/// Sets a ShouldRetry <see cref="Func{HttpResponseMessage, Boolean}"/> delegate to the default Retry Middleware Handler for this request.
/// Sets a ShouldRetry <see cref="Func{HttpResponseMessage httpResponseMessage, Boolean}"/> delegate to the default Retry Middleware Handler for this request.
/// This only works with the default Retry Middleware Handler.
/// If you use a custom Retry Middleware Handler, you have to handle it's retreival in your implementation.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="baseRequest">The <see cref="BaseRequest"/> for the request.</param>
/// <param name="shouldRetry">A <see cref="Func{HttpResponseMessage, Boolean}"/> for the request.</param>
/// <returns></returns>
public static T WithShouldRetry<T>(this T baseRequest, Func<HttpResponseMessage, bool> shouldRetry) where T : IBaseRequest
public static T WithShouldRetry<T>(this T baseRequest, Func<int, int, HttpResponseMessage, bool> shouldRetry) where T : IBaseRequest
{
string retryOptionKey = typeof(RetryHandlerOption).ToString();
if (baseRequest.MiddlewareOptions.ContainsKey(retryOptionKey))
Expand Down Expand Up @@ -121,11 +121,11 @@ public static T WithMaxRedirects<T>(this T baseRequest, int maxRedirects) where
string redirectOptionKey = typeof(RedirectHandlerOption).ToString();
if (baseRequest.MiddlewareOptions.ContainsKey(redirectOptionKey))
{
(baseRequest.MiddlewareOptions[redirectOptionKey] as RedirectHandlerOption).MaxRedirects = maxRedirects;
(baseRequest.MiddlewareOptions[redirectOptionKey] as RedirectHandlerOption).MaxRedirect = maxRedirects;
}
else
{
baseRequest.MiddlewareOptions.Add(redirectOptionKey, new RedirectHandlerOption { MaxRedirects = maxRedirects });
baseRequest.MiddlewareOptions.Add(redirectOptionKey, new RedirectHandlerOption { MaxRedirect = maxRedirects });
}
return baseRequest;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.Graph.Core/Microsoft.Graph.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
<Description>Microsoft Graph Core Client Library implements core functionality used by Microsoft Graph Client Libraries.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<AssemblyTitle>Microsoft Graph Core Client Library</AssemblyTitle>
<VersionPrefix>1.13.0</VersionPrefix>
<FileVersion>1.13.0</FileVersion>
<AssemblyVersion>1.13.0</AssemblyVersion>
<VersionPrefix>1.14.0</VersionPrefix>
<FileVersion>1.14.0</FileVersion>
<AssemblyVersion>1.14.0</AssemblyVersion>
<Authors>Microsoft</Authors>
<TargetFrameworks>netstandard1.1;net45</TargetFrameworks>
<PreserveCompilationContext>false</PreserveCompilationContext>
<AssemblyName>Microsoft.Graph.Core</AssemblyName>
<PackageId>Microsoft.Graph.Core</PackageId>
<PackageTags>Microsoft Office365;Graph;GraphServiceClient;Outlook;OneDrive;AzureAD;GraphAPI;Productivity;SharePoint;Intune;SDK</PackageTags>
<PackageReleaseNotes>
January 2019 Release Summary (version 1.13.0)
February 2019 Release Summary (version 1.14.0-preview)

- Authentication handler added.
- Removed Newtonsoft.Json package reference upper bound limitation.
Expand All @@ -38,7 +38,7 @@ January 2019 Release Summary (version 1.13.0)
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.13.0</Version>
<Version>1.14.0-preview</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.1|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.1\Microsoft.Graph.Core.xml</DocumentationFile>
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Graph.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.13.0")]
[assembly: AssemblyFileVersion("1.13.0.0")]
[assembly: AssemblyVersion("1.14.0")]
[assembly: AssemblyFileVersion("1.14.0.0")]

#if DEBUG
[assembly: InternalsVisibleTo("Microsoft.Graph.Core.Test")]
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Graph.Core/Requests/GraphRequestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ public class GraphRequestContext
/// A FeatureUsage property
/// </summary>
public FeatureFlag FeatureUsage { get; set; }

/// <summary>
/// A <see cref="GraphUserAccount"/> property representing the logged in user
/// </summary>
public GraphUserAccount User { get; set; }
}
}
32 changes: 32 additions & 0 deletions src/Microsoft.Graph.Core/Requests/Middleware/GraphUserAccount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

namespace Microsoft.Graph
{
/// <summary>
/// Class representing the logged in MS graph user
/// </summary>
public class GraphUserAccount
{
/// <summary>
/// The users email address
/// </summary>
public string Email { get; set; }

/// <summary>
/// The identity provider url
/// </summary>
public string Environment { get; set; }

/// <summary>
/// Users tenant id
/// </summary>
public string TenantId { get; set; }

/// <summary>
/// Users id in a tenant
/// </summary>
public string ObjectId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace Microsoft.Graph
public class AuthenticationHandlerOption : IMiddlewareOption
{
/// <summary>
/// An Authentication Provider
/// An authentication provider
/// </summary>
internal IAuthenticationProvider AuthenticationProvider { get; set; }

/// <summary>
/// An auth provider option property
/// An authentication provider option.
/// </summary>
public IAuthProviderOption AuthProviderOption { get; set; }
public IAuthenticationProviderOption AuthenticationProviderOption { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.Graph
/// An interface used to pass auth provider options in a request.
/// Auth providers will be incharge of implementing this interface and providing <see cref="IBaseRequest"/> extensions to set it's values.
/// </summary>
public interface IAuthProviderOption
public interface IAuthenticationProviderOption
{
/// <summary>
/// Microsoft Graph scopes property.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

using System;
using System.Net.Http;

namespace Microsoft.Graph
{
/// <summary>
/// The redirect middleware option class
/// </summary>
public class RedirectHandlerOption : IMiddlewareOption
{
internal const int DEFAULT_MAX_REDIRECT = 5;
internal const int MAX_MAX_REDIRECT = 20;
/// <summary>
/// Constructs a new <see cref="RedirectHandlerOption"/>
/// </summary>
public RedirectHandlerOption()
{

}


private int _maxRedirect = DEFAULT_MAX_REDIRECT;

/// <summary>
/// The maximum number of redirects with a maximum value of 20. This defaults to 5 redirects.
/// </summary>
public int MaxRedirect
{
get { return _maxRedirect; }
set
{
if (value > MAX_MAX_REDIRECT)
{
throw new ServiceException(
new Error
{
Code = ErrorConstants.Codes.MaximumValueExceeded,
Message = string.Format(ErrorConstants.Messages.MaximumValueExceeded, "MaxRedirect", MAX_MAX_REDIRECT)
});
}
_maxRedirect = value;
}
}

/// <summary>
/// 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.
/// </summary>
public Func<HttpResponseMessage, bool> ShouldRedirect { get; set; } = (response) => true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

namespace Microsoft.Graph
{
using System;
using System.Net.Http;

/// <summary>
/// The retry middleware option class
/// </summary>
public class RetryHandlerOption : IMiddlewareOption
{
internal const int DEFAULT_DELAY = 3;
internal const int DEFAULT_MAX_RETRY = 3;
internal const int MAX_MAX_RETRY = 10;
internal const int MAX_DELAY = 180;

/// <summary>
/// Constructs a new <see cref="RetryHandlerOption"/>
/// </summary>
public RetryHandlerOption()
{
}

private int _delay = DEFAULT_DELAY;
/// <summary>
/// The waiting time in seconds before retrying a request with a maximum value of 180 seconds. This defaults to 3 seconds.
/// </summary>
public int Delay
{
get { return _delay; }
set
{
if (value > MAX_DELAY)
{
throw new ServiceException(
new Error
{
Code = ErrorConstants.Codes.MaximumValueExceeded,
Message = string.Format(ErrorConstants.Messages.MaximumValueExceeded, "Delay", MAX_DELAY)
});
}

_delay = value;
}
}

private int _maxRetry = DEFAULT_MAX_RETRY;
/// <summary>
/// The maximum number of retries for a request with a maximum value of 10. This defaults to 3.
/// </summary>
public int MaxRetry
{
get
{
return _maxRetry;
}
set
{
if (value > MAX_MAX_RETRY)
{
throw new ServiceException(
new Error
{
Code = ErrorConstants.Codes.MaximumValueExceeded,
Message = string.Format(ErrorConstants.Messages.MaximumValueExceeded, "MaxRetry", MAX_MAX_RETRY)
});
}
_maxRetry = value;
}
}

/// <summary>
/// A delegate that's called to determine whether a request should be retried or not.
/// 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
/// </summary>
public Func<int, int, HttpResponseMessage, bool> ShouldRetry { get; set; } = (delay, attempt, response) => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
// send request first time to get response
var response = await base.SendAsync(request, cancellationToken);

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

var redirectCount = 0;

while (redirectCount < RedirectOption.MaxRedirects)
while (redirectCount < RedirectOption.MaxRedirect)
{
// general clone request with internal CloneAsync (see CloneAsync for details) extension method
var newRequest = await response.RequestMessage.CloneAsync();
Expand Down Expand Up @@ -100,6 +100,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
}
redirectCount++;
}

throw new ServiceException(
new Error
{
Expand Down
Loading

0 comments on commit c9a3093

Please sign in to comment.