/// <summary>
 /// Performs a batched operation request, returning the responses for each suboperation.
 /// </summary>
 /// <param name="batchOperation">The <see cref="BatchOperation"/> with the set of suboperations to include in the request.</param>
 /// <param name="requestOptions">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
 /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for a task to complete.</param>
 /// <returns></returns>
 public Task <IList <BlobBatchSubOperationResponse> > ExecuteBatchAsync(BatchOperation batchOperation, BlobRequestOptions requestOptions = default(BlobRequestOptions),
                                                                        OperationContext operationContext = default(OperationContext), CancellationToken cancellationToken = default(CancellationToken))
 {
     CommonUtility.AssertNotNull("batchOperation", batchOperation);
     return(batchOperation.ExecuteAsync(this, requestOptions, operationContext, cancellationToken));
 }
        private static RESTCommand <IList <BlobBatchSubOperationResponse> > BatchImpl(BatchOperation batch, CloudBlobClient client, BlobRequestOptions requestOptions)
        {
            // ContentMD5??
            //string contentMD5 = null;

            /*if (requestOptions.UseTransactionalMD5.HasValue && requestOptions.UseTransactionalMD5.Value)
             * {
             *  contentMD5 = memoryStream.ComputeMD5Hash();
             * }*/

            RESTCommand <IList <BlobBatchSubOperationResponse> > batchCmd = new RESTCommand <IList <BlobBatchSubOperationResponse> >(client.Credentials, client.StorageUri, client.HttpClient);

            requestOptions.ApplyToStorageCommand(batchCmd);

            List <BlobBatchSubOperationResponse> results = new List <BlobBatchSubOperationResponse>();

            batchCmd.CommandLocationMode      = CommandLocationMode.PrimaryOnly;
            batchCmd.RetrieveResponseStream   = true;
            batchCmd.PreProcessResponse       = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, null /* retVal */, cmd, ex);
            batchCmd.BuildContent             = (cmd, ctx) => BlobHttpRequestMessageFactory.WriteBatchBody(client, cmd, batch, ctx);
            batchCmd.BuildRequest             = (cmd, uri, builder, cnt, serverTimeout, ctx) => BlobHttpRequestMessageFactory.PrepareBatchRequest(uri, client.BufferManager, serverTimeout, batch, cnt, ctx, client.GetCanonicalizer(), client.Credentials);
            batchCmd.PostProcessResponseAsync = (cmd, resp, ctx, ct) => BlobHttpResponseParsers.BatchPostProcessAsync(results, cmd, new[] { HttpStatusCode.Accepted, HttpStatusCode.OK }, resp, ctx, ct);

            return(batchCmd);
        }