예제 #1
0
 /// <summary>Constructor.</summary>
 /// <param name="messageInfo">The context information for the message.</param>
 /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
 public ODataMetadataJsonInputContext(
     ODataMessageInfo messageInfo,
     ODataMessageReaderSettings messageReaderSettings)
     : base(ODataFormat.Metadata, messageInfo, messageReaderSettings)
 {
     Debug.Assert(messageInfo.MessageStream != null, "messageInfo.MessageStream != null");
     messageStream = messageInfo.MessageStream;
 }
예제 #2
0
 /// <summary>
 /// Asynchronously detects the payload kinds supported by this format for the specified message payload.
 /// </summary>
 /// <param name="messageInfo">The context information for the message.</param>
 /// <param name="settings">Configuration settings of the OData reader.</param>
 /// <returns>A task that when completed returns the set of <see cref="ODataPayloadKind"/>s
 /// that are supported with the specified payload.</returns>
 public override Task <IEnumerable <ODataPayloadKind> > DetectPayloadKindAsync(
     ODataMessageInfo messageInfo,
     ODataMessageReaderSettings settings)
 {
     ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo");
     return(messageInfo.IsResponse
         ? Task.FromResult(DetectPayloadKindImplementation(messageInfo, settings))
         : TaskUtils.GetCompletedTask(Enumerable.Empty <ODataPayloadKind>()));
 }
예제 #3
0
        /// <summary>
        /// Creates an instance of the output context for this format.
        /// </summary>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <returns>Task which represents the pending create operation.</returns>
        public override Task <ODataOutputContext> CreateOutputContextAsync(
            ODataMessageInfo messageInfo,
            ODataMessageWriterSettings messageWriterSettings)
        {
            ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataMetadataFormat_CreateOutputContextAsync));
        }
예제 #4
0
        /// <summary>
        /// Creates an instance of the input context for this format.
        /// </summary>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <returns>The newly created input context.</returns>
        public override ODataInputContext CreateInputContext(
            ODataMessageInfo messageInfo,
            ODataMessageReaderSettings messageReaderSettings)
        {
            ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            return(new ODataMetadataInputContext(messageInfo, messageReaderSettings));
        }
        /// <summary>
        /// Creates an instance of the output context for this format.
        /// </summary>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <returns>The newly created output context.</returns>
        public override ODataOutputContext CreateOutputContext(
            ODataMessageInfo messageInfo,
            ODataMessageWriterSettings messageWriterSettings)
        {
            ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            return(new ODataRawOutputContext(this, messageInfo, messageWriterSettings));
        }
        /// <summary>
        /// Asynchronously creates an instance of the input context for this format.
        /// </summary>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <returns>Task which when completed returned the newly created input context.</returns>
        public override Task <ODataInputContext> CreateInputContextAsync(
            ODataMessageInfo messageInfo,
            ODataMessageReaderSettings messageReaderSettings)
        {
            ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            return(Task.FromResult <ODataInputContext>(
                       new ODataRawInputContext(this, messageInfo, messageReaderSettings)));
        }
예제 #7
0
        /// <summary>
        /// Detects the payload kinds supported by this format for the specified message payload.
        /// </summary>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="settings">Configuration settings of the OData reader.</param>
        /// <returns>The set of <see cref="ODataPayloadKind"/>s that are supported with the specified payload.</returns>
        public override IEnumerable <ODataPayloadKind> DetectPayloadKind(
            ODataMessageInfo messageInfo,
            ODataMessageReaderSettings settings)
        {
            ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo");

            // Metadata is not supported in requests!
            return(messageInfo.IsResponse
                ? DetectPayloadKindImplementation(messageInfo, settings)
                : Enumerable.Empty <ODataPayloadKind>());
        }
예제 #8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="messageReaderSettings">The <see cref="ODataMessageReaderSettings"/> being used for reading the message.</param>
        internal ODataPayloadKindDetectionInfo(
            ODataMessageInfo messageInfo,
            ODataMessageReaderSettings messageReaderSettings)
        {
            ExceptionUtils.CheckArgumentNotNull(messageInfo.MediaType, "messageInfo.MediaType");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "readerSettings");

            this.contentType           = messageInfo.MediaType;
            this.encoding              = messageInfo.Encoding;
            this.messageReaderSettings = messageReaderSettings;
            this.model = messageInfo.Model;
        }
예제 #9
0
        /// <summary>
        /// Write a literal value in JSON Light format.
        /// </summary>
        /// <param name="model">EDM Model to use for validation and type lookups.</param>
        /// <param name="messageWriterSettings">Settings to use when writing.</param>
        /// <param name="textWriter">TextWriter to use as the output for the value.</param>
        /// <param name="writeValue">Delegate to use to actually write the value.</param>
        private static void WriteJsonLightLiteral(IEdmModel model, ODataMessageWriterSettings messageWriterSettings, TextWriter textWriter, Action <ODataJsonLightValueSerializer> writeValue)
        {
            // Calling dispose since it's the right thing to do, but when created from a custom-built TextWriter
            // the output context Dispose will not actually dispose anything, it will just cleanup itself.
            // TODO: URI parser will also support DI container in the future but set the container to null at this moment.
            ODataMessageInfo messageInfo = new ODataMessageInfo
            {
                Model      = model,
                IsAsync    = false,
                IsResponse = false
            };

            using (ODataJsonLightOutputContext jsonOutputContext =
                       new ODataJsonLightOutputContext(textWriter, messageInfo, messageWriterSettings))
            {
                ODataJsonLightValueSerializer jsonLightValueSerializer = new ODataJsonLightValueSerializer(jsonOutputContext);
                writeValue(jsonLightValueSerializer);
                jsonLightValueSerializer.AssertRecursionDepthIsZero();
            }
        }
예제 #10
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        protected ODataOutputContext(
            ODataFormat format,
            ODataMessageInfo messageInfo,
            ODataMessageWriterSettings messageWriterSettings)
        {
            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            this.format = format;
            this.messageWriterSettings = messageWriterSettings;
            this.writingResponse       = messageInfo.IsResponse;
            this.synchronous           = !messageInfo.IsAsync;
            this.model = messageInfo.Model ?? EdmCoreModel.Instance;
            this.payloadUriConverter    = messageInfo.PayloadUriConverter;
            this.container              = messageInfo.Container;
            this.edmTypeResolver        = EdmTypeWriterResolver.Instance;
            this.payloadValueConverter  = ODataPayloadValueConverter.GetPayloadValueConverter(this.container);
            this.writerValidator        = messageWriterSettings.Validator;
            this.odataSimplifiedOptions = ODataSimplifiedOptions.GetODataSimplifiedOptions(this.container);
        }
예제 #11
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        protected ODataInputContext(
            ODataFormat format,
            ODataMessageInfo messageInfo,
            ODataMessageReaderSettings messageReaderSettings)
        {
            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            this.format = format;
            this.messageReaderSettings = messageReaderSettings;
            this.readingResponse       = messageInfo.IsResponse;
            this.synchronous           = !messageInfo.IsAsync;
            this.model = messageInfo.Model ?? EdmCoreModel.Instance;
            this.payloadUriConverter    = messageInfo.PayloadUriConverter;
            this.container              = messageInfo.Container;
            this.edmTypeResolver        = new EdmTypeReaderResolver(this.Model, this.MessageReaderSettings.ClientCustomTypeResolver);
            this.payloadValueConverter  = ODataPayloadValueConverter.GetPayloadValueConverter(this.container);
            this.odataSimplifiedOptions = ODataSimplifiedOptions.GetODataSimplifiedOptions(this.container, messageReaderSettings.Version);
        }
예제 #12
0
        private static object ConvertFromResourceOrCollectionValue(string value, IEdmModel model, IEdmTypeReference typeReference)
        {
            ODataMessageReaderSettings settings = new ODataMessageReaderSettings();

            settings.Validations        &= ~ValidationKinds.ThrowOnUndeclaredPropertyForNonOpenType;
            settings.ReadUntypedAsString = false;

            using (StringReader reader = new StringReader(value))
            {
                ODataMessageInfo messageInfo = new ODataMessageInfo
                {
                    MediaType     = new ODataMediaType(MimeConstants.MimeApplicationType, MimeConstants.MimeJsonSubType),
                    Model         = model,
                    IsResponse    = false,
                    IsAsync       = false,
                    MessageStream = null,
                };

                using (ODataJsonLightInputContext context = new ODataJsonLightInputContext(reader, messageInfo, settings))
                {
                    ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(context);

                    // TODO: The way JSON array literals look in the URI is different that response payload with an array in it.
                    // The fact that we have to manually setup the underlying reader shows this different in the protocol.
                    // There is a discussion on if we should change this or not.
                    deserializer.JsonReader.Read(); // Move to first thing
                    object rawResult = deserializer.ReadNonEntityValue(
                        null /*payloadTypeName*/,
                        typeReference,
                        null /*DuplicatePropertyNameChecker*/,
                        null /*CollectionWithoutExpectedTypeValidator*/,
                        true /*validateNullValue*/,
                        false /*isTopLevelPropertyValue*/,
                        false /*insideResourceValue*/,
                        null /*propertyName*/);
                    deserializer.ReadPayloadEnd(false);

                    return(rawResult);
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        internal ODataMetadataOutputContext(
            ODataMessageInfo messageInfo,
            ODataMessageWriterSettings messageWriterSettings)
            : base(ODataFormat.Metadata, messageInfo, messageWriterSettings)
        {
            Debug.Assert(messageInfo.MessageStream != null, "messageInfo.MessageStream != null");

            try
            {
                this.messageOutputStream = messageInfo.MessageStream;

                Stream outputStream;
                if (this.Synchronous)
                {
                    outputStream = this.messageOutputStream;
                }
                else
                {
#if NETSTANDARD1_1
                    this.asynchronousOutputStream = new AsyncBufferedStream(this.messageOutputStream);
#else
                    this.asynchronousOutputStream = new BufferedStream(this.messageOutputStream, ODataConstants.DefaultOutputBufferSize);
#endif
                    outputStream = this.asynchronousOutputStream;
                }

                this.xmlWriter = ODataMetadataWriterUtils.CreateXmlWriter(outputStream, messageWriterSettings, messageInfo.Encoding);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the output context.
                if (ExceptionUtils.IsCatchableExceptionType(e))
                {
                    this.messageOutputStream.Dispose();
                }

                throw;
            }
        }
예제 #14
0
        /// <summary>
        /// Write a literal value in JSON Light format.
        /// </summary>
        /// <param name="model">EDM Model to use for validation and type lookups.</param>
        /// <param name="messageWriterSettings">Settings to use when writing.</param>
        /// <param name="textWriter">TextWriter to use as the output for the value.</param>
        /// <param name="writeValue">Delegate to use to actually write the value.</param>
        /// <param name="isResourceValue">We want to pass the <see cref="IDuplicatePropertyNameChecker"/> instance to the Action delegate when writing Resource value but not Collection value.</param>
        private static void WriteJsonLightLiteral(IEdmModel model, ODataMessageWriterSettings messageWriterSettings, TextWriter textWriter, Action <ODataJsonLightValueSerializer, IDuplicatePropertyNameChecker> writeValue, bool isResourceValue = true)
        {
            IEnumerable <KeyValuePair <string, string> > parameters = new Dictionary <string, string>
            {
                { MimeConstants.MimeIeee754CompatibleParameterName, messageWriterSettings.IsIeee754Compatible.ToString() }
            };
            ODataMediaType mediaType = new ODataMediaType(MimeConstants.MimeApplicationType, MimeConstants.MimeJsonSubType, parameters);

            // Calling dispose since it's the right thing to do, but when created from a custom-built TextWriter
            // the output context Dispose will not actually dispose anything, it will just cleanup itself.
            // TODO: URI parser will also support DI container in the future but set the container to null at this moment.
            ODataMessageInfo messageInfo = new ODataMessageInfo
            {
                Model      = model,
                IsAsync    = false,
                IsResponse = false,
                MediaType  = mediaType
            };

            using (ODataJsonLightOutputContext jsonOutputContext =
                       new ODataJsonLightOutputContext(textWriter, messageInfo, messageWriterSettings))
            {
                ODataJsonLightValueSerializer jsonLightValueSerializer = new ODataJsonLightValueSerializer(jsonOutputContext);

                if (!isResourceValue)
                {
                    writeValue(jsonLightValueSerializer, null);
                }
                else
                {
                    IDuplicatePropertyNameChecker duplicatePropertyNameChecker = jsonLightValueSerializer.GetDuplicatePropertyNameChecker();
                    writeValue(jsonLightValueSerializer, duplicatePropertyNameChecker);
                    jsonLightValueSerializer.ReturnDuplicatePropertyNameChecker(duplicatePropertyNameChecker);
                }

                jsonLightValueSerializer.AssertRecursionDepthIsZero();
            }
        }
예제 #15
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="messageInfo">The context information for the message.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        internal ODataMetadataOutputContext(
            ODataMessageInfo messageInfo,
            ODataMessageWriterSettings messageWriterSettings)
            : base(ODataFormat.Metadata, messageInfo, messageWriterSettings)
        {
            Debug.Assert(messageInfo.MessageStream != null, "messageInfo.MessageStream != null");
            Debug.Assert(!messageInfo.IsAsync, "Metadata output context is only supported in synchronous operations.");

            try
            {
                this.messageOutputStream = messageInfo.MessageStream;
                this.xmlWriter           = ODataMetadataWriterUtils.CreateXmlWriter(this.messageOutputStream, messageWriterSettings, messageInfo.Encoding);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the output context.
                if (ExceptionUtils.IsCatchableExceptionType(e))
                {
                    this.messageOutputStream.Dispose();
                }

                throw;
            }
        }
예제 #16
0
 /// <summary>
 /// Detects the payload kinds supported by this format for the specified message payload.
 /// </summary>
 /// <param name="messageInfo">The context information for the message.</param>
 /// <param name="settings">Configuration settings of the OData reader.</param>
 /// <returns>The set of <see cref="ODataPayloadKind"/>s that are supported with the specified payload.</returns>
 /// <remarks>
 /// The stream returned by GetMessageStream of <paramref name="messageInfo"/> could be used for reading for
 /// payload kind detection. Reading this stream won't affect later reading operations of payload processing.
 /// </remarks>
 public abstract IEnumerable <ODataPayloadKind> DetectPayloadKind(ODataMessageInfo messageInfo, ODataMessageReaderSettings settings);
예제 #17
0
 /// <summary>
 /// Asynchronously detects the payload kinds supported by this format for the specified message payload.
 /// </summary>
 /// <param name="messageInfo">The context information for the message.</param>
 /// <param name="settings">Configuration settings of the OData reader.</param>
 /// <returns>A task that when completed returns the set of <see cref="ODataPayloadKind"/>s
 /// that are supported with the specified payload.</returns>
 /// <remarks>
 /// The stream returned by GetMessageStream of <paramref name="messageInfo"/> could be used for reading for
 /// payload kind detection. Reading this stream won't affect later reading operations of payload processing.
 /// </remarks>
 public abstract Task <IEnumerable <ODataPayloadKind> > DetectPayloadKindAsync(ODataMessageInfo messageInfo, ODataMessageReaderSettings settings);
예제 #18
0
 /// <summary>
 /// Asynchronously creates an instance of the input context for this format.
 /// </summary>
 /// <param name="messageInfo">The context information for the message.</param>
 /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
 /// <returns>Task which when completed returned the newly created input context.</returns>
 public abstract Task <ODataInputContext> CreateInputContextAsync(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings);
예제 #19
0
 /// <summary>
 /// Creates an instance of the output context for this format.
 /// </summary>
 /// <param name="messageInfo">The context information for the message.</param>
 /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
 /// <returns>Task which represents the pending create operation.</returns>
 public abstract Task <ODataOutputContext> CreateOutputContextAsync(ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings);
예제 #20
0
 /// <summary>
 /// Creates an instance of the output context for this format.
 /// </summary>
 /// <param name="messageInfo">The context information for the message.</param>
 /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
 /// <returns>The newly created output context.</returns>
 public abstract ODataOutputContext CreateOutputContext(ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings);
예제 #21
0
 /// <summary>
 /// Creates an instance of the input context for this format.
 /// </summary>
 /// <param name="messageInfo">The context information for the message.</param>
 /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
 /// <returns>The newly created input context.</returns>
 public abstract ODataInputContext CreateInputContext(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings);