private async Task <JObject> GetBatchRequestContentFromStepAsync(BatchRequestStep batchRequestStep) { JObject jRequestContent = new JObject { { CoreConstants.BatchRequest.Id, batchRequestStep.RequestId }, { CoreConstants.BatchRequest.Url, GetRelativeUrl(batchRequestStep.Request.RequestUri) }, { CoreConstants.BatchRequest.Method, batchRequestStep.Request.Method.Method } }; if (batchRequestStep.DependsOn != null && batchRequestStep.DependsOn.Count() > 0) { jRequestContent.Add(CoreConstants.BatchRequest.DependsOn, new JArray(batchRequestStep.DependsOn)); } if (batchRequestStep.Request.Content?.Headers != null && batchRequestStep.Request.Content.Headers.Count() > 0) { jRequestContent.Add(CoreConstants.BatchRequest.Headers, GetContentHeader(batchRequestStep.Request.Content.Headers)); } if (batchRequestStep.Request != null && batchRequestStep.Request.Content != null) { jRequestContent.Add(CoreConstants.BatchRequest.Body, await GetRequestContentAsync(batchRequestStep.Request)); } return(jRequestContent); }
/// <summary> /// Adds a <see cref="BatchRequestStep"/> to batch request content if doesn't exists. /// </summary> /// <param name="batchRequestStep">A <see cref="BatchRequestStep"/> to add.</param> /// <returns>True or false based on addition or not addition of the provided <see cref="BatchRequestStep"/>. </returns> public bool AddBatchRequestStep(BatchRequestStep batchRequestStep) { if (batchRequestStep == null || BatchRequestSteps.ContainsKey(batchRequestStep.RequestId)) { return(false); } (BatchRequestSteps as IDictionary <string, BatchRequestStep>).Add(batchRequestStep.RequestId, batchRequestStep); return(true); }
/// <summary> /// Adds a <see cref="BatchRequestStep"/> to batch request content if doesn't exists. /// </summary> /// <param name="batchRequestStep">A <see cref="BatchRequestStep"/> to add.</param> /// <returns>True or false based on addition or not addition of the provided <see cref="BatchRequestStep"/>. </returns> public bool AddBatchRequestStep(BatchRequestStep batchRequestStep) { if (batchRequestStep == null || BatchRequestSteps.ContainsKey(batchRequestStep.RequestId) || BatchRequestSteps.Count >= CoreConstants.BatchRequest.MaxNumberOfRequests //we should not add any more steps ) { return(false); } (BatchRequestSteps as IDictionary <string, BatchRequestStep>).Add(batchRequestStep.RequestId, batchRequestStep); return(true); }
/// <summary> /// Adds a <see cref="IBaseRequest"/> to batch request content /// </summary> /// <param name="request">A <see cref="BaseRequest"/> to use to build a <see cref="BatchRequestStep"/> to add.</param> /// <returns>The requestId of the newly created <see cref="BatchRequestStep"/></returns> public string AddBatchRequestStep(IBaseRequest request) { if (BatchRequestSteps.Count >= CoreConstants.BatchRequest.MaxNumberOfRequests) { throw new ClientException(new Error { Code = ErrorConstants.Codes.MaximumValueExceeded, Message = string.Format(ErrorConstants.Messages.MaximumValueExceeded, "Number of batch request steps", CoreConstants.BatchRequest.MaxNumberOfRequests) }); } string requestId = Guid.NewGuid().ToString(); BatchRequestStep batchRequestStep = new BatchRequestStep(requestId, request.GetHttpRequestMessage()); (BatchRequestSteps as IDictionary <string, BatchRequestStep>).Add(batchRequestStep.RequestId, batchRequestStep); return(requestId); }