/// <summary> /// Makes a single batch request to the server. /// </summary> /// <param name="serverRequest">A server request with a set of operations on items.</param> /// <param name="trace">The trace.</param> /// <param name="cancellationToken"><see cref="CancellationToken"/> representing request cancellation.</param> /// <returns>Response from the server.</returns> private async Task <TransactionalBatchResponse> ExecuteServerRequestAsync( SinglePartitionKeyServerBatchRequest serverRequest, ITrace trace, CancellationToken cancellationToken) { using (ITrace executeBatchTrace = trace.StartChild("Execute Batch Request", TraceComponent.Batch, Tracing.TraceLevel.Info)) { using (Stream serverRequestPayload = serverRequest.TransferBodyStream()) { Debug.Assert(serverRequestPayload != null, "Server request payload expected to be non-null"); ResponseMessage responseMessage = await this.clientContext.ProcessResourceOperationStreamAsync( this.container.LinkUri, ResourceType.Document, OperationType.Batch, this.batchOptions, this.container, serverRequest.PartitionKey.HasValue?new FeedRangePartitionKey(serverRequest.PartitionKey.Value) : null, serverRequestPayload, requestMessage => { requestMessage.Headers.Add(HttpConstants.HttpHeaders.IsBatchRequest, bool.TrueString); requestMessage.Headers.Add(HttpConstants.HttpHeaders.IsBatchAtomic, bool.TrueString); requestMessage.Headers.Add(HttpConstants.HttpHeaders.IsBatchOrdered, bool.TrueString); }, executeBatchTrace, cancellationToken); return(await TransactionalBatchResponse.FromResponseMessageAsync( responseMessage, serverRequest, this.clientContext.SerializerCore, shouldPromoteOperationStatus : true, executeBatchTrace, cancellationToken)); } } }
/// <summary> /// Makes a single batch request to the server. /// </summary> /// <param name="serverRequest">A server request with a set of operations on items.</param> /// <param name="cancellationToken"><see cref="CancellationToken"/> representing request cancellation.</param> /// <returns>Response from the server.</returns> private async Task <TransactionalBatchResponse> ExecuteServerRequestAsync( SinglePartitionKeyServerBatchRequest serverRequest, CancellationToken cancellationToken) { using (Stream serverRequestPayload = serverRequest.TransferBodyStream()) { Debug.Assert(serverRequestPayload != null, "Server request payload expected to be non-null"); ResponseMessage responseMessage = await this.clientContext.ProcessResourceOperationStreamAsync( this.container.LinkUri, ResourceType.Document, OperationType.Batch, this.batchOptions, this.container, serverRequest.PartitionKey, serverRequestPayload, requestMessage => { requestMessage.Headers.Add(HttpConstants.HttpHeaders.IsBatchRequest, bool.TrueString); requestMessage.Headers.Add(HttpConstants.HttpHeaders.IsBatchAtomic, bool.TrueString); requestMessage.Headers.Add(HttpConstants.HttpHeaders.IsBatchOrdered, bool.TrueString); }, diagnosticsContext : this.diagnosticsContext, cancellationToken); using (this.diagnosticsContext.CreateScope("TransactionalBatchResponse")) { return(await TransactionalBatchResponse.FromResponseMessageAsync( responseMessage, serverRequest, this.clientContext.SerializerCore, shouldPromoteOperationStatus : true, shouldPerformDecryption : true, cancellationToken)); } } }