예제 #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="inputContext">The input context to read the content from.</param>
        /// <param name="batchBoundary">The boundary string for the batch structure itself.</param>
        /// <param name="batchEncoding">The encoding to use to read from the batch stream.</param>
        /// <param name="synchronous">true if the reader is created for synchronous operation; false for asynchronous.</param>
        internal ODataBatchReader(ODataRawInputContext inputContext, string batchBoundary, Encoding batchEncoding, bool synchronous)
        {
            Debug.Assert(inputContext != null, "inputContext != null");
            Debug.Assert(!string.IsNullOrEmpty(batchBoundary), "!string.IsNullOrEmpty(batchBoundary)");

            this.inputContext                  = inputContext;
            this.container                     = inputContext.Container;
            this.synchronous                   = synchronous;
            this.payloadUriConverter           = new ODataBatchPayloadUriConverter(inputContext.PayloadUriConverter);
            this.batchStream                   = new ODataBatchReaderStream(inputContext, batchBoundary, batchEncoding);
            this.allowLegacyContentIdBehaviour = true;
        }
예제 #2
0
        /// <summary>
        /// Creates an operation request message that can be used to read the operation content from.
        /// </summary>
        /// <param name="batchReaderStream">The batch stream underyling the operation response message.</param>
        /// <param name="method">The HTTP method to use for the message to create.</param>
        /// <param name="requestUrl">The request URL for the message to create.</param>
        /// <param name="headers">The headers to use for the operation request message.</param>
        /// <param name="operationListener">The operation listener.</param>
        /// <param name="contentId">The content-ID for the operation request message.</param>
        /// <param name="payloadUriConverter">The (optional) URL converter for the message to create.</param>
        /// <param name="container">The dependency injection container to get related services.</param>
        /// <returns>An <see cref="ODataBatchOperationRequestMessage"/> to read the request content from.</returns>
        internal static ODataBatchOperationRequestMessage CreateReadMessage(
            ODataBatchReaderStream batchReaderStream,
            string method,
            Uri requestUrl,
            ODataBatchOperationHeaders headers,
            IODataBatchOperationListener operationListener,
            string contentId,
            IODataPayloadUriConverter payloadUriConverter,
            IServiceProvider container)
        {
            Debug.Assert(batchReaderStream != null, "batchReaderStream != null");
            Debug.Assert(operationListener != null, "operationListener != null");

            Func <Stream> streamCreatorFunc = () => ODataBatchUtils.CreateBatchOperationReadStream(batchReaderStream, headers, operationListener);

            return(new ODataBatchOperationRequestMessage(streamCreatorFunc, method, requestUrl, headers, operationListener, contentId, payloadUriConverter, /*writing*/ false, container));
        }
예제 #3
0
        /// <summary>
        /// Creates an operation response message that can be used to read the operation content from.
        /// </summary>
        /// <param name="batchReaderStream">The batch stream underyling the operation response message.</param>
        /// <param name="statusCode">The status code to use for the operation response message.</param>
        /// <param name="headers">The headers to use for the operation response message.</param>
        /// <param name="contentId">The content-ID for the operation response message.</param>
        /// <param name="operationListener">The operation listener.</param>
        /// <param name="payloadUriConverter">The (optional) URL converter for the message to create.</param>
        /// <param name="container">The dependency injection container to get related services.</param>
        /// <returns>An <see cref="ODataBatchOperationResponseMessage"/> that can be used to read the operation content.</returns>
        internal static ODataBatchOperationResponseMessage CreateReadMessage(
            ODataBatchReaderStream batchReaderStream,
            int statusCode,
            ODataBatchOperationHeaders headers,
            string contentId,
            IODataBatchOperationListener operationListener,
            IODataPayloadUriConverter payloadUriConverter,
            IServiceProvider container)
        {
            Debug.Assert(batchReaderStream != null, "batchReaderStream != null");
            Debug.Assert(operationListener != null, "operationListener != null");

            Func <Stream> streamCreatorFunc = () => ODataBatchUtils.CreateBatchOperationReadStream(batchReaderStream, headers, operationListener);
            ODataBatchOperationResponseMessage responseMessage =
                new ODataBatchOperationResponseMessage(streamCreatorFunc, headers, operationListener, contentId, payloadUriConverter, /*writing*/ false, container);

            responseMessage.statusCode = statusCode;
            return(responseMessage);
        }
예제 #4
0
        /// <summary>
        /// Creates a batch operation stream from the specified batch stream.
        /// </summary>
        /// <param name="batchReaderStream">The batch stream to create the operation read stream for.</param>
        /// <param name="headers">The headers of the current part; based on the header we create different, optimized stream implementations.</param>
        /// <param name="operationListener">The operation listener to be passed to the newly created read stream.</param>
        /// <returns>A new <see cref="ODataReadStream"/> instance.</returns>
        internal static ODataReadStream CreateBatchOperationReadStream(
            ODataBatchReaderStream batchReaderStream,
            ODataBatchOperationHeaders headers,
            IODataStreamListener operationListener)
        {
            Debug.Assert(batchReaderStream != null, "batchReaderStream != null");
            Debug.Assert(operationListener != null, "operationListener != null");

            // See whether we have a Content-Length header
            string contentLengthValue;

            if (headers.TryGetValue(ODataConstants.ContentLengthHeader, out contentLengthValue))
            {
                int length = Int32.Parse(contentLengthValue, CultureInfo.InvariantCulture);
                if (length < 0)
                {
                    throw new ODataException(Strings.ODataBatchReaderStream_InvalidContentLengthSpecified(contentLengthValue));
                }

                return(ODataReadStream.Create(batchReaderStream, operationListener, length));
            }

            return(ODataReadStream.Create(batchReaderStream, operationListener));
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="batchReaderStream">The underlying stream to read from.</param>
 /// <param name="listener">Listener interface to be notified of operation changes.</param>
 internal ODataBatchOperationReadStream(ODataBatchReaderStream batchReaderStream, IODataBatchOperationListener listener)
     : base(listener)
 {
     Debug.Assert(batchReaderStream != null, "batchReaderStream != null");
     this.batchReaderStream = batchReaderStream;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="batchReaderStream">The underlying batch stream to write the message to.</param>
 /// <param name="listener">Listener interface to be notified of operation changes.</param>
 internal ODataBatchOperationReadStreamWithDelimiter(ODataBatchReaderStream batchReaderStream, IODataBatchOperationListener listener)
     : base(batchReaderStream, listener)
 {
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="batchReaderStream">The underlying batch stream to write the message to.</param>
 /// <param name="listener">Listener interface to be notified of operation changes.</param>
 /// <param name="length">The total length of the stream.</param>
 internal ODataBatchOperationReadStreamWithLength(ODataBatchReaderStream batchReaderStream, IODataBatchOperationListener listener, int length)
     : base(batchReaderStream, listener)
 {
     ExceptionUtils.CheckIntegerNotNegative(length, "length");
     this.length = length;
 }
 /// <summary>
 /// Create a batch operation read stream over the specified batch stream using the batch delimiter to detect the end of the stream.
 /// </summary>
 /// <param name="batchReaderStream">The batch stream underlying the operation stream to create.</param>
 /// <param name="listener">The batch operation listener.</param>
 /// <returns>A <see cref="ODataBatchOperationReadStream"/> to read the content of a batch operation from.</returns>
 internal static ODataBatchOperationReadStream Create(ODataBatchReaderStream batchReaderStream, IODataBatchOperationListener listener)
 {
     return(new ODataBatchOperationReadStreamWithDelimiter(batchReaderStream, listener));
 }
 /// <summary>
 /// Create a batch operation read stream over the specified batch stream with a given content length.
 /// </summary>
 /// <param name="batchReaderStream">The batch stream underlying the operation stream to create.</param>
 /// <param name="listener">The batch operation listener.</param>
 /// <param name="length">The content length of the operation stream.</param>
 /// <returns>A <see cref="ODataBatchOperationReadStream"/> to read the content of a batch operation from.</returns>
 internal static ODataBatchOperationReadStream Create(ODataBatchReaderStream batchReaderStream, IODataBatchOperationListener listener, int length)
 {
     return(new ODataBatchOperationReadStreamWithLength(batchReaderStream, listener, length));
 }
예제 #10
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="batchReaderStream">The underlying stream to read from.</param>
 /// <param name="listener">Listener interface to be notified of operation changes.</param>
 private ODataReadStream(ODataBatchReaderStream batchReaderStream, IODataStreamListener listener)
     : base(listener)
 {
     Debug.Assert(batchReaderStream != null, "batchReaderStream != null");
     this.batchReaderStream = batchReaderStream;
 }