Skip to content

Commit

Permalink
Merge pull request #887 from MichaMican/main
Browse files Browse the repository at this point in the history
feat: Add option to specify requestId manually when calling AddBatchRequestStepAsync()
  • Loading branch information
andrueastman authored Aug 19, 2024
2 parents 766c000 + 8c474c4 commit 7c7511c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ public string AddBatchRequestStep(HttpRequestMessage httpRequestMessage)
/// Adds a <see cref="RequestInformation"/> to batch request content
/// </summary>
/// <param name="requestInformation">A <see cref="RequestInformation"/> to use to build a <see cref="BatchRequestStep"/> to add.</param>
/// <param name="requestId">An optional string that will be used as the requestId of the batch request</param>
/// <returns>The requestId of the newly created <see cref="BatchRequestStep"/></returns>
[Obsolete("Please use the BatchRequestContentCollection for making batch requests as it supports handling more than 20 requests and provides a similar API experience.")]
public async Task<string> AddBatchRequestStepAsync(RequestInformation requestInformation)
public async Task<string> AddBatchRequestStepAsync(RequestInformation requestInformation, string requestId = null)
{
if (BatchRequestSteps.Count >= CoreConstants.BatchRequest.MaxNumberOfRequests)
throw new ArgumentException(string.Format(ErrorConstants.Messages.MaximumValueExceeded, "Number of batch request steps", CoreConstants.BatchRequest.MaxNumberOfRequests));
string requestId = Guid.NewGuid().ToString();
if (string.IsNullOrEmpty(requestId))
{
requestId = Guid.NewGuid().ToString();
}
var requestMessage = await RequestAdapter.ConvertToNativeRequestAsync<HttpRequestMessage>(requestInformation);
BatchRequestStep batchRequestStep = new BatchRequestStep(requestId, requestMessage);
(BatchRequestSteps as IDictionary<string, BatchRequestStep>)!.Add(batchRequestStep.RequestId, batchRequestStep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ public string AddBatchRequestStep(HttpRequestMessage httpRequestMessage)
/// Adds a <see cref="RequestInformation"/> to batch request content
/// </summary>
/// <param name="requestInformation">A <see cref="RequestInformation"/> to use to build a <see cref="BatchRequestStep"/> to add.</param>
/// <param name="requestId">An optional string that will be used as the requestId of the batch request</param>
/// <returns>The requestId of the newly created <see cref="BatchRequestStep"/></returns>
public Task<string> AddBatchRequestStepAsync(RequestInformation requestInformation)
public Task<string> AddBatchRequestStepAsync(RequestInformation requestInformation, string requestId = null)
{
SetupCurrentRequest();
#pragma warning disable CS0618
return currentRequest.AddBatchRequestStepAsync(requestInformation);
return currentRequest.AddBatchRequestStepAsync(requestInformation, requestId);
#pragma warning restore CS0618
}

Expand Down

0 comments on commit 7c7511c

Please sign in to comment.