/// <summary> /// Executes the ChangeSet. /// </summary> /// <param name="batchReader">The batch reader.</param> /// <param name="batchId">The batch id.</param> /// <param name="originalRequest">The original request containing all the batch requests.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>The response for the ChangeSet.</returns> public virtual async Task <ODataBatchResponseItem> ExecuteChangeSetAsync(ODataBatchReader batchReader, Guid batchId, HttpRequestMessage originalRequest, CancellationToken cancellationToken) { if (batchReader == null) { throw Error.ArgumentNull("batchReader"); } if (originalRequest == null) { throw Error.ArgumentNull("originalRequest"); } Guid changeSetId = Guid.NewGuid(); List <HttpResponseMessage> changeSetResponse = new List <HttpResponseMessage>(); Dictionary <string, string> contentIdToLocationMapping = new Dictionary <string, string>(); try { while (batchReader.Read() && batchReader.State != ODataBatchReaderState.ChangesetEnd) { if (batchReader.State == ODataBatchReaderState.Operation) { HttpRequestMessage changeSetOperationRequest = await batchReader.ReadChangeSetOperationRequestAsync(batchId, changeSetId, bufferContentStream : false); changeSetOperationRequest.CopyBatchRequestProperties(originalRequest); changeSetOperationRequest.DeleteRequestContainer(false); try { HttpResponseMessage response = await ODataBatchRequestItem.SendMessageAsync(Invoker, changeSetOperationRequest, cancellationToken, contentIdToLocationMapping); if (response.IsSuccessStatusCode) { changeSetResponse.Add(response); } else { ChangeSetRequestItem.DisposeResponses(changeSetResponse); changeSetResponse.Clear(); changeSetResponse.Add(response); return(new ChangeSetResponseItem(changeSetResponse)); } } finally { originalRequest.RegisterForDispose(changeSetOperationRequest.GetResourcesForDisposal()); originalRequest.RegisterForDispose(changeSetOperationRequest); } } } } catch { ChangeSetRequestItem.DisposeResponses(changeSetResponse); throw; } return(new ChangeSetResponseItem(changeSetResponse)); }