Example #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.synchronous  = synchronous;
            this.urlResolver  = new ODataBatchUrlResolver(inputContext.UrlResolver);
            this.batchStream  = new ODataBatchReaderStream(inputContext, batchBoundary, batchEncoding);
            this.allowLegacyContentIdBehaviour = true;
        }
Example #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="urlResolver">The (optional) URL resolver for the message to create.</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,
            IODataUrlResolver urlResolver)
        {
            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, urlResolver, /*writing*/ false));
        }
 private static ODataBatchReaderStream CreateBatchReaderStream(string inputString)
 {
     var underlyingStream = new MemoryStream(Encoding.UTF8.GetBytes(inputString));
     var inputContext = new ODataRawInputContext(
         ODataFormat.Batch, 
         underlyingStream, 
         Encoding.UTF8, 
         new ODataMessageReaderSettings(),
         false, 
         true, 
         null, 
         null, 
         ODataPayloadKind.Batch);
     var batchStream = new ODataBatchReaderStream(inputContext, "batch_862fb28e-dc50-4af1-aad5-9608647761d1", Encoding.UTF8);
     return batchStream;
 }
        /// <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="urlResolver">The (optional) URL resolver for the message to create.</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,
            IODataUrlResolver urlResolver)
        {
            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, urlResolver, /*writing*/ false);

            responseMessage.statusCode = statusCode;
            return(responseMessage);
        }
Example #5
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="ODataBatchOperationReadStream"/> instance.</returns>
        internal static ODataBatchOperationReadStream CreateBatchOperationReadStream(
            ODataBatchReaderStream batchReaderStream,
            ODataBatchOperationHeaders headers,
            IODataBatchOperationListener 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 ODataBatchOperationReadStream.Create(batchReaderStream, operationListener, length);
            }

            return ODataBatchOperationReadStream.Create(batchReaderStream, operationListener);
        }
Example #6
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="ODataBatchOperationReadStream"/> instance.</returns>
        internal static ODataBatchOperationReadStream CreateBatchOperationReadStream(
            ODataBatchReaderStream batchReaderStream,
            ODataBatchOperationHeaders headers,
            IODataBatchOperationListener 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(ODataBatchOperationReadStream.Create(batchReaderStream, operationListener, length));
            }

            return(ODataBatchOperationReadStream.Create(batchReaderStream, operationListener));
        }
        /// <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="urlResolver">The (optional) URL resolver for the message to create.</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,
            IODataUrlResolver urlResolver)
        {
            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, urlResolver, /*writing*/ false);
            responseMessage.statusCode = statusCode;
            return responseMessage;
        }
Example #8
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>
 internal ODataBatchOperationReadStream(ODataBatchReaderStream batchReaderStream, IODataBatchOperationListener listener)
     : base(listener)
 {
     Debug.Assert(batchReaderStream != null, "batchReaderStream != null");
     this.batchReaderStream = batchReaderStream;
 }
        /// <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="urlResolver">The (optional) URL resolver for the message to create.</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,
            IODataUrlResolver urlResolver)
        {
            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, urlResolver, /*writing*/ false);
        }
Example #10
0
 /// <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;
 }
Example #11
0
 /// <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)
 {
 }
Example #12
0
 /// <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));
 }
Example #13
0
 /// <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);
 }
 /// <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>
 /// 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;
 }