/// <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 ODataRawInputContext(
                       this,
                       messageStream,
                       encoding,
                       messageReaderSettings,
                       version,
                       readingResponse,
                       /*synchronous*/ true,
                       model,
                       urlResolver,
                       readerPayloadKind));
        }
        /// <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 ODataRawInputContext(
                           this,
                           streamTask.Result,
                           encoding,
                           messageReaderSettings,
                           version,
                           readingResponse,
                           /*synchronous*/ false,
                           model,
                           urlResolver,
                           readerPayloadKind)));
        }
 /// <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);
        /// <summary>
        /// Sets the 'OData-Version' HTTP header on the message based on the protocol version specified in the settings.
        /// </summary>
        /// <param name="message">The message to set the OData-Version header on.</param>
        /// <param name="settings">The <see cref="ODataMessageWriterSettings"/> determining the protocol version to use.</param>
        internal static void SetODataVersion(ODataMessage message, ODataMessageWriterSettings settings)
        {
            Debug.Assert(message != null, "message != null");
            Debug.Assert(settings != null, "settings != null");
            Debug.Assert(settings.Version.HasValue, "settings.Version.HasValue");

            string odataVersionString = ODataUtils.ODataVersionToString(settings.Version.Value);

            message.SetHeader(ODataConstants.ODataVersionHeader, odataVersionString);
        }
        /// <summary>
        /// Reads the OData-Version header from the <paramref name="message"/> and parses it.
        /// If no OData-Version header is found it sets the default version to be used for reading.
        /// </summary>
        /// <param name="message">The message to get the OData-Version header from.</param>
        /// <param name="defaultVersion">The default version to use if the header was not specified.</param>
        /// <returns>
        /// The <see cref="ODataVersion"/> retrieved from the OData-Version header of the message.
        /// The default version if none is specified in the header.
        /// </returns>
        internal static ODataVersion GetODataVersion(ODataMessage message, ODataVersion defaultVersion)
        {
            Debug.Assert(message != null, "message != null");

            string originalHeaderValue = message.GetHeader(ODataConstants.ODataVersionHeader);
            string headerValue         = originalHeaderValue;

            return(string.IsNullOrEmpty(headerValue)
                ? defaultVersion
                : ODataUtils.StringToODataVersion(headerValue));
        }
 /// <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);
예제 #7
0
        /// <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");

            throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataMetadataFormat_CreateOutputContextAsync));
        }
예제 #8
0
        /// <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");

            throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataMetadataFormat_CreateInputContextAsync));
        }
예제 #9
0
        /// <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 ODataRawOutputContext(
                           this,
                           streamTask.Result,
                           encoding,
                           messageWriterSettings,
                           writingResponse,
                           /*synchronous*/ false,
                           model,
                           urlResolver)));
        }
예제 #10
0
        /// <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 ODataRawOutputContext(
                       this,
                       messageStream,
                       encoding,
                       messageWriterSettings,
                       writingResponse,
                       /*synchronous*/ true,
                       model,
                       urlResolver));
        }
예제 #11
0
 /// <summary>
 /// Internal constructor to instantiate an <see cref="ODataPreferenceHeader"/> from an <see cref="IODataResponseMessage"/>.
 /// </summary>
 /// <param name="responseMessage">The response message to get and set the "Preference-Applied" header.</param>
 internal ODataPreferenceHeader(IODataResponseMessage responseMessage)
 {
     Debug.Assert(responseMessage != null, "responseMessage != null");
     this.message = new ODataResponseMessage(responseMessage, /*writing*/ true, /*disableMessageStreamDisposal*/ false, /*maxMessageSize*/ -1);
     this.preferenceHeaderName = PreferenceAppliedHeaderName;
 }