Beispiel #1
0
        /// <summary>
        /// Returns the cached <see cref="ODataBatchOperationRequestMessage"/> for reading the content of an operation
        /// in a batch request.
        /// </summary>
        /// <returns>The message that can be used to read the content of the batch request operation from.</returns>
        private ODataBatchOperationRequestMessage CreateOperationRequestMessageImplementation()
        {
            this.operationState = OperationState.MessageCreated;

            // Read and parse the request line (skip all empty lines)
            string requestLine = this.batchStream.ReadLine();

            while (requestLine.Length == 0)
            {
                requestLine = this.batchStream.ReadLine();
            }

            string httpMethod;
            Uri    requestUri;

            this.ParseRequestLine(requestLine, out httpMethod, out requestUri);

            // Read all headers and create the request message
            ODataBatchOperationHeaders        headers        = this.batchStream.ReadHeaders();
            ODataBatchOperationRequestMessage requestMessage = ODataBatchOperationRequestMessage.CreateReadMessage(
                this.batchStream,
                httpMethod,
                requestUri,
                headers,
                /*operationListener*/ this,
                this.urlResolver);

            // Add a potential Content-ID header to the URL resolver so that it will be available
            // to subsequent operations.
            string contentId;

            if (headers.TryGetValue(ODataConstants.ContentIdHeader, out contentId))
            {
                Debug.Assert(this.contentIdToAddOnNextRead == null, "Must not have a content ID to be added to a part.");

                if (contentId != null && this.urlResolver.ContainsContentId(contentId))
                {
                    throw new ODataException(Strings.ODataBatchReader_DuplicateContentIDsNotAllowed(contentId));
                }

                this.contentIdToAddOnNextRead = contentId;
            }

            return(requestMessage);
        }
Beispiel #2
0
 private ODataBatchOperationRequestMessage CreateOperationRequestMessageImplementation(string method, Uri uri)
 {
     if (this.changeSetBoundary == null)
     {
         this.InterceptException(new Action(this.IncreaseBatchSize));
     }
     else
     {
         this.InterceptException(new Action(this.IncreaseChangeSetSize));
     }
     this.WritePendingMessageData(true);
     if (this.currentOperationContentId != null)
     {
         this.urlResolver.AddContentId(this.currentOperationContentId);
     }
     this.InterceptException(delegate {
         uri = ODataBatchUtils.CreateOperationRequestUri(uri, this.rawOutputContext.MessageWriterSettings.BaseUri, this.urlResolver);
     });
     this.CurrentOperationRequestMessage = ODataBatchOperationRequestMessage.CreateWriteMessage(this.rawOutputContext.OutputStream, method, uri, this, this.urlResolver);
     this.SetState(BatchWriterState.OperationCreated);
     this.WriteStartBoundaryForOperation();
     ODataBatchWriterUtils.WriteRequestPreamble(this.rawOutputContext.TextWriter, method, uri);
     return(this.CurrentOperationRequestMessage);
 }
 private static void SetAcceptAndContentTypeForODataBatchMessage(ODataBatchOperationRequestMessage mimePartMsg, TablePayloadFormat payloadFormat)
 {
     if (payloadFormat == TablePayloadFormat.AtomPub)
     {
         mimePartMsg.SetHeader(Constants.HeaderConstants.PayloadAcceptHeader, Constants.AtomAcceptHeaderValue);
         mimePartMsg.SetHeader(Constants.HeaderConstants.PayloadContentTypeHeader, Constants.AtomContentTypeHeaderValue);
     }
     else if (payloadFormat == TablePayloadFormat.JsonFullMetadata)
     {
         mimePartMsg.SetHeader(Constants.HeaderConstants.PayloadAcceptHeader, Constants.JsonFullMetadataAcceptHeaderValue);
         mimePartMsg.SetHeader(Constants.HeaderConstants.PayloadContentTypeHeader, Constants.JsonContentTypeHeaderValue);
     }
     else if (payloadFormat == TablePayloadFormat.Json)
     {
         mimePartMsg.SetHeader(Constants.HeaderConstants.PayloadAcceptHeader, Constants.JsonLightAcceptHeaderValue);
         mimePartMsg.SetHeader(Constants.HeaderConstants.PayloadContentTypeHeader, Constants.JsonContentTypeHeaderValue);
     }
     else
     {
         mimePartMsg.SetHeader(Constants.HeaderConstants.PayloadAcceptHeader, Constants.JsonNoMetadataAcceptHeaderValue);
         mimePartMsg.SetHeader(Constants.HeaderConstants.PayloadContentTypeHeader, Constants.JsonContentTypeHeaderValue);
     }
 }