private static ODataMediaTypeFormatter CreateApplicationJson(ODataSerializerProvider serializerProvider, ODataDeserializerProvider deserializerProvider)
        {
            ODataMediaTypeFormatter formatter = CreateFormatterWithoutMediaTypes(
                serializerProvider,
                deserializerProvider,
                ODataPayloadKind.Feed,
                ODataPayloadKind.Entry,
                ODataPayloadKind.Property,
                ODataPayloadKind.EntityReferenceLink,
                ODataPayloadKind.EntityReferenceLinks,
                ODataPayloadKind.Collection,
                ODataPayloadKind.ServiceDocument,
                ODataPayloadKind.Error,
                ODataPayloadKind.Parameter);

            // 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;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataMediaTypeFormatter"/> class.
        /// </summary>
        /// <param name="deserializerProvider">The <see cref="ODataDeserializerProvider"/> to use.</param>
        /// <param name="serializerProvider">The <see cref="ODataSerializerProvider"/> to use.</param>
        /// <param name="payloadKinds">The kind of payloads this formatter supports.</param>
        public ODataMediaTypeFormatter(ODataDeserializerProvider deserializerProvider, ODataSerializerProvider serializerProvider,
            IEnumerable<ODataPayloadKind> payloadKinds)
        {
            if (deserializerProvider == null)
            {
                throw Error.ArgumentNull("deserializerProvider");
            }
            if (serializerProvider == null)
            {
                throw Error.ArgumentNull("serializerProvider");
            }
            if (payloadKinds == null)
            {
                throw Error.ArgumentNull("payloadKinds");
            }

            _deserializerProvider = deserializerProvider;
            _serializerProvider = serializerProvider;
            _payloadKinds = payloadKinds;

            // Maxing out the received message size as we depend on the hosting layer to enforce this limit.
            MessageWriterSettings = new ODataMessageWriterSettings
            {
                Indent = true,
                DisableMessageStreamDisposal = true,
                MessageQuotas = new ODataMessageQuotas { MaxReceivedMessageSize = Int64.MaxValue }
            };
            MessageReaderSettings = new ODataMessageReaderSettings
            {
                DisableMessageStreamDisposal = true,
                MessageQuotas = new ODataMessageQuotas { MaxReceivedMessageSize = Int64.MaxValue },
            };

            _version = DefaultODataVersion;
        }
 private static ODataMediaTypeFormatter CreateRawValue(ODataSerializerProvider serializerProvider, ODataDeserializerProvider deserializerProvider)
 {
     ODataMediaTypeFormatter formatter = CreateFormatterWithoutMediaTypes(serializerProvider, deserializerProvider, ODataPayloadKind.Value);
     formatter.MediaTypeMappings.Add(new ODataPrimitiveValueMediaTypeMapping());
     formatter.MediaTypeMappings.Add(new ODataEnumValueMediaTypeMapping());
     formatter.MediaTypeMappings.Add(new ODataBinaryValueMediaTypeMapping());
     return formatter;
 }
        private static ODataMediaTypeFormatter CreateApplicationAtomSvcXml(ODataSerializerProvider serializerProvider, ODataDeserializerProvider deserializerProvider)
        {
            ODataMediaTypeFormatter formatter = CreateFormatterWithoutMediaTypes(serializerProvider, deserializerProvider, ODataPayloadKind.ServiceDocument);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationAtomSvcXml);

            formatter.AddDollarFormatQueryStringMappings();

            return formatter;
        }
 /// <summary>
 /// Creates a list of media type formatters to handle OData with the given <paramref name="serializerProvider"/> and 
 /// <paramref name="deserializerProvider"/>.
 /// </summary>
 /// <param name="serializerProvider">The serializer provider to use.</param>
 /// <param name="deserializerProvider">The deserializer provider to use.</param>
 /// <returns>A list of media type formatters to handle OData.</returns>
 public static IList<ODataMediaTypeFormatter> Create(ODataSerializerProvider serializerProvider, ODataDeserializerProvider deserializerProvider)
 {
     return new List<ODataMediaTypeFormatter>()
     {
         // Place JSON formatter first so it gets used when the request doesn't ask for a specific content type
         CreateApplicationJson(serializerProvider, deserializerProvider),
         CreateApplicationXml(serializerProvider, deserializerProvider),
         CreateRawValue(serializerProvider, deserializerProvider)
     };
 }
        /// <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;
        }
 /// <summary>
 /// Creates a list of media type formatters to handle OData with the given <paramref name="serializerProvider"/> and 
 /// <paramref name="deserializerProvider"/>.
 /// </summary>
 /// <param name="serializerProvider">The serializer provider to use.</param>
 /// <param name="deserializerProvider">The deserializer provider to use.</param>
 /// <returns>A list of media type formatters to handle OData.</returns>
 /// <remarks>The default serializer provider is <see cref="DefaultODataSerializerProvider"/> and the default deserializer provider is
 /// <see cref="DefaultODataDeserializerProvider"/>.</remarks>
 public static IList<ODataMediaTypeFormatter> Create(ODataSerializerProvider serializerProvider, ODataDeserializerProvider deserializerProvider)
 {
     return new List<ODataMediaTypeFormatter>()
     {
         // Create atomsvc+xml formatter first to handle service document requests without an Accept header in an XML format
         CreateApplicationAtomSvcXml(serializerProvider, deserializerProvider),
         // Create JSON formatter next so it gets used when the request doesn't ask for a specific content type
         CreateApplicationJson(serializerProvider, deserializerProvider),
         CreateApplicationAtomXmlTypeFeed(serializerProvider, deserializerProvider),
         CreateApplicationAtomXmlTypeEntry(serializerProvider, deserializerProvider),
         CreateApplicationXml(serializerProvider, deserializerProvider),
         CreateTextXml(serializerProvider, deserializerProvider),
         CreateRawValue(serializerProvider, deserializerProvider)
     };
 }
        public ODataEntityTypeSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();

            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Customer"), new ClrTypeAnnotation(typeof(Customer)));
            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Order"), new ClrTypeAnnotation(typeof(Order)));

            _customerSet = _model.FindDeclaredEntityContainer("Default.Container").FindEntitySet("Customers");
            _customer = new Customer()
            {
                FirstName = "Foo",
                LastName = "Bar",
                ID = 10,
            };

            _serializerProvider = new DefaultODataSerializerProvider();
            _customerType = _model.GetEdmTypeReference(typeof(Customer)).AsEntity();
            _serializer = new ODataEntityTypeSerializer(_serializerProvider);
            _path = new ODataPath(new EntitySetPathSegment(_customerSet));
            _writeContext = new ODataSerializerContext() { EntitySet = _customerSet, Model = _model, Path = _path };
            _entityInstanceContext = new EntityInstanceContext(_writeContext, _customerSet.ElementType.AsReference(), _customer);
        }
 public NullEntityTypeSerializer(ODataSerializerProvider serializerProvider)
     : base(serializerProvider)
 {
 }
 /// <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)
 {
 }
 private static ODataMediaTypeFormatter CreateFormatterWithoutMediaTypes(ODataSerializerProvider serializerProvider, ODataDeserializerProvider deserializerProvider, params ODataPayloadKind[] payloadKinds)
 {
     ODataMediaTypeFormatter formatter = new ODataMediaTypeFormatter(deserializerProvider, serializerProvider, payloadKinds);
     AddSupportedEncodings(formatter);
     return formatter;
 }
Exemple #12
0
 /// <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)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataDomainFeedSerializer" /> class.
 /// </summary>
 /// <param name="provider">The serializer provider.</param>
 public ODataDomainFeedSerializer(ODataSerializerProvider provider)
     : base(provider)
 {
 }
 /// <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)
 {
 }
        private ODataSerializer GetSerializer(Type type, object value, IEdmModel model, ODataSerializerProvider serializerProvider)
        {
            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(ODataMediaTypeFormatter).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(ODataMediaTypeFormatter).Name);
                    throw new SerializationException(message);
                }
            }

            return serializer;
        }
 /// <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)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RestierCollectionSerializer" /> class.
 /// </summary>
 /// <param name="provider">The serializer provider.</param>
 public RestierCollectionSerializer(ODataSerializerProvider provider)
     : base(provider)
 {
 }
        private static ODataMediaTypeFormatter CreateTextXml(ODataSerializerProvider serializerProvider, ODataDeserializerProvider deserializerProvider)
        {
            ODataMediaTypeFormatter formatter = CreateFormatterWithoutMediaTypes(
                serializerProvider,
                deserializerProvider,
                ODataPayloadKind.Property,
                ODataPayloadKind.EntityReferenceLink,
                ODataPayloadKind.EntityReferenceLinks,
                ODataPayloadKind.Collection);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.TextXml);

            formatter.AddDollarFormatQueryStringMappings();

            return formatter;
        }
 /// <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)
 {
 }
        private static ODataMediaTypeFormatter CreateApplicationXml(ODataSerializerProvider serializerProvider, ODataDeserializerProvider deserializerProvider)
        {
            ODataMediaTypeFormatter formatter = CreateFormatterWithoutMediaTypes(
                serializerProvider,
                deserializerProvider,
                ODataPayloadKind.Property,
                ODataPayloadKind.EntityReferenceLink,
                ODataPayloadKind.EntityReferenceLinks,
                ODataPayloadKind.Collection,
                ODataPayloadKind.ServiceDocument,
                ODataPayloadKind.MetadataDocument,
                ODataPayloadKind.Error);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationXml);

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

            return formatter;
        }
 /// <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)
 {
 }
 public CustomEntrySerializer(ODataSerializerProvider serializerProvider)
     : base(serializerProvider)
 {
 }
Exemple #23
0
 /// <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)
 {
 }
 /// <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="ODataEnumSerializer"/>.
 /// </summary>
 public ODataEnumSerializer(ODataSerializerProvider serializerProvider)
     : base(ODataPayloadKind.Property, serializerProvider)
 {
 }
 public AnnotatingEntitySerializer(ODataSerializerProvider serializerProvider)
     : base(serializerProvider)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataMediaTypeFormatter"/> class.
        /// </summary>
        /// <param name="formatter">The <see cref="ODataMediaTypeFormatter"/> to copy settings from.</param>
        /// <param name="version">The OData version that this formatter supports.</param>
        /// <param name="request">The <see cref="HttpRequestMessage"/> for the per-request formatter instance.</param>
        /// <remarks>This is a copy constructor to be used in <see cref="GetPerRequestFormatterInstance"/>.</remarks>
        internal ODataMediaTypeFormatter(ODataMediaTypeFormatter formatter, ODataVersion version, HttpRequestMessage request)
            : base(formatter)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            Contract.Assert(formatter._serializerProvider != null);
            Contract.Assert(formatter._deserializerProvider != null);
            Contract.Assert(formatter._payloadKinds != null);

            // Parameter 1: formatter

            // Execept for the other two parameters, this constructor is a copy constructor, and we need to copy
            // everything on the other instance.

            // Copy this class's private fields and internal properties.
            _serializerProvider = formatter._serializerProvider;
            _deserializerProvider = formatter._deserializerProvider;
            _payloadKinds = formatter._payloadKinds;
            MessageWriterSettings = formatter.MessageWriterSettings;
            MessageReaderSettings = formatter.MessageReaderSettings;

            // Parameter 2: version
            _version = version;

            // Parameter 3: request
            Request = request;
        }
 /// <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)
 {
 }
Exemple #29
0
 /// <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="ODataDomainEntityTypeSerializer" /> class.
 /// </summary>
 /// <param name="provider">The serializer provider.</param>
 public ODataDomainEntityTypeSerializer(ODataSerializerProvider provider)
     : base(provider)
 {
 }
        private static ODataMediaTypeFormatter CreateApplicationAtomXmlTypeEntry(ODataSerializerProvider serializerProvider, ODataDeserializerProvider deserializerProvider)
        {
            ODataMediaTypeFormatter formatter = CreateFormatterWithoutMediaTypes(serializerProvider, deserializerProvider, ODataPayloadKind.Entry);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationAtomXmlTypeEntry);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationAtomXml);

            formatter.AddDollarFormatQueryStringMappings();
            formatter.AddQueryStringMapping(DollarFormat, AtomFormat, ODataMediaTypes.ApplicationAtomXml);

            return formatter;
        }
 /// <inheritdoc />
 public ODataEntityTypeSerializer(ODataSerializerProvider serializerProvider)
     : base(ODataPayloadKind.Entry, serializerProvider)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RestierResourceSetSerializer" /> class.
 /// </summary>
 /// <param name="provider">The serializer provider.</param>
 public RestierResourceSetSerializer(ODataSerializerProvider provider)
     : base(provider)
 {
 }
 public CustomFeedSerializer(ODataSerializerProvider serializerProvider)
     : base(serializerProvider)
 {
 }
 /// <inheritdoc />
 public ODataEntityTypeSerializer(ODataSerializerProvider serializerProvider)
     : base(ODataPayloadKind.Entry, serializerProvider)
 {
 }
 public CustomFormatter(ODataDeserializerProvider oDataDeserializerProvider,
     ODataSerializerProvider oDataSerializerProvider, params ODataPayloadKind[] kinds)
     : base(oDataDeserializerProvider, oDataSerializerProvider, kinds)
 {
     this.MessageWriterSettings.MediaTypeResolver = new MixResolver();
 }