Skip to content

Commit 921e07b

Browse files
authored
Merge pull request #631 from microsoftgraph/dev
Release 3.0.3
2 parents ac81702 + e08c8d6 commit 921e07b

File tree

6 files changed

+102
-11
lines changed

6 files changed

+102
-11
lines changed

.github/workflows/validatePullRequest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
solutionName: Microsoft.Graph.Core.sln
1616
relativePath: ./src/Microsoft.Graph.Core
1717
steps:
18-
- uses: actions/checkout@v3.3.0
18+
- uses: actions/checkout@v3.4.0
1919

2020
- name: Setup .NET
2121
uses: actions/[email protected]

docs/logging-requests.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ The best practice for this is to add this to the end of the handler list so that
6666

6767
```cs
6868
// create the auth provider
69-
var authenticationProvider = new TokenCredentialAuthProvider(clientCertificateCredential,scopes);
69+
var authProvider = new AzureIdentityAuthenticationProvider(clientSecretCredential, scopes);
7070

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

7575
// create the GraphServiceClient with logging support
7676
var httpClient = GraphClientFactory.Create(handlers);
77-
GraphServiceClient graphServiceClient = new GraphServiceClient(httpClient);
77+
GraphServiceClient graphServiceClient = new GraphServiceClient(httpClient, authProvider);
7878

7979
// make a request with logging enabled!!
8080
User me = await graphServiceClient.Me.GetAsync();

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
<DelaySign>false</DelaySign>
2121
<AssemblyOriginatorKeyFile>35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
2222
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
23-
<VersionPrefix>3.0.2</VersionPrefix>
23+
<VersionPrefix>3.0.3</VersionPrefix>
2424
<VersionSuffix></VersionSuffix>
2525
<PackageReleaseNotes>
26-
- Fixes missing delta link after completed iteration in the PageIterator (https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/issues/619)
27-
- Updates kiota abstraction library dependencies
26+
- Allows checking for status codes without parsing request bodies in batch requests (https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/pull/626)
27+
- Updates kiota abstraction library dependencies to fix serialization errors.
28+
2829
</PackageReleaseNotes>
2930
<PublishRepositoryUrl>true</PublishRepositoryUrl>
3031
<EmbedUntrackedSources>true</EmbedUntrackedSources>
@@ -59,7 +60,7 @@
5960
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
6061
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.0.1" />
6162
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.0.1" />
62-
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.0.2" />
63+
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.0.3" />
6364
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.0.1" />
6465
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.0.1" />
6566
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.0.1" />

src/Microsoft.Graph.Core/Requests/Content/BatchRequestContentCollection.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.Kiota.Abstractions;
44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using System.Net.Http;
78
using System.Threading.Tasks;
89

@@ -13,16 +14,36 @@ public class BatchRequestContentCollection
1314
{
1415
private readonly IBaseClient baseClient;
1516
private readonly List<BatchRequestContent> batchRequests;
17+
private readonly int batchRequestLimit;
1618
private BatchRequestContent currentRequest;
1719
private bool readOnly = false;
1820

1921
/// <summary>
2022
/// Constructs a new <see cref="BatchRequestContentCollection"/>.
2123
/// </summary>
2224
/// <param name="baseClient">The <see cref="IBaseClient"/> for making requests</param>
23-
public BatchRequestContentCollection(IBaseClient baseClient)
25+
public BatchRequestContentCollection(IBaseClient baseClient) : this (baseClient, CoreConstants.BatchRequest.MaxNumberOfRequests)
2426
{
27+
28+
}
29+
30+
/// <summary>
31+
/// Constructs a new <see cref="BatchRequestContentCollection"/>.
32+
/// </summary>
33+
/// <param name="baseClient">The <see cref="IBaseClient"/> for making requests</param>
34+
/// <param name="batchRequestLimit">Number of requests that may be placed in a single batch</param>
35+
public BatchRequestContentCollection(IBaseClient baseClient, int batchRequestLimit)
36+
{
37+
if(baseClient == null)
38+
{
39+
throw new ArgumentNullException(nameof(baseClient));
40+
}
41+
if (batchRequestLimit < 2 || batchRequestLimit > CoreConstants.BatchRequest.MaxNumberOfRequests)
42+
{
43+
throw new ArgumentOutOfRangeException(nameof(batchRequestLimit));
44+
}
2545
this.baseClient = baseClient;
46+
this.batchRequestLimit = batchRequestLimit;
2647
batchRequests = new List<BatchRequestContent>();
2748
currentRequest = new BatchRequestContent(baseClient);
2849
}
@@ -38,7 +59,7 @@ private void ValidateReadOnly()
3859
private void SetupCurrentRequest()
3960
{
4061
ValidateReadOnly();
41-
if (currentRequest.BatchRequestSteps.Count >= CoreConstants.BatchRequest.MaxNumberOfRequests)
62+
if (currentRequest.BatchRequestSteps.Count >= batchRequestLimit)
4263
{
4364
batchRequests.Add(currentRequest);
4465
currentRequest = new BatchRequestContent(baseClient);
@@ -100,5 +121,25 @@ internal IEnumerable<BatchRequestContent> GetBatchRequestsForExecution()
100121

101122
return batchRequests;
102123
}
124+
125+
/// <summary>
126+
/// A BatchRequestSteps property.
127+
/// </summary>
128+
public IReadOnlyDictionary<string, BatchRequestStep> BatchRequestSteps { get
129+
{
130+
if (batchRequests.Count > 0)
131+
{
132+
IEnumerable<KeyValuePair<string, BatchRequestStep>> result = currentRequest.BatchRequestSteps;
133+
foreach ( var request in batchRequests)
134+
{
135+
result = result.Concat(request.BatchRequestSteps);
136+
}
137+
138+
return result.ToDictionary(x => x.Key, x => x.Value);
139+
}
140+
141+
return currentRequest.BatchRequestSteps;
142+
}
143+
}
103144
}
104145
}

src/Microsoft.Graph.Core/Requests/Content/BatchResponseContent.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ public async Task<Dictionary<string, HttpResponseMessage>> GetResponsesAsync()
5555
return responseMessages;
5656
}
5757

58+
/// <summary>
59+
/// Gets all batch responses statuscodes <see cref="Dictionary{String, HttpStatusCode}"/>.
60+
/// </summary>
61+
/// <returns>A Dictionary of id and <see cref="HttpStatusCode"/> representing batch responses.</returns>
62+
public async Task<Dictionary<string, HttpStatusCode>> GetResponsesStatusCodesAsync()
63+
{
64+
Dictionary<string, HttpStatusCode> statuscodes = new Dictionary<string, HttpStatusCode>();
65+
jBatchResponseObject = jBatchResponseObject ?? await GetBatchResponseContentAsync().ConfigureAwait(false);
66+
if (jBatchResponseObject == null)
67+
return statuscodes;
68+
69+
if (jBatchResponseObject.RootElement.TryGetProperty(CoreConstants.BatchRequest.Responses, out JsonElement jResponses) && jResponses.ValueKind == JsonValueKind.Array)
70+
{
71+
foreach (JsonElement jResponseItem in jResponses.EnumerateArray())
72+
statuscodes.Add(jResponseItem.GetProperty(CoreConstants.BatchRequest.Id).ToString(), GetStatusCodeFromJObject(jResponseItem));
73+
}
74+
return statuscodes;
75+
}
76+
5877
/// <summary>
5978
/// Gets a batch response as <see cref="HttpResponseMessage"/> for the specified batch request id.
6079
/// The returned <see cref="HttpResponseMessage"/> MUST be disposed since it implements an <see cref="IDisposable"/>.
@@ -170,6 +189,15 @@ private HttpResponseMessage GetResponseMessageFromJObject(JsonElement jResponseI
170189
return responseMessage;
171190
}
172191

192+
193+
private HttpStatusCode GetStatusCodeFromJObject(JsonElement jResponseItem)
194+
{
195+
if (jResponseItem.TryGetProperty(CoreConstants.BatchRequest.Status, out JsonElement status))
196+
{
197+
return (HttpStatusCode)int.Parse(status.ToString());
198+
}
199+
throw new ArgumentException("Response does not contain statuscode");
200+
}
173201
/// <summary>
174202
/// Gets the <see cref="HttpContent"/> of a batch response as a <see cref="JsonDocument"/>.
175203
/// </summary>

src/Microsoft.Graph.Core/Requests/Content/BatchResponseContentCollection.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using System.Collections.Generic;
77
using System.IO;
88
using System.Linq;
9+
using System.Net;
910
using System.Net.Http;
11+
using System.Text.Json;
1012
using System.Threading.Tasks;
1113

1214
/// <summary>
@@ -77,10 +79,29 @@ public Task<Stream> GetResponseStreamByIdAsync(string requestId)
7779
/// All <see cref="HttpResponseMessage"/> in the dictionary MUST be disposed since they implement <see cref="IDisposable"/>.
7880
/// </summary>
7981
/// <returns>A Dictionary of id and <see cref="HttpResponseMessage"/> representing batch responses.</returns>
80-
/// <remarks>Not implemented, need help</remarks>
82+
/// <remarks>Not implemented, use GetResponsesStatusCodesAsync and fetch individual responses</remarks>
83+
[Obsolete("use GetResponsesStatusCodesAsync and then GetResponseByIdAsync")]
8184
public Task<Dictionary<string, HttpResponseMessage>> GetResponsesAsync()
8285
{
8386
throw new NotImplementedException("GetResponsesAsync() is not available in the BatchCollection");
8487
}
88+
89+
/// <summary>
90+
/// Gets all batch responses statuscodes <see cref="Dictionary{String, HttpStatusCode}"/>.
91+
/// </summary>
92+
/// <returns>A Dictionary of id and <see cref="HttpStatusCode"/> representing batch responses.</returns>
93+
public async Task<Dictionary<string, HttpStatusCode>> GetResponsesStatusCodesAsync()
94+
{
95+
Dictionary<string, HttpStatusCode> statuscodes = new Dictionary<string, HttpStatusCode>();
96+
foreach(var response in batchResponses)
97+
{
98+
var batchStatusCodes = await response.Response.GetResponsesStatusCodesAsync();
99+
foreach(var result in batchStatusCodes)
100+
{
101+
statuscodes.Add(result.Key, result.Value);
102+
}
103+
}
104+
return statuscodes;
105+
}
85106
}
86107
}

0 commit comments

Comments
 (0)