コード例 #1
0
        /// <summary>
        /// Asynchronously parses the batch requests.
        /// </summary>
        /// <param name="request">The HTTP request that contains the batch requests.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The task object that represents this asynchronous operation.</returns>
        public override async Task <IList <ODataBatchRequestItem> > ParseBatchRequestsAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            if (this.ApiFactory == null)
            {
                throw new InvalidOperationException(Resources.BatchHandlerRequiresApiContextFactory);
            }

            Ensure.NotNull(request, "request");

            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings
            {
                DisableMessageStreamDisposal = true,
                MessageQuotas = MessageQuotas,
                BaseUri       = GetBaseUri(request)
            };

            ODataMessageReader reader =
                await request.Content.GetODataMessageReaderAsync(readerSettings, cancellationToken);

            request.RegisterForDispose(reader);

            List <ODataBatchRequestItem> requests    = new List <ODataBatchRequestItem>();
            ODataBatchReader             batchReader = reader.CreateODataBatchReader();
            Guid batchId = Guid.NewGuid();

            while (batchReader.Read())
            {
                if (batchReader.State == ODataBatchReaderState.ChangesetStart)
                {
                    IList <HttpRequestMessage> changeSetRequests =
                        await batchReader.ReadChangeSetRequestAsync(batchId, cancellationToken);

                    foreach (HttpRequestMessage changeSetRequest in changeSetRequests)
                    {
                        changeSetRequest.CopyBatchRequestProperties(request);
                    }

                    requests.Add(this.CreateChangeSetRequestItem(changeSetRequests));
                }
                else if (batchReader.State == ODataBatchReaderState.Operation)
                {
                    HttpRequestMessage operationRequest = await batchReader.ReadOperationRequestAsync(
                        batchId,
                        bufferContentStream : true,
                        cancellationToken : cancellationToken);

                    operationRequest.CopyBatchRequestProperties(request);
                    requests.Add(new OperationRequestItem(operationRequest));
                }
            }

            return(requests);
        }
コード例 #2
0
        /// <summary>
        /// Converts the incoming OData batch request into a collection of request messages.
        /// </summary>
        /// <param name="context">The context containing the batch request messages.</param>
        /// <returns>A collection of <see cref="ODataBatchRequestItem"/>.</returns>
        public virtual async Task <IList <ODataBatchRequestItem> > ParseBatchRequestsAsync(HttpContext context)
        {
            if (context == null)
            {
                throw Error.ArgumentNull(nameof(context));
            }

            HttpRequest      request          = context.Request;
            IServiceProvider requestContainer = request.CreateRouteServices(PrefixName);

            requestContainer.GetRequiredService <ODataMessageReaderSettings>().BaseUri = GetBaseUri(request);

            using (ODataMessageReader reader = request.GetODataMessageReader(requestContainer))
            {
                CancellationToken            cancellationToken = context.RequestAborted;
                List <ODataBatchRequestItem> requests          = new List <ODataBatchRequestItem>();
                ODataBatchReader             batchReader       = await reader.CreateODataBatchReaderAsync().ConfigureAwait(false);

                Guid batchId = Guid.NewGuid();
                Dictionary <string, string> contentToLocationMapping = new Dictionary <string, string>();

                while (await batchReader.ReadAsync().ConfigureAwait(false))
                {
                    if (batchReader.State == ODataBatchReaderState.ChangesetStart)
                    {
                        IList <HttpContext> changeSetContexts = await batchReader.ReadChangeSetRequestAsync(context, batchId, cancellationToken).ConfigureAwait(false);

                        foreach (HttpContext changeSetContext in changeSetContexts)
                        {
                            changeSetContext.Request.ClearRouteServices();
                        }

                        ChangeSetRequestItem requestItem = new ChangeSetRequestItem(changeSetContexts);
                        requestItem.ContentIdToLocationMapping = contentToLocationMapping;
                        requests.Add(requestItem);
                    }
                    else if (batchReader.State == ODataBatchReaderState.Operation)
                    {
                        HttpContext operationContext = await batchReader.ReadOperationRequestAsync(context, batchId, cancellationToken).ConfigureAwait(false);

                        operationContext.Request.ClearRouteServices();
                        OperationRequestItem requestItem = new OperationRequestItem(operationContext);
                        requestItem.ContentIdToLocationMapping = contentToLocationMapping;
                        requests.Add(requestItem);
                    }
                }

                return(requests);
            }
        }
コード例 #3
0
        /// <summary>
        /// Asynchronously parses the batch requests.
        /// </summary>
        /// <param name="request">The HTTP request that contains the batch requests.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The task object that represents this asynchronous operation.</returns>
        public override async Task <IList <ODataBatchRequestItem> > ParseBatchRequestsAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            Ensure.NotNull(request, "request");

            IServiceProvider requestContainer = request.CreateRequestContainer(ODataRouteName);

            requestContainer.GetRequiredService <ODataMessageReaderSettings>().BaseUri = GetBaseUri(request);

            ODataMessageReader reader
                = await request.Content.GetODataMessageReaderAsync(requestContainer, cancellationToken);

            request.RegisterForDispose(reader);

            List <ODataBatchRequestItem> requests    = new List <ODataBatchRequestItem>();
            ODataBatchReader             batchReader = reader.CreateODataBatchReader();
            Guid batchId = Guid.NewGuid();

            while (batchReader.Read())
            {
                if (batchReader.State == ODataBatchReaderState.ChangesetStart)
                {
                    IList <HttpRequestMessage> changeSetRequests =
                        await batchReader.ReadChangeSetRequestAsync(batchId, cancellationToken);

                    foreach (HttpRequestMessage changeSetRequest in changeSetRequests)
                    {
                        changeSetRequest.CopyBatchRequestProperties(request);
                        changeSetRequest.DeleteRequestContainer(false);
                    }

                    requests.Add(this.CreateRestierBatchChangeSetRequestItem(changeSetRequests));
                }
                else if (batchReader.State == ODataBatchReaderState.Operation)
                {
                    HttpRequestMessage operationRequest = await batchReader.ReadOperationRequestAsync(
                        batchId, true, cancellationToken);

                    operationRequest.CopyBatchRequestProperties(request);
                    operationRequest.DeleteRequestContainer(false);
                    requests.Add(new OperationRequestItem(operationRequest));
                }
            }

            return(requests);
        }
コード例 #4
0
        public virtual async Task <IList <ODataBatchRequestItem> > ParseBatchRequestsAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            ODataMessageReaderSettings oDataReaderSettings = new ODataMessageReaderSettings
            {
                DisableMessageStreamDisposal = true,
                MessageQuotas = MessageQuotas,
                BaseUri       = GetBaseUri(request)
            };

            cancellationToken.ThrowIfCancellationRequested();
            ODataMessageReader reader = await request.Content.GetODataMessageReaderAsync(oDataReaderSettings);

            request.RegisterForDispose(reader);

            List <ODataBatchRequestItem> requests    = new List <ODataBatchRequestItem>();
            ODataBatchReader             batchReader = reader.CreateODataBatchReader();
            Guid batchId = Guid.NewGuid();

            while (batchReader.Read())
            {
                if (batchReader.State == ODataBatchReaderState.ChangesetStart)
                {
                    IList <HttpRequestMessage> changeSetRequests = await batchReader.ReadChangeSetRequestAsync(batchId, cancellationToken);

                    foreach (HttpRequestMessage changeSetRequest in changeSetRequests)
                    {
                        changeSetRequest.CopyBatchRequestProperties(request);
                    }
                    requests.Add(new ChangeSetRequestItem(changeSetRequests));
                }
                else if (batchReader.State == ODataBatchReaderState.Operation)
                {
                    HttpRequestMessage operationRequest = await batchReader.ReadOperationRequestAsync(batchId, bufferContentStream : true, cancellationToken : cancellationToken);

                    operationRequest.CopyBatchRequestProperties(request);
                    requests.Add(new OperationRequestItem(operationRequest));
                }
            }

            return(requests);
        }
コード例 #5
0
        /// <summary>
        /// Converts the incoming OData batch request into a collection of request messages.
        /// </summary>
        /// <param name="context">The context containing the batch request messages.</param>
        /// <returns>A collection of <see cref="ODataBatchRequestItem"/>.</returns>
        public virtual async Task <IList <ODataBatchRequestItem> > ParseBatchRequestsAsync(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            HttpRequest      request          = context.Request;
            IServiceProvider requestContainer = request.CreateSubServiceProvider(PrefixName);

            requestContainer.GetRequiredService <ODataMessageReaderSettings>().BaseUri = GetBaseUri(request);

            using (ODataMessageReader reader = request.GetODataMessageReader(requestContainer))
            {
                CancellationToken            cancellationToken = context.RequestAborted;
                List <ODataBatchRequestItem> requests          = new List <ODataBatchRequestItem>();
                ODataBatchReader             batchReader       = await reader.CreateODataBatchReaderAsync().ConfigureAwait(false);

                Guid batchId = Guid.NewGuid();
                while (await batchReader.ReadAsync().ConfigureAwait(false))
                {
                    if (batchReader.State == ODataBatchReaderState.ChangesetStart)
                    {
                        IList <HttpContext> changeSetContexts = await batchReader.ReadChangeSetRequestAsync(context, batchId, cancellationToken).ConfigureAwait(false);

                        foreach (HttpContext changeSetContext in changeSetContexts)
                        {
                            changeSetContext.Request.CopyBatchRequestProperties(request);
                            changeSetContext.Request.DeleteSubRequestProvider(false);
                        }
                        requests.Add(new ChangeSetRequestItem(changeSetContexts));
                    }
                    else if (batchReader.State == ODataBatchReaderState.Operation)
                    {
                        HttpContext operationContext = await batchReader.ReadOperationRequestAsync(context, batchId, cancellationToken).ConfigureAwait(false);

                        operationContext.Request.CopyBatchRequestProperties(request);
                        operationContext.Request.DeleteSubRequestProvider(false);
                        requests.Add(new OperationRequestItem(operationContext));
                    }
                }

                return(requests);
            }
        }
コード例 #6
0
        public virtual async Task <IList <ODataBatchRequestItem> > ParseBatchRequestsAsync(HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            ODataMessageReaderSettings oDataReaderSettings = new ODataMessageReaderSettings
            {
                DisableMessageStreamDisposal = true,
                MessageQuotas = MessageQuotas,
                BaseUri       = GetBaseUri(request)
            };

            ODataMessageReader reader = await request.Content.GetODataMessageReaderAsync(oDataReaderSettings);

            request.RegisterForDispose(reader);

            List <ODataBatchRequestItem> requests    = new List <ODataBatchRequestItem>();
            ODataBatchReader             batchReader = reader.CreateODataBatchReader();
            Guid batchId = Guid.NewGuid();

            while (batchReader.Read())
            {
                if (batchReader.State == ODataBatchReaderState.ChangesetStart)
                {
                    requests.Add(new ChangeSetRequestItem(await batchReader.ReadChangeSetRequestAsync(batchId)));
                }
                else if (batchReader.State == ODataBatchReaderState.Operation)
                {
                    requests.Add(new OperationRequestItem(await batchReader.ReadOperationRequestAsync(batchId, bufferContentStream: true)));
                }
            }

            return(requests);
        }
コード例 #7
0
 public static Task <IList <HttpRequestMessage> > ReadChangeSetRequestAsync(this ODataBatchReader reader, Guid batchId)
 {
     return(reader.ReadChangeSetRequestAsync(batchId, CancellationToken.None));
 }