Example #1
0
        private static ODataOutputFormatter CreateApplicationJson(ODataSerializerProvider serializerProvider)
        {
            ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(
                serializerProvider,
                ODataPayloadKind.Feed,
                ODataPayloadKind.Entry,
                ODataPayloadKind.Property,
                ODataPayloadKind.EntityReferenceLink,
                ODataPayloadKind.EntityReferenceLinks,
                ODataPayloadKind.Collection,
                ODataPayloadKind.ServiceDocument,
                ODataPayloadKind.Error,
                ODataPayloadKind.Parameter,
                ODataPayloadKind.Delta);

            // Add minimal metadata as the first media type so it gets used when the request doesn't
            // ask for a specific content type
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataMinimalMetadataStreamingTrue);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataMinimalMetadataStreamingFalse);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataMinimalMetadata);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataFullMetadataStreamingTrue);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataFullMetadataStreamingFalse);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataFullMetadata);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataNoMetadataStreamingTrue);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataNoMetadataStreamingFalse);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataNoMetadata);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonStreamingTrue);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonStreamingFalse);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJson);

            //formatter.AddDollarFormatQueryStringMappings();
            //formatter.AddQueryStringMapping(DollarFormat, JsonFormat, ODataMediaTypes.ApplicationJson);

            return formatter;
        }
Example #2
0
 /// <summary>
 /// Creates a list of media type formatters to handle OData with the given <paramref name="serializerProvider"/>.
 /// </summary>
 /// <param name="serializerProvider">The serializer provider to use.</param>
 /// <returns>A list of media type formatters to handle OData.</returns>
 public static IList<ODataOutputFormatter> Create(ODataSerializerProvider serializerProvider)
 {
     return new List<ODataOutputFormatter>()
     {
         // Place JSON formatter first so it gets used when the request doesn't ask for a specific content type
         CreateApplicationJson(serializerProvider),
         CreateApplicationXml(serializerProvider),
         CreateRawValue(serializerProvider)
     };
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataEdmTypeSerializer"/> class.
        /// </summary>
        /// <param name="payloadKind">The kind of OData payload that this serializer generates.</param>
        /// <param name="serializerProvider">The <see cref="ODataSerializerProvider"/> to use to write inner objects.</param>
        protected ODataEdmTypeSerializer(ODataPayloadKind payloadKind, ODataSerializerProvider serializerProvider)
            : this(payloadKind)
        {
            if (serializerProvider == null)
            {
                throw Error.ArgumentNull("serializerProvider");
            }

            SerializerProvider = serializerProvider;
        }
Example #4
0
        public ODataOutputFormatter(ODataSerializerProvider serializerProvider, IEnumerable<ODataPayloadKind> payloadKinds)
        {
            _messageWriterSettings = new ODataMessageWriterSettings
            {
                Indent = true,
                DisableMessageStreamDisposal = true,
                MessageQuotas = new ODataMessageQuotas { MaxReceivedMessageSize = Int64.MaxValue },
                AutoComputePayloadMetadataInJson = true,
            };

            _serializerProvider = serializerProvider;
            _payloadKinds = payloadKinds;
        }
Example #5
0
 /// <inheritdoc />
 public ODataEntityTypeSerializer(ODataSerializerProvider serializerProvider)
     : base(ODataPayloadKind.Entry, serializerProvider)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RestierEntityTypeSerializer" /> class.
 /// </summary>
 /// <param name="provider">The serializer provider.</param>
 public RestierEntityTypeSerializer(ODataSerializerProvider provider)
     : base(provider)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RestierFeedSerializer" /> class.
 /// </summary>
 /// <param name="provider">The serializer provider.</param>
 public RestierFeedSerializer(ODataSerializerProvider provider)
     : base(provider)
 {
 }
 /// <summary>
 /// Initializes a new instance of <see cref="ODataFeedSerializer"/>.
 /// </summary>
 /// <param name="serializerProvider">The <see cref="ODataSerializerProvider"/> to use to write nested entries.</param>
 public ODataFeedSerializer(ODataSerializerProvider serializerProvider)
     : base(ODataPayloadKind.Feed, serializerProvider)
 {
 }
Example #9
0
        private ODataSerializer GetSerializer(Type type, object value, IEdmModel model, ODataSerializerProvider serializerProvider, HttpRequest request)
        {
            ODataSerializer serializer;

            IEdmObject edmObject = value as IEdmObject;
            if (edmObject != null)
            {
                IEdmTypeReference edmType = edmObject.GetEdmType();
                if (edmType == null)
                {
                    throw new SerializationException(Error.Format(SRResources.EdmTypeCannotBeNull,
                        edmObject.GetType().FullName, typeof(IEdmObject).Name));
                }

                serializer = serializerProvider.GetEdmTypeSerializer(edmType);
                if (serializer == null)
                {
                    string message = Error.Format(SRResources.TypeCannotBeSerialized, edmType.ToTraceString(), typeof(ODataOutputFormatter).Name);
                    throw new SerializationException(message);
                }
            }
            else
            {
                // get the most appropriate serializer given that we support inheritance.
                type = value == null ? type : value.GetType();
                serializer = serializerProvider.GetODataPayloadSerializer(model, type, request);
                if (serializer == null)
                {
                    string message = Error.Format(SRResources.TypeCannotBeSerialized, type.Name, typeof(ODataOutputFormatter).Name);
                    throw new SerializationException(message);
                }
            }

            return serializer;
        }
 /// <summary>
 /// Initializes a new instance of <see cref="ODataResourceSetSerializer"/>.
 /// </summary>
 /// <param name="serializerProvider">The <see cref="ODataSerializerProvider"/> to use to write nested entries.</param>
 public ODataResourceSetSerializer(ODataSerializerProvider serializerProvider)
     : base(ODataPayloadKind.ResourceSet, serializerProvider)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RestierComplexTypeSerializer" /> class.
 /// </summary>
 /// <param name="provider">The serializer provider.</param>
 public RestierComplexTypeSerializer(ODataSerializerProvider provider)
     : base(provider)
 {
 }
Example #12
0
 private static ODataOutputFormatter CreateRawValue(ODataSerializerProvider serializerProvider)
 {
     ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(serializerProvider, ODataPayloadKind.Value);
     //formatter.MediaTypeMappings.Add(new ODataPrimitiveValueMediaTypeMapping());
     //formatter.MediaTypeMappings.Add(new ODataEnumValueMediaTypeMapping());
     //formatter.MediaTypeMappings.Add(new ODataBinaryValueMediaTypeMapping());
     //formatter.MediaTypeMappings.Add(new ODataCountMediaTypeMapping());
     return formatter;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataComplexTypeSerializer"/> class.
 /// </summary>
 /// <param name="serializerProvider">The serializer provider to use to serialize nested objects.</param>
 public ODataComplexTypeSerializer(ODataSerializerProvider serializerProvider)
     : base(ODataPayloadKind.Property, serializerProvider)
 {
 }
Example #14
0
 private static ODataOutputFormatter CreateFormatterWithoutMediaTypes(ODataSerializerProvider serializerProvider, params ODataPayloadKind[] payloadKinds)
 {
     ODataOutputFormatter formatter = new ODataOutputFormatter(serializerProvider, payloadKinds);
     AddSupportedEncodings(formatter);
     return formatter;
 }
Example #15
0
        private static ODataOutputFormatter CreateApplicationXml(ODataSerializerProvider serializerProvider)
        {
            ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(
                serializerProvider,
                ODataPayloadKind.MetadataDocument);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationXml);

            //formatter.AddDollarFormatQueryStringMappings();
            //formatter.AddQueryStringMapping(DollarFormat, XmlFormat, ODataMediaTypes.ApplicationXml);

            return formatter;
        }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataCollectionSerializer"/> class.
 /// </summary>
 /// <param name="serializerProvider">The serializer provider to use to serialize nested objects.</param>
 /// <param name="isForAnnotations">bool value to check if its for instance annotations</param>
 public ODataCollectionSerializer(ODataSerializerProvider serializerProvider, bool isForAnnotations)
     : base(ODataPayloadKind.Collection, serializerProvider)
 {
     this.isForAnnotations = isForAnnotations;
 }
Example #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataCollectionSerializer"/> class.
 /// </summary>
 /// <param name="serializerProvider">The serializer provider to use to serialize nested objects.</param>
 public ODataCollectionSerializer(ODataSerializerProvider serializerProvider)
     : base(ODataPayloadKind.Collection, serializerProvider)
 {
 }
Example #18
0
 /// <summary>
 /// Initializes a new instance of <see cref="ODataEnumSerializer"/>.
 /// </summary>
 public ODataEnumSerializer(ODataSerializerProvider serializerProvider)
     : base(ODataPayloadKind.Property, serializerProvider)
 {
 }