Ejemplo n.º 1
0
        /// <summary>
        /// Executes the operation.
        /// </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 operation.</returns>
        public virtual async Task <ODataBatchResponseItem> ExecuteOperationAsync(ODataBatchReader batchReader, Guid batchId, HttpRequestMessage originalRequest, CancellationToken cancellationToken)
        {
            if (batchReader == null)
            {
                throw Error.ArgumentNull("batchReader");
            }
            if (originalRequest == null)
            {
                throw Error.ArgumentNull("originalRequest");
            }

            cancellationToken.ThrowIfCancellationRequested();
            HttpRequestMessage operationRequest = await batchReader.ReadOperationRequestAsync(batchId, bufferContentStream : false);

            operationRequest.CopyBatchRequestProperties(originalRequest);
            operationRequest.DeleteRequestContainer(false);
            OperationRequestItem operation = new OperationRequestItem(operationRequest);

            try
            {
                ODataBatchResponseItem response = await operation.SendRequestAsync(Invoker, cancellationToken);

                return(response);
            }
            finally
            {
                originalRequest.RegisterForDispose(operation.GetResourcesForDisposal());
                originalRequest.RegisterForDispose(operation);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the operation.
        /// </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="handler">The handler for processing a message.</param>
        /// <returns>The response for the operation.</returns>
        public virtual async Task <ODataBatchResponseItem> ExecuteOperationAsync(ODataBatchReader batchReader, Guid batchId, HttpRequest originalRequest, RequestDelegate handler)
        {
            if (batchReader == null)
            {
                throw Error.ArgumentNull("batchReader");
            }
            if (originalRequest == null)
            {
                throw Error.ArgumentNull("originalRequest");
            }
            if (handler == null)
            {
                throw Error.ArgumentNull("handler");
            }

            CancellationToken cancellationToken = originalRequest.HttpContext.RequestAborted;

            cancellationToken.ThrowIfCancellationRequested();
            HttpContext operationContext = await batchReader.ReadOperationRequestAsync(originalRequest.HttpContext, batchId, false, cancellationToken);

            operationContext.Request.CopyBatchRequestProperties(originalRequest);
            operationContext.Request.DeleteRequestContainer(false);
            OperationRequestItem operation = new OperationRequestItem(operationContext);

            ODataBatchResponseItem responseItem = await operation.SendRequestAsync(handler);

            return(responseItem);
        }