Esempio n. 1
0
        internal ODataRawInputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver,
            ODataPayloadKind readerPayloadKind)
            : base(format, messageReaderSettings, readingResponse, synchronous, model, urlResolver)
        {
            Debug.Assert(messageStream != null, "stream != null");
            Debug.Assert(readerPayloadKind != ODataPayloadKind.Unsupported, "readerPayloadKind != ODataPayloadKind.Unsupported");

            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            try
            {
                this.stream            = messageStream;
                this.encoding          = encoding;
                this.readerPayloadKind = readerPayloadKind;
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
        /// <summary>
        /// Create JSON input context.
        /// </summary>
        /// <param name="format">The format for the input context.</param>
        /// <param name="message">The message to use.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        /// <returns>The newly created input context.</returns>
        internal static ODataInputContext Create(
            ODataFormat format,
            ODataMessage message,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(message != null, "message != null");
            Debug.Assert(messageReaderSettings != null, "messageReaderSettings != null");

            Stream messageStream = message.GetStream();

            return(new ODataJsonInputContext(
                       format,
                       messageStream,
                       encoding,
                       messageReaderSettings,
                       version,
                       readingResponse,
                       true,
                       model,
                       urlResolver));
        }
Esempio n. 3
0
        /// <summary>
        /// Helper method to create a test message from its content.
        /// </summary>
        /// <param name="messageContent">Stream with the content of the message.</param>
        /// <param name="testConfiguration">The test configuration.</param>
        /// <param name="payloadKind">The payload kind to use to compute and set the content type header; or null if no content type header should be set.</param>
        /// <param name="customContentTypeHeader">A custom content type header to be used in the message.</param>
        /// <param name="urlResolver">Url resolver to add to the test message created.</param>
        /// <returns>Newly created test message.</returns>
        protected TestMessage CreateInputMessageFromStream(
            TestStream messageContent,
            WriterTestConfiguration testConfiguration,
            ODataPayloadKind?payloadKind,
            string customContentTypeHeader,
            IODataUrlResolver urlResolver)
        {
            TestMessage message;

            if (testConfiguration.IsRequest)
            {
                if (urlResolver != null)
                {
                    message = new TestRequestMessageWithUrlResolver(messageContent, urlResolver, testConfiguration.Synchronous ? TestMessageFlags.NoAsynchronous : TestMessageFlags.NoSynchronous);
                }
                else
                {
                    message = new TestRequestMessage(messageContent, testConfiguration.Synchronous ? TestMessageFlags.NoAsynchronous : TestMessageFlags.NoSynchronous);
                }
            }
            else
            {
                if (urlResolver != null)
                {
                    message = new TestResponseMessageWithUrlResolver(messageContent, urlResolver, testConfiguration.Synchronous ? TestMessageFlags.NoAsynchronous : TestMessageFlags.NoSynchronous);
                }
                else
                {
                    message = new TestResponseMessage(messageContent, testConfiguration.Synchronous ? TestMessageFlags.NoAsynchronous : TestMessageFlags.NoSynchronous);
                }
            }

            return(message);
        }
        /// <summary>Constructor.</summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="reader">The reader to read data from.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        internal ODataJsonInputContext(
            ODataFormat format,
            TextReader reader,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(reader != null, "reader != null");

            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            try
            {
                this.textReader = reader;
                this.jsonReader = new BufferingJsonReader(this.textReader, /*removeDuplicateProperties*/ this.UseServerFormatBehavior, messageReaderSettings.MessageQuotas.MaxNestingDepth);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && reader != null)
                {
                    reader.Dispose();
                }

                throw;
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageStream">The message stream to write the payload to.</param>
        /// <param name="encoding">The encoding to use for the payload.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        private ODataMetadataOutputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
        {
            Debug.Assert(synchronous, "Metadata output context is only supported in synchronous operations.");

            try
            {
                this.messageOutputStream = messageStream;
                this.xmlWriter = ODataAtomWriterUtils.CreateXmlWriter(messageStream, messageWriterSettings, encoding);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the output context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
 internal ODataBatchOperationMessage(Func <Stream> contentStreamCreatorFunc, ODataBatchOperationHeaders headers, IODataBatchOperationListener operationListener, IODataUrlResolver urlResolver, bool writing) : base(writing, false, -1L)
 {
     this.contentStreamCreatorFunc = contentStreamCreatorFunc;
     this.operationListener        = operationListener;
     this.headers     = headers;
     this.urlResolver = urlResolver;
 }
Esempio n. 7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageStream">The message stream to write the payload to.</param>
        /// <param name="encoding">The encoding to use for the payload.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        internal ODataMetadataOutputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(messageStream != null, "messageStream != null");
            Debug.Assert(synchronous, "Metadata output context is only supported in synchronous operations.");

            try
            {
                this.messageOutputStream = messageStream;
                this.xmlWriter           = ODataAtomWriterUtils.CreateXmlWriter(messageStream, messageWriterSettings, encoding);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the output context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageStream">The message stream to write the payload to.</param>
        /// <param name="encoding">The encoding to use for the payload.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        internal ODataRawOutputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(messageStream != null, "messageStream != null");

            try
            {
                this.messageOutputStream = messageStream;
                this.encoding            = encoding;

                if (synchronous)
                {
                    this.outputStream = messageStream;
                }
                else
                {
                    this.asynchronousOutputStream = new AsyncBufferedStream(messageStream);
                    this.outputStream             = this.asynchronousOutputStream;
                }
            }
            catch
            {
                messageStream.Dispose();
                throw;
            }
        }
        /// <summary>
        /// Create RAW input context.
        /// </summary>
        /// <param name="format">The format for the input context.</param>
        /// <param name="message">The message to use.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        /// <param name="readerPayloadKind">The <see cref="ODataPayloadKind"/> to read.</param>
        /// <returns>The newly created input context.</returns>
        internal static ODataInputContext Create(
            ODataFormat format,
            ODataMessage message,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver,
            ODataPayloadKind readerPayloadKind)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(format == ODataFormat.RawValue || format == ODataFormat.Batch, "This method only supports the RAW value or batch format.");
            Debug.Assert(message != null, "message != null");
            Debug.Assert(messageReaderSettings != null, "messageReaderSettings != null");
            Debug.Assert(readerPayloadKind != ODataPayloadKind.Unsupported, "readerPayloadKind != ODataPayloadKind.Unsupported");

            Stream messageStream = message.GetStream();

            return(new ODataRawInputContext(
                       format,
                       messageStream,
                       encoding,
                       messageReaderSettings,
                       version,
                       readingResponse,
                       true,
                       model,
                       urlResolver,
                       readerPayloadKind));
        }
        /// <summary>
        /// Asynchronously create RAW input context.
        /// </summary>
        /// <param name="format">The format for the input context.</param>
        /// <param name="message">The message to use.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        /// <param name="readerPayloadKind">The <see cref="ODataPayloadKind"/> to read.</param>
        /// <returns>Task which when completed returns the newly create input context.</returns>
        internal static Task <ODataInputContext> CreateAsync(
            ODataFormat format,
            ODataMessage message,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver,
            ODataPayloadKind readerPayloadKind)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(format == ODataFormat.RawValue || format == ODataFormat.Batch, "This method only supports the RAW value or batch format.");
            Debug.Assert(message != null, "message != null");
            Debug.Assert(messageReaderSettings != null, "messageReaderSettings != null");
            Debug.Assert(readerPayloadKind != ODataPayloadKind.Unsupported, "readerPayloadKind != ODataPayloadKind.Unsupported");

            // TODO: Note that this will buffer the entire input. We need this for batch and for raw values since they
            // both use TextReader - verify that this is really what we want to do.
            return(message.GetStreamAsync()
                   .FollowOnSuccessWith(
                       (streamTask) => (ODataInputContext) new ODataRawInputContext(
                           format,
                           streamTask.Result,
                           encoding,
                           messageReaderSettings,
                           version,
                           readingResponse,
                           false,
                           model,
                           urlResolver,
                           readerPayloadKind)));
        }
Esempio n. 11
0
 internal ODataBatchOperationMessage(Func<Stream> contentStreamCreatorFunc, ODataBatchOperationHeaders headers, IODataBatchOperationListener operationListener, IODataUrlResolver urlResolver, bool writing) : base(writing, false, -1L)
 {
     this.contentStreamCreatorFunc = contentStreamCreatorFunc;
     this.operationListener = operationListener;
     this.headers = headers;
     this.urlResolver = urlResolver;
 }
Esempio n. 12
0
        /// <summary>Constructor.</summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="reader">The reader to use.</param>
        /// <param name="contentType">The content type of the message to read.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        /// <param name="payloadKindDetectionState">JSON Ligth specific state stored during payload kind detection (or null if no payload kind detection happened).</param>
        internal ODataJsonLightInputContext(
            ODataFormat format,
            TextReader reader,
            MediaType contentType,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver,
            ODataJsonLightPayloadKindDetectionState payloadKindDetectionState)
            : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(reader != null, "reader != null");
            Debug.Assert(contentType != null, "contentType != null");

            try
            {
                ExceptionUtils.CheckArgumentNotNull(format, "format");
                ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");
            }
            catch (ArgumentNullException)
            {
                // Dispose the message stream if we failed to create the input context.
                reader.Dispose();
                throw;
            }

            try
            {
                this.textReader = reader;

                if (contentType.HasStreamingSetToTrue())
                {
                    this.jsonReader = new BufferingJsonReader(
                        this.textReader,
                        ODataAnnotationNames.ODataError,
                        messageReaderSettings.MessageQuotas.MaxNestingDepth,
                        ODataFormat.Json);
                }
                else
                {
                    // If we have a non-streaming Json Light content type we need to use the re-ordering Json reader
                    this.jsonReader = new ReorderingJsonReader(this.textReader, messageReaderSettings.MessageQuotas.MaxNestingDepth);
                }
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && reader != null)
                {
                    reader.Dispose();
                }

                throw;
            }

            this.payloadKindDetectionState = payloadKindDetectionState;
        }
Esempio n. 13
0
        /// <summary>
        /// Creates the URI for a batch request operation.
        /// </summary>
        /// <param name="uri">The uri to process.</param>
        /// <param name="baseUri">The base Uri to use.</param>
        /// <param name="urlResolver">An optional custom URL resolver to resolve URLs for writing them into the payload.</param>
        /// <returns>An URI to be used in the request line of a batch request operation. It uses the <paramref name="urlResolver"/>
        /// first and falls back to the defaullt URI building schema if the no URL resolver is specified or the URL resolver
        /// returns null. In the default scheme, the method either returns the specified <paramref name="uri"/> if it was absolute,
        /// or it's combination with the <paramref name="baseUri"/> if it was relative.</returns>
        /// <remarks>
        /// This method will fail if no custom resolution is implemented and the specified <paramref name="uri"/> is 
        /// relative and there's no base URI available.
        /// </remarks>
        internal static Uri CreateOperationRequestUri(Uri uri, Uri baseUri, IODataUrlResolver urlResolver)
        {
            Debug.Assert(uri != null, "uri != null");

            Uri resultUri;
            if (urlResolver != null)
            {
                // The resolver returns 'null' if no custom resolution is desired.
                resultUri = urlResolver.ResolveUrl(baseUri, uri);
                if (resultUri != null)
                {
                    return resultUri;
                }
            }

            if (uri.IsAbsoluteUri)
            {
                resultUri = uri;
            }
            else
            {
                if (baseUri == null)
                {
                    string errorMessage = UriUtils.UriToString(uri).StartsWith("$", StringComparison.Ordinal)
                        ? Strings.ODataBatchUtils_RelativeUriStartingWithDollarUsedWithoutBaseUriSpecified(UriUtils.UriToString(uri))
                        : Strings.ODataBatchUtils_RelativeUriUsedWithoutBaseUriSpecified(UriUtils.UriToString(uri));
                    throw new ODataException(errorMessage);
                }

                resultUri = UriUtils.UriToAbsoluteUri(baseUri, uri);
            }

            return resultUri;
        }
        /// <summary>
        /// Creates an instance of the input context for this format.
        /// </summary>
        /// <param name="readerPayloadKind">The <see cref="ODataPayloadKind"/> to read.</param>
        /// <param name="message">The message to use.</param>
        /// <param name="contentType">The content type of the message to read.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        /// <param name="payloadKindDetectionFormatState">Format specific state stored during payload kind detection
        /// using the <see cref="ODataPayloadKindDetectionInfo.SetPayloadKindDetectionFormatState"/>.</param>
        /// <returns>The newly created input context.</returns>
        internal override ODataInputContext CreateInputContext(
            ODataPayloadKind readerPayloadKind,
            ODataMessage message,
            MediaType contentType,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver,
            object payloadKindDetectionFormatState)
        {
            ExceptionUtils.CheckArgumentNotNull(message, "message");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            Stream messageStream = message.GetStream();

            return(new ODataJsonLightInputContext(
                       this,
                       messageStream,
                       contentType,
                       encoding,
                       messageReaderSettings,
                       version,
                       readingResponse,
                       /*synchronous*/ true,
                       model,
                       urlResolver,
                       (ODataJsonLightPayloadKindDetectionState)payloadKindDetectionFormatState));
        }
        /// <summary>
        /// Asynchronously create RAW output context.
        /// </summary>
        /// <param name="format">The format to create the outpu context for.</param>
        /// <param name="message">The message to use.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        /// <returns>Task which when completed returns the newly created output context.</returns>
        internal static Task <ODataOutputContext> CreateAsync(
            ODataFormat format,
            ODataMessage message,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(format == ODataFormat.RawValue || format == ODataFormat.Batch, "This method only supports the RAW value or batch format.");
            Debug.Assert(message != null, "message != null");
            Debug.Assert(messageWriterSettings != null, "messageWriterSettings != null");

            return(message.GetStreamAsync()
                   .FollowOnSuccessWith(
                       (streamTask) => (ODataOutputContext) new ODataRawOutputContext(
                           format,
                           streamTask.Result,
                           encoding,
                           messageWriterSettings,
                           writingResponse,
                           false,
                           model,
                           urlResolver)));
        }
Esempio n. 16
0
        internal ODataRawInputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver,
            ODataPayloadKind readerPayloadKind)
            : base(format, messageReaderSettings, readingResponse, synchronous, model, urlResolver)
        {
            Debug.Assert(messageStream != null, "stream != null");
            Debug.Assert(readerPayloadKind != ODataPayloadKind.Unsupported, "readerPayloadKind != ODataPayloadKind.Unsupported");

            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            try
            {
                this.stream = messageStream;
                this.encoding = encoding;
                this.readerPayloadKind = readerPayloadKind;
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
Esempio n. 17
0
 private ODataJsonOutputContext(ODataFormat format, Stream messageStream, Encoding encoding, ODataMessageWriterSettings messageWriterSettings, bool writingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver) : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
 {
     try
     {
         Stream asynchronousOutputStream;
         this.messageOutputStream = messageStream;
         if (synchronous)
         {
             asynchronousOutputStream = messageStream;
         }
         else
         {
             this.asynchronousOutputStream = new AsyncBufferedStream(messageStream);
             asynchronousOutputStream = this.asynchronousOutputStream;
         }
         this.textWriter = new StreamWriter(asynchronousOutputStream, encoding);
         this.jsonWriter = new Microsoft.Data.OData.Json.JsonWriter(this.textWriter, messageWriterSettings.Indent);
     }
     catch (Exception exception)
     {
         if (ExceptionUtils.IsCatchableExceptionType(exception) && (messageStream != null))
         {
             messageStream.Dispose();
         }
         throw;
     }
 }
        /// <summary>
        /// Asynchronously create JSON input context.
        /// </summary>
        /// <param name="format">The format for the input context.</param>
        /// <param name="message">The message to use.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        /// <returns>Task which when completed returns the newly created input context.</returns>
        internal static Task <ODataInputContext> CreateAsync(
            ODataFormat format,
            ODataMessage message,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(message != null, "message != null");
            Debug.Assert(messageReaderSettings != null, "messageReaderSettings != null");

            return(message.GetStreamAsync()
                   .FollowOnSuccessWith(
                       (streamTask) => (ODataInputContext) new ODataJsonInputContext(
                           format,
                           streamTask.Result,
                           encoding,
                           messageReaderSettings,
                           version,
                           readingResponse,
                           false,
                           model,
                           urlResolver)));
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageStream">The message stream to write the payload to.</param>
        /// <param name="encoding">The encoding to use for the payload.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        private ODataRawOutputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
        {
            try
            {
                this.messageOutputStream = messageStream;
                this.encoding = encoding;

                if (synchronous)
                {
                    this.outputStream = messageStream;
                }
                else
                {
                    this.asynchronousOutputStream = new AsyncBufferedStream(messageStream);
                    this.outputStream = this.asynchronousOutputStream;
                }
            }
            catch
            {
                messageStream.Dispose();
                throw;
            }
        }
Esempio n. 20
0
 private ODataAtomOutputContext(ODataFormat format, Stream messageStream, Encoding encoding, ODataMessageWriterSettings messageWriterSettings, bool writingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver) : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
 {
     try
     {
         Stream asynchronousOutputStream;
         this.messageOutputStream = messageStream;
         if (synchronous)
         {
             asynchronousOutputStream = messageStream;
         }
         else
         {
             this.asynchronousOutputStream = new AsyncBufferedStream(messageStream);
             asynchronousOutputStream = this.asynchronousOutputStream;
         }
         this.xmlRootWriter = ODataAtomWriterUtils.CreateXmlWriter(asynchronousOutputStream, messageWriterSettings, encoding);
         this.xmlWriter = this.xmlRootWriter;
     }
     catch (Exception exception)
     {
         if (ExceptionUtils.IsCatchableExceptionType(exception) && (messageStream != null))
         {
             messageStream.Dispose();
         }
         throw;
     }
 }
Esempio n. 21
0
        /// <summary>
        /// Creates the URI for a batch request operation.
        /// </summary>
        /// <param name="uri">The uri to process.</param>
        /// <param name="baseUri">The base Uri to use.</param>
        /// <param name="urlResolver">An optional custom URL resolver to resolve URLs for writing them into the payload.</param>
        /// <returns>An URI to be used in the request line of a batch request operation. It uses the <paramref name="urlResolver"/>
        /// first and falls back to the defaullt URI building schema if the no URL resolver is specified or the URL resolver
        /// returns null. In the default scheme, the method either returns the specified <paramref name="uri"/> if it was absolute,
        /// or it's combination with the <paramref name="baseUri"/> if it was relative.</returns>
        /// <remarks>
        /// This method will fail if no custom resolution is implemented and the specified <paramref name="uri"/> is
        /// relative and there's no base URI available.
        /// </remarks>
        internal static Uri CreateOperationRequestUri(Uri uri, Uri baseUri, IODataUrlResolver urlResolver)
        {
            Debug.Assert(uri != null, "uri != null");

            Uri resultUri;

            if (urlResolver != null)
            {
                // The resolver returns 'null' if no custom resolution is desired.
                resultUri = urlResolver.ResolveUrl(baseUri, uri);
                if (resultUri != null)
                {
                    return(resultUri);
                }
            }

            if (uri.IsAbsoluteUri)
            {
                resultUri = uri;
            }
            else
            {
                if (baseUri == null)
                {
                    string errorMessage = UriUtils.UriToString(uri).StartsWith("$", StringComparison.Ordinal)
                        ? Strings.ODataBatchUtils_RelativeUriStartingWithDollarUsedWithoutBaseUriSpecified(UriUtils.UriToString(uri))
                        : Strings.ODataBatchUtils_RelativeUriUsedWithoutBaseUriSpecified(UriUtils.UriToString(uri));
                    throw new ODataException(errorMessage);
                }

                resultUri = UriUtils.UriToAbsoluteUri(baseUri, uri);
            }

            return(resultUri);
        }
        /// <summary>
        /// Creates an instance of the output context for this format.
        /// </summary>
        /// <param name="message">The message to use.</param>
        /// <param name="mediaType">The specific media type being written.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        /// <returns>Task which represents the pending create operation.</returns>
        internal override Task <ODataOutputContext> CreateOutputContextAsync(
            ODataMessage message,
            MediaType mediaType,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            ExceptionUtils.CheckArgumentNotNull(message, "message");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            return(message.GetStreamAsync()
                   .FollowOnSuccessWith(
                       (streamTask) => (ODataOutputContext) new ODataJsonLightOutputContext(
                           this,
                           streamTask.Result,
                           mediaType,
                           encoding,
                           messageWriterSettings,
                           writingResponse,
                           /*synchronous*/ false,
                           model,
                           urlResolver)));
        }
        /// <summary>
        /// Creates an instance of the output context for this format.
        /// </summary>
        /// <param name="message">The message to use.</param>
        /// <param name="mediaType">The specific media type being written.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        /// <returns>The newly created output context.</returns>
        internal override ODataOutputContext CreateOutputContext(
            ODataMessage message,
            MediaType mediaType,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            ExceptionUtils.CheckArgumentNotNull(message, "message");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            Stream messageStream = message.GetStream();

            return(new ODataJsonLightOutputContext(
                       this,
                       messageStream,
                       mediaType,
                       encoding,
                       messageWriterSettings,
                       writingResponse,
                       /*synchronous*/ true,
                       model,
                       urlResolver));
        }
        /// <summary>
        /// Asynchronously creates an instance of the input context for this format.
        /// </summary>
        /// <param name="readerPayloadKind">The <see cref="ODataPayloadKind"/> to read.</param>
        /// <param name="message">The message to use.</param>
        /// <param name="contentType">The content type of the message to read.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        /// <param name="payloadKindDetectionFormatState">Format specific state stored during payload kind detection
        /// using the <see cref="ODataPayloadKindDetectionInfo.SetPayloadKindDetectionFormatState"/>.</param>
        /// <returns>Task which when completed returned the newly created input context.</returns>
        internal override Task <ODataInputContext> CreateInputContextAsync(
            ODataPayloadKind readerPayloadKind,
            ODataMessage message,
            MediaType contentType,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver,
            object payloadKindDetectionFormatState)
        {
            ExceptionUtils.CheckArgumentNotNull(message, "message");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            return(message.GetStreamAsync()
                   .FollowOnSuccessWith(
                       (streamTask) => (ODataInputContext) new ODataJsonLightInputContext(
                           this,
                           streamTask.Result,
                           contentType,
                           encoding,
                           messageReaderSettings,
                           version,
                           readingResponse,
                           /*synchronous*/ false,
                           model,
                           urlResolver,
                           (ODataJsonLightPayloadKindDetectionState)payloadKindDetectionFormatState)));
        }
        /// <summary>
        /// Create RAW output context.
        /// </summary>
        /// <param name="format">The format to create the output context for.</param>
        /// <param name="message">The message to use.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        /// <returns>The newly created output context.</returns>
        internal static ODataOutputContext Create(
            ODataFormat format,
            ODataMessage message,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(format == ODataFormat.RawValue || format == ODataFormat.Batch, "This method only supports the RAW value or batch format.");
            Debug.Assert(message != null, "message != null");
            Debug.Assert(messageWriterSettings != null, "messageWriterSettings != null");

            Stream messageStream = message.GetStream();

            return(new ODataRawOutputContext(
                       format,
                       messageStream,
                       encoding,
                       messageWriterSettings,
                       writingResponse,
                       true,
                       model,
                       urlResolver));
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageStream">The message stream to write the payload to.</param>
        /// <param name="encoding">The encoding to use for the payload.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        private ODataRawOutputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
        {
            try
            {
                this.messageOutputStream = messageStream;
                this.encoding            = encoding;

                if (synchronous)
                {
                    this.outputStream = messageStream;
                }
                else
                {
                    this.asynchronousOutputStream = new AsyncBufferedStream(messageStream);
                    this.outputStream             = this.asynchronousOutputStream;
                }
            }
            catch
            {
                messageStream.Dispose();
                throw;
            }
        }
 /// <summary>
 /// Creates an instance of the output context for this format.
 /// </summary>
 /// <param name="message">The message to use.</param>
 /// <param name="mediaType">The specific media type being written.</param>
 /// <param name="encoding">The encoding to use.</param>
 /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
 /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
 /// <param name="model">The model to use.</param>
 /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
 /// <returns>Task which represents the pending create operation.</returns>
 internal abstract Task <ODataOutputContext> CreateOutputContextAsync(
     ODataMessage message,
     MediaType mediaType,
     Encoding encoding,
     ODataMessageWriterSettings messageWriterSettings,
     bool writingResponse,
     IEdmModel model,
     IODataUrlResolver urlResolver);
 public BatchWriterTestDescriptor(Settings settings, InvocationAndOperationDescriptor[] invocationsAndOperationDescriptors, Dictionary <string, string> expectedHeaders = null, Uri baseUri = null, IODataUrlResolver urlResolver = null)
 {
     this.TestDescriptorSettings             = settings;
     this.invocationsAndOperationDescriptors = invocationsAndOperationDescriptors;
     this.expectedResultCallback             = CreateExpectedResultCallback(invocationsAndOperationDescriptors, expectedHeaders, this.TestDescriptorSettings.ExpectedResultSettings);
     this.baseUri     = baseUri;
     this.urlResolver = urlResolver;
 }
 public BatchWriterTestDescriptor(Settings settings, InvocationAndOperationDescriptor[] invocationsAndOperationDescriptors, Dictionary<string, string> expectedHeaders = null, Uri baseUri = null, IODataUrlResolver urlResolver = null)
 {
     this.TestDescriptorSettings = settings;
     this.invocationsAndOperationDescriptors = invocationsAndOperationDescriptors;
     this.expectedResultCallback = CreateExpectedResultCallback(invocationsAndOperationDescriptors, expectedHeaders, this.TestDescriptorSettings.ExpectedResultSettings);
     this.baseUri = baseUri;
     this.urlResolver = urlResolver;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="format">The format for this output context.</param>
 /// <param name="messageStream">The message stream to write the payload to.</param>
 /// <param name="mediaType">The specific media type being written.</param>
 /// <param name="encoding">The encoding to use for the payload.</param>
 /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
 /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
 /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
 /// <param name="model">The model to use.</param>
 /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
 internal ODataJsonLightOutputContext(ODataFormat format, Stream messageStream, ODataMediaType mediaType, Encoding encoding, ODataMessageWriterSettings messageWriterSettings, bool writingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver)
     : base(format, messageStream, encoding, messageWriterSettings, writingResponse, synchronous, mediaType.HasIeee754CompatibleSetToTrue(), model, urlResolver)
 {
     Debug.Assert(messageStream != null, "messageStream != null");
     Debug.Assert(messageWriterSettings != null, "messageWriterSettings != null");
     Debug.Assert(mediaType != null, "mediaType != null");
     Uri metadataDocumentUri = messageWriterSettings.MetadataDocumentUri;
     this.metadataLevel = JsonLightMetadataLevel.Create(mediaType, metadataDocumentUri, model, writingResponse);
 }
        /// <summary>
        /// Creates an operation response message that can be used to write the operation content to.
        /// </summary>
        /// <param name="outputStream">The output stream underlying the operation 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 write the operation content.</returns>
        internal static ODataBatchOperationResponseMessage CreateWriteMessage(
            Stream outputStream,
            IODataBatchOperationListener operationListener,
            IODataUrlResolver urlResolver)
        {
            Func <Stream> streamCreatorFunc = () => ODataBatchUtils.CreateBatchOperationWriteStream(outputStream, operationListener);

            return(new ODataBatchOperationResponseMessage(streamCreatorFunc, /*headers*/ null, operationListener, /*contentId*/ null, urlResolver, /*writing*/ true));
        }
Esempio n. 32
0
        /// <summary>
        /// Asynchronously creates an instance of the input context for the specified format.
        /// </summary>
        /// <param name="format">The format to create the context for.</param>
        /// <param name="readerPayloadKind">The <see cref="ODataPayloadKind"/> to read.</param>
        /// <param name="message">The message to use.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        /// <returns>Task which when completed returned the newly created input context.</returns>
        internal static Task <ODataInputContext> CreateInputContextAsync(
            ODataFormat format,
            ODataPayloadKind readerPayloadKind,
            ODataMessage message,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(format != ODataFormat.Metadata, "Async reading of metadata documents is not supported.");
            Debug.Assert(readerPayloadKind != ODataPayloadKind.MetadataDocument, "Async reading of metadata documents is not supported.");

            if (format == ODataFormat.Atom)
            {
                return(ODataAtomInputContext.CreateAsync(
                           format,
                           message,
                           encoding,
                           messageReaderSettings,
                           version,
                           readingResponse,
                           model,
                           urlResolver));
            }

            if (format == ODataFormat.VerboseJson)
            {
                return(ODataJsonInputContext.CreateAsync(
                           format,
                           message,
                           encoding,
                           messageReaderSettings,
                           version,
                           readingResponse,
                           model,
                           urlResolver));
            }

            if (format == ODataFormat.Batch || format == ODataFormat.RawValue)
            {
                return(ODataRawInputContext.CreateAsync(
                           format,
                           message,
                           encoding,
                           messageReaderSettings,
                           version,
                           readingResponse,
                           model,
                           urlResolver,
                           readerPayloadKind));
            }

            throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataInputContext_CreateInputContext_UnrecognizedFormat));
        }
Esempio n. 33
0
        internal Uri ResolveUri(Uri baseUri, Uri payloadUri)
        {
            IODataUrlResolver urlResolver = this.inputContext.UrlResolver;

            if (urlResolver != null)
            {
                return(urlResolver.ResolveUrl(baseUri, payloadUri));
            }
            return(null);
        }
 /// <summary>
 /// Asynchronously creates an instance of the input context for this format.
 /// </summary>
 /// <param name="readerPayloadKind">The <see cref="ODataPayloadKind"/> to read.</param>
 /// <param name="message">The message to use.</param>
 /// <param name="contentType">The content type of the message to read.</param>
 /// <param name="encoding">The encoding to use.</param>
 /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
 /// <param name="version">The OData protocol version to be used for reading the payload.</param>
 /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
 /// <param name="model">The model to use.</param>
 /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
 /// <param name="payloadKindDetectionFormatState">Format specific state stored during payload kind detection
 /// using the <see cref="ODataPayloadKindDetectionInfo.SetPayloadKindDetectionFormatState"/>.</param>
 /// <returns>Task which when completed returned the newly created input context.</returns>
 internal abstract Task <ODataInputContext> CreateInputContextAsync(
     ODataPayloadKind readerPayloadKind,
     ODataMessage message,
     MediaType contentType,
     Encoding encoding,
     ODataMessageReaderSettings messageReaderSettings,
     ODataVersion version,
     bool readingResponse,
     IEdmModel model,
     IODataUrlResolver urlResolver,
     object payloadKindDetectionFormatState);
Esempio n. 35
0
 protected ODataOutputContext(ODataFormat format, ODataMessageWriterSettings messageWriterSettings, bool writingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver)
 {
     ExceptionUtils.CheckArgumentNotNull <ODataFormat>(format, "format");
     ExceptionUtils.CheckArgumentNotNull <ODataMessageWriterSettings>(messageWriterSettings, "messageWriterSettings");
     this.format = format;
     this.messageWriterSettings = messageWriterSettings;
     this.writingResponse       = writingResponse;
     this.synchronous           = synchronous;
     this.model       = model;
     this.urlResolver = urlResolver;
 }
Esempio n. 36
0
 public ODataMessageWriter(IODataResponseMessage responseMessage, ODataMessageWriterSettings settings, IEdmModel model)
 {
     this.writerPayloadKind = ODataPayloadKind.Unsupported;
     ExceptionUtils.CheckArgumentNotNull <IODataResponseMessage>(responseMessage, "responseMessage");
     this.settings = (settings == null) ? new ODataMessageWriterSettings() : new ODataMessageWriterSettings(settings);
     WriterValidationUtils.ValidateMessageWriterSettings(this.settings);
     this.writingResponse = true;
     this.message         = new ODataResponseMessage(responseMessage, true, this.settings.DisableMessageStreamDisposal, -1L);
     this.urlResolver     = responseMessage as IODataUrlResolver;
     this.model           = model ?? EdmCoreModel.Instance;
 }
Esempio n. 37
0
 protected ODataOutputContext(ODataFormat format, ODataMessageWriterSettings messageWriterSettings, bool writingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver)
 {
     ExceptionUtils.CheckArgumentNotNull<ODataFormat>(format, "format");
     ExceptionUtils.CheckArgumentNotNull<ODataMessageWriterSettings>(messageWriterSettings, "messageWriterSettings");
     this.format = format;
     this.messageWriterSettings = messageWriterSettings;
     this.writingResponse = writingResponse;
     this.synchronous = synchronous;
     this.model = model;
     this.urlResolver = urlResolver;
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="contentStreamCreatorFunc">A function to retrieve the content stream for this batch operation message.</param>
        /// <param name="headers">The headers of the batch operation message.</param>
        /// <param name="operationListener">Listener interface to be notified of part changes.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        /// <param name="writing">true if the request message is being written; false when it is read.</param>
        private ODataBatchOperationResponseMessage(
            Func<Stream> contentStreamCreatorFunc,
            ODataBatchOperationHeaders headers, 
            IODataBatchOperationListener operationListener,
            IODataUrlResolver urlResolver,
            bool writing)
        {
            Debug.Assert(contentStreamCreatorFunc != null, "contentStreamCreatorFunc != null");
            Debug.Assert(operationListener != null, "operationListener != null");

            this.message = new ODataBatchOperationMessage(contentStreamCreatorFunc, headers, operationListener, urlResolver, writing);
        }
Esempio n. 39
0
 protected ODataInputContext(ODataFormat format, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver)
 {
     ExceptionUtils.CheckArgumentNotNull <ODataFormat>(format, "format");
     ExceptionUtils.CheckArgumentNotNull <ODataMessageReaderSettings>(messageReaderSettings, "messageReaderSettings");
     this.format = format;
     this.messageReaderSettings = messageReaderSettings;
     this.version         = version;
     this.readingResponse = readingResponse;
     this.synchronous     = synchronous;
     this.model           = model;
     this.urlResolver     = urlResolver;
 }
Esempio n. 40
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="contentStreamCreatorFunc">A function to retrieve the content stream for this batch operation message.</param>
        /// <param name="headers">The headers of the batch operation message.</param>
        /// <param name="operationListener">Listener interface to be notified of part changes.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        /// <param name="writing">true if the request message is being written; false when it is read.</param>
        private ODataBatchOperationResponseMessage(
            Func <Stream> contentStreamCreatorFunc,
            ODataBatchOperationHeaders headers,
            IODataBatchOperationListener operationListener,
            IODataUrlResolver urlResolver,
            bool writing)
        {
            Debug.Assert(contentStreamCreatorFunc != null, "contentStreamCreatorFunc != null");
            Debug.Assert(operationListener != null, "operationListener != null");

            this.message = new ODataBatchOperationMessage(contentStreamCreatorFunc, headers, operationListener, urlResolver, writing);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="format">The format for this output context.</param>
 /// <param name="jsonWriter">The JSON writer to write to.</param>
 /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
 /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
 /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
 /// <param name="model">The model to use.</param>
 /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
 private ODataJsonOutputContext(
     ODataFormat format,
     JsonWriter jsonWriter,
     ODataMessageWriterSettings messageWriterSettings,
     bool writingResponse,
     bool synchronous,
     IEdmModel model,
     IODataUrlResolver urlResolver)
     : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
 {
     this.jsonWriter = jsonWriter;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="format">The format for this output context.</param>
 /// <param name="jsonWriter">The JSON writer to write to.</param>
 /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
 /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
 /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
 /// <param name="model">The model to use.</param>
 /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
 private ODataJsonOutputContext(
     ODataFormat format,
     JsonWriter jsonWriter,
     ODataMessageWriterSettings messageWriterSettings,
     bool writingResponse,
     bool synchronous,
     IEdmModel model,
     IODataUrlResolver urlResolver)
     : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
 {
     this.jsonWriter = jsonWriter;
 }
Esempio n. 43
0
 protected ODataInputContext(ODataFormat format, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver)
 {
     ExceptionUtils.CheckArgumentNotNull<ODataFormat>(format, "format");
     ExceptionUtils.CheckArgumentNotNull<ODataMessageReaderSettings>(messageReaderSettings, "messageReaderSettings");
     this.format = format;
     this.messageReaderSettings = messageReaderSettings;
     this.version = version;
     this.readingResponse = readingResponse;
     this.synchronous = synchronous;
     this.model = model;
     this.urlResolver = urlResolver;
 }
 /// <summary>Constructor.</summary>
 /// <param name="format">The format for this input context.</param>
 /// <param name="messageStream">The stream to read data from.</param>
 /// <param name="contentType">The content type of the message to read.</param>
 /// <param name="encoding">The encoding to use to read the input.</param>
 /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
 /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
 /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
 /// <param name="model">The model to use.</param>
 /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
 internal ODataJsonLightInputContext(
     ODataFormat format,
     Stream messageStream,
     ODataMediaType contentType,
     Encoding encoding,
     ODataMessageReaderSettings messageReaderSettings,
     bool readingResponse,
     bool synchronous,
     IEdmModel model,
     IODataUrlResolver urlResolver)
     : this(format, CreateTextReaderForMessageStreamConstructor(messageStream, encoding), contentType, messageReaderSettings, readingResponse, synchronous, model, urlResolver)
 {
 }
 internal VCardOutputContext(
     ODataFormat format,
     Stream messageStream,
     Encoding encoding,
     ODataMessageWriterSettings messageWriterSettings,
     bool writingResponse,
     bool synchronous,
     IEdmModel model,
     IODataUrlResolver urlResolver)
     : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
 {
     this.writer = new VCardWriter(new StreamWriter(messageStream, new UTF8Encoding(false)));
     this.outputStream = messageStream;
 }
Esempio n. 46
0
 internal ODataAvroOutputContext(
      ODataFormat format,
      Stream messageStream,
      Encoding encoding,
      ODataMessageWriterSettings messageWriterSettings,
      bool writingResponse,
      bool synchronous,
      IEdmModel model,
      IODataUrlResolver urlResolver)
     : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
 {
     this.outputStream = messageStream;
     this.AvroWriter = new AvroWriter(new StreamWrapper(outputStream));
 }
Esempio n. 47
0
 public VCardInputContext(ODataFormat format,
     Stream messageStream,
     ODataMediaType contentType,
     Encoding encoding,
     ODataMessageReaderSettings messageReaderSettings,
     bool readingResponse,
     bool synchronous,
     IEdmModel model,
     IODataUrlResolver urlResolver)
     : base(format, messageReaderSettings, readingResponse, synchronous, model, urlResolver)
 {
     this.stream = messageStream;
     this.reader = new VCardReader(new StreamReader(messageStream, encoding));
     this.throwExceptionOnDuplicatedPropertyNames = false;
 }
        /// <summary>
        /// Constructor. Base class constructor to create a message for an operation of a batch request/response.
        /// </summary>
        /// <param name="contentStreamCreatorFunc">A function to retrieve the content stream for this batch operation message.</param>
        /// <param name="headers">The headers of the batch operation message.</param>
        /// <param name="operationListener">Listener interface to be notified of part changes.</param>
        /// <param name="urlResolver">The URL resolver to perform custom URL resolution for URLs read or written from/to the payload.</param>
        /// <param name="writing">true if the request message is being written; false when it is read.</param>
        internal ODataBatchOperationMessage(
            Func<Stream> contentStreamCreatorFunc,
            ODataBatchOperationHeaders headers,
            IODataBatchOperationListener operationListener,
            IODataUrlResolver urlResolver,
            bool writing)
            : base(writing, /*disableMessageStreamDisposal*/ false, /*maxMessageSize*/ -1)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(contentStreamCreatorFunc != null, "contentStreamCreatorFunc != null");
            Debug.Assert(operationListener != null, "operationListener != null");

            this.contentStreamCreatorFunc = contentStreamCreatorFunc;
            this.operationListener = operationListener;
            this.headers = headers;
            this.urlResolver = urlResolver;
        }
        protected internal ODataJsonOutputContextBase(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            bool isIeee754Compatible,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
        {
            Debug.Assert(messageStream != null, "messageStream != null");

            try
            {
                this.messageOutputStream = messageStream;

                Stream outputStream;
                if (synchronous)
                {
                    outputStream = messageStream;
                }
                else
                {
                    this.asynchronousOutputStream = new AsyncBufferedStream(messageStream);
                    outputStream = this.asynchronousOutputStream;
                }

                this.textWriter = new StreamWriter(outputStream, encoding);
                
                // COMPAT 2: JSON indentation - WCFDS indents only partially, it inserts newlines but doesn't actually insert spaces for indentation
                // in here we allow the user to specify if true indentation should be used or if the limited functionality is enough.
                this.jsonWriter = new JsonWriter(this.textWriter, messageWriterSettings.Indent, format, isIeee754Compatible);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
Esempio n. 50
0
 private ODataMetadataInputContext(ODataFormat format, Stream messageStream, Encoding encoding, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver) : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
 {
     ExceptionUtils.CheckArgumentNotNull<ODataFormat>(format, "format");
     ExceptionUtils.CheckArgumentNotNull<ODataMessageReaderSettings>(messageReaderSettings, "messageReaderSettings");
     try
     {
         this.baseXmlReader = ODataAtomReaderUtils.CreateXmlReader(messageStream, encoding, messageReaderSettings);
         this.xmlReader = new BufferingXmlReader(this.baseXmlReader, null, messageReaderSettings.BaseUri, false, messageReaderSettings.MessageQuotas.MaxNestingDepth, messageReaderSettings.ReaderBehavior.ODataNamespace);
     }
     catch (Exception exception)
     {
         if (ExceptionUtils.IsCatchableExceptionType(exception) && (messageStream != null))
         {
             messageStream.Dispose();
         }
         throw;
     }
 }
Esempio n. 51
0
 internal ODataJsonInputContext(ODataFormat format, TextReader reader, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver) : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
 {
     ExceptionUtils.CheckArgumentNotNull<ODataFormat>(format, "format");
     ExceptionUtils.CheckArgumentNotNull<ODataMessageReaderSettings>(messageReaderSettings, "messageReaderSettings");
     try
     {
         this.textReader = reader;
         this.jsonReader = new BufferingJsonReader(this.textReader, base.UseServerFormatBehavior, messageReaderSettings.MessageQuotas.MaxNestingDepth);
     }
     catch (Exception exception)
     {
         if (ExceptionUtils.IsCatchableExceptionType(exception) && (reader != null))
         {
             reader.Dispose();
         }
         throw;
     }
 }
        /// <summary>
        /// Constructor. Creates a request message for an operation of a batch request.
        /// </summary>
        /// <param name="contentStreamCreatorFunc">A function to create the content stream.</param>
        /// <param name="method">The HTTP method used for this request message.</param>
        /// <param name="requestUrl">The request Url for this request message.</param>
        /// <param name="headers">The headers for the this request message.</param>
        /// <param name="operationListener">Listener interface to be notified of operation changes.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        /// <param name="writing">true if the request message is being written; false when it is read.</param>
        private ODataBatchOperationRequestMessage(
            Func<Stream> contentStreamCreatorFunc, 
            string method, 
            Uri requestUrl,
            ODataBatchOperationHeaders headers,
            IODataBatchOperationListener operationListener,
            IODataUrlResolver urlResolver,
            bool writing)
        {
            Debug.Assert(contentStreamCreatorFunc != null, "contentStreamCreatorFunc != null");
            Debug.Assert(operationListener != null, "operationListener != null");
            Debug.Assert(urlResolver != null, "urlResolver != null");

            this.Method = method;
            this.Url = requestUrl;

            this.message = new ODataBatchOperationMessage(contentStreamCreatorFunc, headers, operationListener, urlResolver, writing);
        }
Esempio n. 53
0
 private ODataRawInputContext(ODataFormat format, System.IO.Stream messageStream, Encoding encoding, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver, ODataPayloadKind readerPayloadKind) : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
 {
     ExceptionUtils.CheckArgumentNotNull<ODataFormat>(format, "format");
     ExceptionUtils.CheckArgumentNotNull<ODataMessageReaderSettings>(messageReaderSettings, "messageReaderSettings");
     try
     {
         this.stream = messageStream;
         this.encoding = encoding;
         this.readerPayloadKind = readerPayloadKind;
     }
     catch (Exception exception)
     {
         if (ExceptionUtils.IsCatchableExceptionType(exception) && (messageStream != null))
         {
             messageStream.Dispose();
         }
         throw;
     }
 }
Esempio n. 54
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        protected ODataInputContext(
            ODataFormat format,
            ODataMessageReaderSettings messageReaderSettings,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            this.format = format;
            this.messageReaderSettings = messageReaderSettings;
            this.readingResponse = readingResponse;
            this.synchronous = synchronous;
            this.model = model;
            this.urlResolver = urlResolver;
            this.edmTypeResolver = new EdmTypeReaderResolver(this.Model, this.MessageReaderSettings.ReaderBehavior);
        }
Esempio n. 55
0
        internal ODataAvroInputContext(
            ODataFormat format,
            Stream messageStream,
            ODataMediaType contentType,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageReaderSettings, readingResponse, synchronous, model, urlResolver)
        {
            this.stream = messageStream;

            MemoryStream st = new MemoryStream();
            stream.CopyTo(st);
            st.Seek(0, SeekOrigin.Begin);
            this.AvroReader = new AvroReader(AvroContainer.CreateGenericReader(st));
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageStream">The message stream to write the payload to.</param>
        /// <param name="encoding">The encoding to use for the payload.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        private ODataAtomOutputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageWriterSettings, writingResponse, synchronous, model, urlResolver)
        {
            Debug.Assert(messageStream != null, "stream != null");

            try
            {
                this.messageOutputStream = messageStream;

                Stream outputStream;
                if (synchronous)
                {
                    outputStream = messageStream;
                }
                else
                {
                    this.asynchronousOutputStream = new AsyncBufferedStream(messageStream);
                    outputStream = this.asynchronousOutputStream;
                }

                this.xmlRootWriter = ODataAtomWriterUtils.CreateXmlWriter(outputStream, messageWriterSettings, encoding);
                this.xmlWriter = this.xmlRootWriter;
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
        /// <summary>Constructor.</summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="messageStream">The stream to read data from.</param>
        /// <param name="encoding">The encoding to use to read the input.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        internal ODataAtomInputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(messageStream != null, "stream != null");

            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            try
            {
                this.baseXmlReader = ODataAtomReaderUtils.CreateXmlReader(messageStream, encoding, messageReaderSettings);

                // For WCF DS Server behavior we need to turn off xml:base processing for V1/V2 back compat.
                this.xmlReader = new BufferingXmlReader(
                    this.baseXmlReader,
                    /*parentXmlReader*/ null,
                    messageReaderSettings.BaseUri,
                    /*disableXmlBase*/ this.UseServerFormatBehavior && this.Version < ODataVersion.V3,
                    messageReaderSettings.MessageQuotas.MaxNestingDepth,
                    messageReaderSettings.ReaderBehavior.ODataNamespace);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
Esempio n. 58
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        protected ODataOutputContext(
            ODataFormat format,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            this.format = format;
            this.messageWriterSettings = messageWriterSettings;
            this.writingResponse = writingResponse;
            this.synchronous = synchronous;
            this.model = model ?? EdmCoreModel.Instance;
            this.urlResolver = urlResolver;
            this.edmTypeResolver = EdmTypeWriterResolver.Instance;
            this.payloadValueConverter = this.model.GetPayloadValueConverter();
        }
        /// <summary>Constructor.</summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="messageStream">The stream to read data from.</param>
        /// <param name="encoding">The encoding to use to read the input.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        private ODataMetadataInputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
        {
            Debug.Assert(messageStream != null, "stream != null");

            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            try
            {
                this.baseXmlReader = ODataAtomReaderUtils.CreateXmlReader(messageStream, encoding, messageReaderSettings);

                // We use the buffering reader here only for in-stream error detection (not for buffering).
                this.xmlReader = new BufferingXmlReader(
                    this.baseXmlReader,
                    /*parentXmlReader*/ null,
                    messageReaderSettings.BaseUri,
                    /*disableXmlBase*/ false,
                    messageReaderSettings.MessageQuotas.MaxNestingDepth,
                    messageReaderSettings.ReaderBehavior.ODataNamespace);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
Esempio n. 60
0
 internal static Uri CreateOperationRequestUri(Uri uri, Uri baseUri, IODataUrlResolver urlResolver)
 {
     if (urlResolver != null)
     {
         Uri uri2 = urlResolver.ResolveUrl(baseUri, uri);
         if (uri2 != null)
         {
             return uri2;
         }
     }
     if (uri.IsAbsoluteUri)
     {
         return uri;
     }
     if (baseUri == null)
     {
         string message = uri.OriginalString.StartsWith("$", StringComparison.Ordinal) ? Strings.ODataBatchUtils_RelativeUriStartingWithDollarUsedWithoutBaseUriSpecified(UriUtilsCommon.UriToString(uri)) : Strings.ODataBatchUtils_RelativeUriUsedWithoutBaseUriSpecified(UriUtilsCommon.UriToString(uri));
         throw new ODataException(message);
     }
     return UriUtils.UriToAbsoluteUri(baseUri, uri);
 }