Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/validatePullRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
solutionName: Microsoft.Graph.Core.sln
relativePath: ./src/Microsoft.Graph.Core
steps:
- uses: actions/checkout@v3.3.0
- uses: actions/checkout@v3.4.0

- name: Setup .NET
uses: actions/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions docs/logging-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ The best practice for this is to add this to the end of the handler list so that

```cs
// create the auth provider
var authenticationProvider = new TokenCredentialAuthProvider(clientCertificateCredential,scopes);
var authProvider = new AzureIdentityAuthenticationProvider(clientSecretCredential, scopes);

// get the default list of handlers and add the logging handler to the list
var handlers = GraphClientFactory.CreateDefaultHandlers(authenticationProvider);
var handlers = GraphClientFactory.CreateDefaultHandlers();
handlers.Add(new LoggingHandler());

// create the GraphServiceClient with logging support
var httpClient = GraphClientFactory.Create(handlers);
GraphServiceClient graphServiceClient = new GraphServiceClient(httpClient);
GraphServiceClient graphServiceClient = new GraphServiceClient(httpClient, authProvider);

// make a request with logging enabled!!
User me = await graphServiceClient.Me.GetAsync();
Expand Down
9 changes: 5 additions & 4 deletions src/Microsoft.Graph.Core/Microsoft.Graph.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<VersionPrefix>3.0.2</VersionPrefix>
<VersionPrefix>3.0.3</VersionPrefix>
<VersionSuffix></VersionSuffix>
<PackageReleaseNotes>
- Fixes missing delta link after completed iteration in the PageIterator (https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/issues/619)
- Updates kiota abstraction library dependencies
- Allows checking for status codes without parsing request bodies in batch requests (https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/pull/626)
- Updates kiota abstraction library dependencies to fix serialization errors.

</PackageReleaseNotes>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down Expand Up @@ -59,7 +60,7 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.0.1" />
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.0.1" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.0.2" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.0.3" />
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.0.1" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.0.1" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Kiota.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

Expand All @@ -13,16 +14,36 @@ public class BatchRequestContentCollection
{
private readonly IBaseClient baseClient;
private readonly List<BatchRequestContent> batchRequests;
private readonly int batchRequestLimit;
private BatchRequestContent currentRequest;
private bool readOnly = false;

/// <summary>
/// Constructs a new <see cref="BatchRequestContentCollection"/>.
/// </summary>
/// <param name="baseClient">The <see cref="IBaseClient"/> for making requests</param>
public BatchRequestContentCollection(IBaseClient baseClient)
public BatchRequestContentCollection(IBaseClient baseClient) : this (baseClient, CoreConstants.BatchRequest.MaxNumberOfRequests)
{

}

/// <summary>
/// Constructs a new <see cref="BatchRequestContentCollection"/>.
/// </summary>
/// <param name="baseClient">The <see cref="IBaseClient"/> for making requests</param>
/// <param name="batchRequestLimit">Number of requests that may be placed in a single batch</param>
public BatchRequestContentCollection(IBaseClient baseClient, int batchRequestLimit)
{
if(baseClient == null)
{
throw new ArgumentNullException(nameof(baseClient));
}
if (batchRequestLimit < 2 || batchRequestLimit > CoreConstants.BatchRequest.MaxNumberOfRequests)
{
throw new ArgumentOutOfRangeException(nameof(batchRequestLimit));
}
this.baseClient = baseClient;
this.batchRequestLimit = batchRequestLimit;
batchRequests = new List<BatchRequestContent>();
currentRequest = new BatchRequestContent(baseClient);
}
Expand All @@ -38,7 +59,7 @@ private void ValidateReadOnly()
private void SetupCurrentRequest()
{
ValidateReadOnly();
if (currentRequest.BatchRequestSteps.Count >= CoreConstants.BatchRequest.MaxNumberOfRequests)
if (currentRequest.BatchRequestSteps.Count >= batchRequestLimit)
{
batchRequests.Add(currentRequest);
currentRequest = new BatchRequestContent(baseClient);
Expand Down Expand Up @@ -100,5 +121,25 @@ internal IEnumerable<BatchRequestContent> GetBatchRequestsForExecution()

return batchRequests;
}

/// <summary>
/// A BatchRequestSteps property.
/// </summary>
public IReadOnlyDictionary<string, BatchRequestStep> BatchRequestSteps { get
{
if (batchRequests.Count > 0)
{
IEnumerable<KeyValuePair<string, BatchRequestStep>> result = currentRequest.BatchRequestSteps;
foreach ( var request in batchRequests)
{
result = result.Concat(request.BatchRequestSteps);
}

return result.ToDictionary(x => x.Key, x => x.Value);
}

return currentRequest.BatchRequestSteps;
}
}
}
}
28 changes: 28 additions & 0 deletions src/Microsoft.Graph.Core/Requests/Content/BatchResponseContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ public async Task<Dictionary<string, HttpResponseMessage>> GetResponsesAsync()
return responseMessages;
}

/// <summary>
/// Gets all batch responses statuscodes <see cref="Dictionary{String, HttpStatusCode}"/>.
/// </summary>
/// <returns>A Dictionary of id and <see cref="HttpStatusCode"/> representing batch responses.</returns>
public async Task<Dictionary<string, HttpStatusCode>> GetResponsesStatusCodesAsync()
{
Dictionary<string, HttpStatusCode> statuscodes = new Dictionary<string, HttpStatusCode>();
jBatchResponseObject = jBatchResponseObject ?? await GetBatchResponseContentAsync().ConfigureAwait(false);
if (jBatchResponseObject == null)
return statuscodes;

if (jBatchResponseObject.RootElement.TryGetProperty(CoreConstants.BatchRequest.Responses, out JsonElement jResponses) && jResponses.ValueKind == JsonValueKind.Array)
{
foreach (JsonElement jResponseItem in jResponses.EnumerateArray())
statuscodes.Add(jResponseItem.GetProperty(CoreConstants.BatchRequest.Id).ToString(), GetStatusCodeFromJObject(jResponseItem));
}
return statuscodes;
}

/// <summary>
/// Gets a batch response as <see cref="HttpResponseMessage"/> for the specified batch request id.
/// The returned <see cref="HttpResponseMessage"/> MUST be disposed since it implements an <see cref="IDisposable"/>.
Expand Down Expand Up @@ -170,6 +189,15 @@ private HttpResponseMessage GetResponseMessageFromJObject(JsonElement jResponseI
return responseMessage;
}


private HttpStatusCode GetStatusCodeFromJObject(JsonElement jResponseItem)
{
if (jResponseItem.TryGetProperty(CoreConstants.BatchRequest.Status, out JsonElement status))
{
return (HttpStatusCode)int.Parse(status.ToString());
}
throw new ArgumentException("Response does not contain statuscode");
}
/// <summary>
/// Gets the <see cref="HttpContent"/> of a batch response as a <see cref="JsonDocument"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

/// <summary>
Expand Down Expand Up @@ -77,10 +79,29 @@ public Task<Stream> GetResponseStreamByIdAsync(string requestId)
/// All <see cref="HttpResponseMessage"/> in the dictionary MUST be disposed since they implement <see cref="IDisposable"/>.
/// </summary>
/// <returns>A Dictionary of id and <see cref="HttpResponseMessage"/> representing batch responses.</returns>
/// <remarks>Not implemented, need help</remarks>
/// <remarks>Not implemented, use GetResponsesStatusCodesAsync and fetch individual responses</remarks>
[Obsolete("use GetResponsesStatusCodesAsync and then GetResponseByIdAsync")]
public Task<Dictionary<string, HttpResponseMessage>> GetResponsesAsync()
{
throw new NotImplementedException("GetResponsesAsync() is not available in the BatchCollection");
}

/// <summary>
/// Gets all batch responses statuscodes <see cref="Dictionary{String, HttpStatusCode}"/>.
/// </summary>
/// <returns>A Dictionary of id and <see cref="HttpStatusCode"/> representing batch responses.</returns>
public async Task<Dictionary<string, HttpStatusCode>> GetResponsesStatusCodesAsync()
{
Dictionary<string, HttpStatusCode> statuscodes = new Dictionary<string, HttpStatusCode>();
foreach(var response in batchResponses)
{
var batchStatusCodes = await response.Response.GetResponsesStatusCodesAsync();
foreach(var result in batchStatusCodes)
{
statuscodes.Add(result.Key, result.Value);
}
}
return statuscodes;
}
}
}