Пример #1
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)
        {
            DebugUtils.CheckNoExternalCallers();
            ExceptionUtils.CheckArgumentNotNull(message, "message");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            Stream messageStream = message.GetStream();

            return(new ODataMetadataOutputContext(
                       this,
                       messageStream,
                       encoding,
                       messageWriterSettings,
                       writingResponse,
                       /*synchronous*/ true,
                       model,
                       urlResolver));
        }
        /// <summary>
        /// Create a metadata input context.
        /// </summary>
        /// <param name="format">The format for this 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 ODataMetadataInputContext(
                       format,
                       messageStream,
                       encoding,
                       messageReaderSettings,
                       version,
                       readingResponse,
                       true,
                       model,
                       urlResolver));
        }
Пример #3
0
        /// <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)
        {
            DebugUtils.CheckNoExternalCallers();
            ExceptionUtils.CheckArgumentNotNull(message, "message");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            Stream messageStream = message.GetStream();

            return(new ODataMetadataInputContext(
                       this,
                       messageStream,
                       encoding,
                       messageReaderSettings,
                       version,
                       readingResponse,
                       /*synchronous*/ true,
                       model,
                       urlResolver));
        }
Пример #4
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 abstract Task <ODataOutputContext> CreateOutputContextAsync(
     ODataMessage message,
     MediaType mediaType,
     Encoding encoding,
     ODataMessageWriterSettings messageWriterSettings,
     bool writingResponse,
     IEdmModel model,
     IODataUrlResolver urlResolver);
Пример #5
0
 internal static ODataVersion GetDataServiceVersion(ODataMessage message, ODataVersion defaultVersion)
 {
     string header = message.GetHeader("DataServiceVersion");
     if (!string.IsNullOrEmpty(header))
     {
         return ODataUtils.StringToODataVersion(header);
     }
     return defaultVersion;
 }
Пример #6
0
        /// <summary>
        /// Sets the 'DataServiceVersion' HTTP header on the message based on the protocol version specified in the settings.
        /// </summary>
        /// <param name="message">The message to set the data service version header on.</param>
        /// <param name="settings">The <see cref="ODataMessageWriterSettings"/> determining the protocol version to use.</param>
        internal static void SetDataServiceVersion(ODataMessage message, ODataMessageWriterSettings settings)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(message != null, "message != null");
            Debug.Assert(settings != null, "settings != null");
            Debug.Assert(settings.Version.HasValue, "settings.Version.HasValue");

            string dataServiceVersionString = ODataUtils.ODataVersionToString(settings.Version.Value) + ";";
            message.SetHeader(ODataConstants.DataServiceVersionHeader, dataServiceVersionString);
        }
Пример #7
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 abstract Task <ODataInputContext> CreateInputContextAsync(
     ODataPayloadKind readerPayloadKind,
     ODataMessage message,
     MediaType contentType,
     Encoding encoding,
     ODataMessageReaderSettings messageReaderSettings,
     ODataVersion version,
     bool readingResponse,
     IEdmModel model,
     IODataUrlResolver urlResolver,
     object payloadKindDetectionFormatState);
Пример #8
0
        /// <summary>
        /// Sets the 'DataServiceVersion' HTTP header on the message based on the protocol version specified in the settings.
        /// </summary>
        /// <param name="message">The message to set the data service version header on.</param>
        /// <param name="settings">The <see cref="ODataMessageWriterSettings"/> determining the protocol version to use.</param>
        internal static void SetDataServiceVersion(ODataMessage message, ODataMessageWriterSettings settings)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(message != null, "message != null");
            Debug.Assert(settings != null, "settings != null");
            Debug.Assert(settings.Version.HasValue, "settings.Version.HasValue");

            string dataServiceVersionString = ODataUtils.ODataVersionToString(settings.Version.Value) + ";";

            message.SetHeader(ODataConstants.DataServiceVersionHeader, dataServiceVersionString);
        }
Пример #9
0
        /// <summary>
        /// Reads the DataServiceVersion header from the <paramref name="message"/> and parses it.
        /// If no DataServiceVersion header is found it sets the default version to be used for reading.
        /// </summary>
        /// <param name="message">The message to get the data service 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 DataServiceVersion header of the message.
        /// The default version if none is specified in the header.
        /// </returns>
        internal static ODataVersion GetDataServiceVersion(ODataMessage message, ODataVersion defaultVersion)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(message != null, "message != null");

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

            return(string.IsNullOrEmpty(headerValue)
                ? defaultVersion
                : ODataUtils.StringToODataVersion(headerValue));
        }
Пример #10
0
        /// <summary>
        /// Reads the DataServiceVersion header from the <paramref name="message"/> and parses it.
        /// If no DataServiceVersion header is found it sets the default version to be used for reading.
        /// </summary>
        /// <param name="message">The message to get the data service 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 DataServiceVersion header of the message.
        /// The default version if none is specified in the header.
        /// </returns>
        internal static ODataVersion GetDataServiceVersion(ODataMessage message, ODataVersion defaultVersion)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(message != null, "message != null");

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

            return string.IsNullOrEmpty(headerValue) 
                ? defaultVersion
                : ODataUtils.StringToODataVersion(headerValue);
        }
Пример #11
0
 public ODataMessageReader(IODataResponseMessage responseMessage, ODataMessageReaderSettings settings, IEdmModel model)
 {
     this.readerPayloadKind = ODataPayloadKind.Unsupported;
     ExceptionUtils.CheckArgumentNotNull <IODataResponseMessage>(responseMessage, "responseMessage");
     this.settings = (settings == null) ? new ODataMessageReaderSettings() : new ODataMessageReaderSettings(settings);
     ReaderValidationUtils.ValidateMessageReaderSettings(this.settings, true);
     this.readingResponse = true;
     this.message         = new ODataResponseMessage(responseMessage, false, this.settings.DisableMessageStreamDisposal, this.settings.MessageQuotas.MaxReceivedMessageSize);
     this.urlResolver     = responseMessage as IODataUrlResolver;
     this.version         = ODataUtilsInternal.GetDataServiceVersion(this.message, this.settings.MaxProtocolVersion);
     this.model           = model ?? EdmCoreModel.Instance;
     ODataVersionChecker.CheckVersionSupported(this.version, this.settings);
 }
Пример #12
0
        /// <summary>
        /// Creates an instance of the output context for the specified format.
        /// </summary>
        /// <param name="format">The format to create the 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 represents the pending create operation.</returns>
        internal static Task <ODataOutputContext> CreateOutputContextAsync(
            ODataFormat format,
            ODataMessage message,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();

            if (format == ODataFormat.Atom)
            {
                return(ODataAtomOutputContext.CreateAsync(
                           format,
                           message,
                           encoding,
                           messageWriterSettings,
                           writingResponse,
                           model,
                           urlResolver));
            }

            if (format == ODataFormat.VerboseJson)
            {
                return(ODataJsonOutputContext.CreateAsync(
                           format,
                           message,
                           encoding,
                           messageWriterSettings,
                           writingResponse,
                           model,
                           urlResolver));
            }

            //// Metadata output is only supported in synchronous operation.

            if (format == ODataFormat.Batch || format == ODataFormat.RawValue)
            {
                return(ODataRawOutputContext.CreateAsync(
                           format,
                           message,
                           encoding,
                           messageWriterSettings,
                           writingResponse,
                           model,
                           urlResolver));
            }

            throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataOutputContext_CreateOutputContext_UnrecognizedFormat));
        }
Пример #13
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)
        {
            DebugUtils.CheckNoExternalCallers();
            ExceptionUtils.CheckArgumentNotNull(message, "message");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataMetadataFormat_CreateOutputContextAsync));
        }
Пример #14
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)
        {
            DebugUtils.CheckNoExternalCallers();
            ExceptionUtils.CheckArgumentNotNull(message, "message");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataMetadataFormat_CreateInputContextAsync));
        }
Пример #15
0
 internal static ODataOutputContext CreateOutputContext(ODataFormat format, ODataMessage message, Encoding encoding, ODataMessageWriterSettings messageWriterSettings, bool writingResponse, IEdmModel model, IODataUrlResolver urlResolver)
 {
     if (format == ODataFormat.Atom)
     {
         return(ODataAtomOutputContext.Create(format, message, encoding, messageWriterSettings, writingResponse, model, urlResolver));
     }
     if (format == ODataFormat.VerboseJson)
     {
         return(ODataJsonOutputContext.Create(format, message, encoding, messageWriterSettings, writingResponse, model, urlResolver));
     }
     if (format == ODataFormat.Metadata)
     {
         return(ODataMetadataOutputContext.Create(format, message, encoding, messageWriterSettings, writingResponse, model, urlResolver));
     }
     if ((format != ODataFormat.Batch) && (format != ODataFormat.RawValue))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataOutputContext_CreateOutputContext_UnrecognizedFormat));
     }
     return(ODataRawOutputContext.Create(format, message, encoding, messageWriterSettings, writingResponse, model, urlResolver));
 }
Пример #16
0
 internal static ODataInputContext CreateInputContext(ODataFormat format, ODataPayloadKind readerPayloadKind, ODataMessage message, Encoding encoding, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, IEdmModel model, IODataUrlResolver urlResolver)
 {
     if (format == ODataFormat.Atom)
     {
         return ODataAtomInputContext.Create(format, message, encoding, messageReaderSettings, version, readingResponse, model, urlResolver);
     }
     if (format == ODataFormat.VerboseJson)
     {
         return ODataJsonInputContext.Create(format, message, encoding, messageReaderSettings, version, readingResponse, model, urlResolver);
     }
     if (format == ODataFormat.Metadata)
     {
         return ODataMetadataInputContext.Create(format, message, encoding, messageReaderSettings, version, readingResponse, model, urlResolver);
     }
     if ((format != ODataFormat.Batch) && (format != ODataFormat.RawValue))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataInputContext_CreateInputContext_UnrecognizedFormat));
     }
     return ODataRawInputContext.Create(format, message, encoding, messageReaderSettings, version, readingResponse, model, urlResolver, readerPayloadKind);
 }
Пример #17
0
 internal static Task<ODataOutputContext> CreateAsync(ODataFormat format, ODataMessage message, Encoding encoding, ODataMessageWriterSettings messageWriterSettings, bool writingResponse, IEdmModel model, IODataUrlResolver urlResolver)
 {
     return message.GetStreamAsync().FollowOnSuccessWith<Stream, ODataOutputContext>(streamTask => new ODataRawOutputContext(format, streamTask.Result, encoding, messageWriterSettings, writingResponse, false, model, urlResolver));
 }
Пример #18
0
 internal static ODataOutputContext Create(ODataFormat format, ODataMessage message, Encoding encoding, ODataMessageWriterSettings messageWriterSettings, bool writingResponse, IEdmModel model, IODataUrlResolver urlResolver)
 {
     return new ODataRawOutputContext(format, message.GetStream(), encoding, messageWriterSettings, writingResponse, true, model, urlResolver);
 }
Пример #19
0
        /// <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);
        }
Пример #20
0
 internal static void SetDataServiceVersion(ODataMessage message, ODataMessageWriterSettings settings)
 {
     string headerValue = ODataUtils.ODataVersionToString(settings.Version.Value) + ";";
     message.SetHeader("DataServiceVersion", headerValue);
 }
Пример #21
0
 internal static ODataInputContext Create(ODataFormat format, ODataMessage message, Encoding encoding, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, IEdmModel model, IODataUrlResolver urlResolver, ODataPayloadKind readerPayloadKind)
 {
     return new ODataRawInputContext(format, message.GetStream(), encoding, messageReaderSettings, version, readingResponse, true, model, urlResolver, readerPayloadKind);
 }
Пример #22
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));
        }
Пример #23
0
        /// <summary>
        /// Creates an instance of the output context for the specified format.
        /// </summary>
        /// <param name="format">The format to create the 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 represents the pending create operation.</returns>
        internal static Task<ODataOutputContext> CreateOutputContextAsync(
            ODataFormat format,
            ODataMessage message,
            Encoding encoding,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();

            if (format == ODataFormat.Atom)
            {
                return ODataAtomOutputContext.CreateAsync(
                    format,
                    message,
                    encoding,
                    messageWriterSettings,
                    writingResponse,
                    model,
                    urlResolver);
            }

            if (format == ODataFormat.VerboseJson)
            {
                return ODataJsonOutputContext.CreateAsync(
                    format,
                    message,
                    encoding,
                    messageWriterSettings,
                    writingResponse,
                    model,
                    urlResolver);
            }

            //// Metadata output is only supported in synchronous operation.

            if (format == ODataFormat.Batch || format == ODataFormat.RawValue)
            {
                return ODataRawOutputContext.CreateAsync(
                    format,
                    message,
                    encoding,
                    messageWriterSettings,
                    writingResponse,
                    model,
                    urlResolver);
            }

            throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataOutputContext_CreateOutputContext_UnrecognizedFormat));
        }
Пример #24
0
 internal static Task <ODataInputContext> CreateInputContextAsync(ODataFormat format, ODataPayloadKind readerPayloadKind, ODataMessage message, Encoding encoding, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, IEdmModel model, IODataUrlResolver urlResolver)
 {
     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))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataInputContext_CreateInputContext_UnrecognizedFormat));
     }
     return(ODataRawInputContext.CreateAsync(format, message, encoding, messageReaderSettings, version, readingResponse, model, urlResolver, readerPayloadKind));
 }
Пример #25
0
        /// <summary>
        /// Create ATOM 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 ODataAtomInputContext(
                format,
                messageStream,
                encoding,
                messageReaderSettings,
                version,
                readingResponse,
                true,
                model,
                urlResolver);
        }
Пример #26
0
        /// <summary>
        /// Asynchronously create ATOM 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 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)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(message != null, "message != null");
            Debug.Assert(messageReaderSettings != null, "messageReaderSettings != null");

            return message.GetStreamAsync()
                .FollowOnSuccessWith(
                    (streamTask) => (ODataInputContext)new ODataAtomInputContext(
                        format,
                        streamTask.Result,
                        encoding,
                        messageReaderSettings,
                        version,
                        readingResponse,
                        false,
                        model,
                        urlResolver));
        }
Пример #27
0
        /// <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);
        }
Пример #28
0
        /// <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));
        }
Пример #29
0
        /// <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));
        }
Пример #30
0
 internal static Task<ODataInputContext> CreateAsync(ODataFormat format, ODataMessage message, Encoding encoding, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, IEdmModel model, IODataUrlResolver urlResolver, ODataPayloadKind readerPayloadKind)
 {
     return message.GetStreamAsync().FollowOnSuccessWith<System.IO.Stream, ODataInputContext>(streamTask => new ODataRawInputContext(format, streamTask.Result, encoding, messageReaderSettings, version, readingResponse, false, model, urlResolver, readerPayloadKind));
 }
Пример #31
0
 internal static ODataOutputContext CreateOutputContext(ODataFormat format, ODataMessage message, Encoding encoding, ODataMessageWriterSettings messageWriterSettings, bool writingResponse, IEdmModel model, IODataUrlResolver urlResolver)
 {
     if (format == ODataFormat.Atom)
     {
         return ODataAtomOutputContext.Create(format, message, encoding, messageWriterSettings, writingResponse, model, urlResolver);
     }
     if (format == ODataFormat.VerboseJson)
     {
         return ODataJsonOutputContext.Create(format, message, encoding, messageWriterSettings, writingResponse, model, urlResolver);
     }
     if (format == ODataFormat.Metadata)
     {
         return ODataMetadataOutputContext.Create(format, message, encoding, messageWriterSettings, writingResponse, model, urlResolver);
     }
     if ((format != ODataFormat.Batch) && (format != ODataFormat.RawValue))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataOutputContext_CreateOutputContext_UnrecognizedFormat));
     }
     return ODataRawOutputContext.Create(format, message, encoding, messageWriterSettings, writingResponse, model, urlResolver);
 }