private static ODataOutputFormatter CreateApplicationJson()
        {
            ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(
                ODataPayloadKind.ResourceSet,
                ODataPayloadKind.Resource,
                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);
        }
        private static ODataOutputFormatter CreateMetadataFormatter()
        {
            ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(ODataPayloadKind.MetadataDocument);

            // put xml before json to make sure xml is the default.
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationXml);

            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJson);
            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.AddDollarFormatQueryStringMappings();
            formatter.AddQueryStringMapping(DollarFormat, XmlFormat, ODataMediaTypes.ApplicationXml);
            formatter.AddQueryStringMapping(DollarFormat, JsonFormat, ODataMediaTypes.ApplicationJson);
            return(formatter);
        }
        private static void AddQueryStringMapping(this ODataOutputFormatter formatter, string queryStringParameterName,
                                                  string queryStringParameterValue, string mediaType)
        {
            QueryStringMediaTypeMapping mapping = new QueryStringMediaTypeMapping(queryStringParameterName, queryStringParameterValue, mediaType);

            formatter.MediaTypeMappings.Add(mapping);
        }
 private static void AddSupportedEncodings(ODataOutputFormatter formatter)
 {
     formatter.SupportedEncodings.Add(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false,
                                                       throwOnInvalidBytes: true));
     formatter.SupportedEncodings.Add(new UnicodeEncoding(bigEndian: false, byteOrderMark: true,
                                                          throwOnInvalidBytes: true));
 }
        private static ODataOutputFormatter CreateFormatterWithoutMediaTypes(params ODataPayloadKind[] payloadKinds)
        {
            ODataOutputFormatter formatter = new ODataOutputFormatter(payloadKinds);

            AddSupportedEncodings(formatter);
            return(formatter);
        }
Example #6
0
 private static void AddSupportedEncodings(ODataOutputFormatter formatter)
 {
     formatter.SupportedEncodings.Add(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false,
         throwOnInvalidBytes: true));
     formatter.SupportedEncodings.Add(new UnicodeEncoding(bigEndian: false, byteOrderMark: true,
         throwOnInvalidBytes: true));
 }
Example #7
0
        private static ODataOutputFormatter CreateRawValue()
        {
            ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(ODataPayloadKind.Value);

            formatter.MediaTypeMappings.Add(new ODataPrimitiveValueMediaTypeMapping());
            formatter.MediaTypeMappings.Add(new ODataEnumValueMediaTypeMapping());
            formatter.MediaTypeMappings.Add(new ODataCountMediaTypeMapping());
            return(formatter);
        }
        private static void AddDollarFormatQueryStringMappings(this ODataOutputFormatter formatter)
        {
            MediaTypeCollection supportedMediaTypes = formatter.SupportedMediaTypes;

            foreach (string supportedMediaType in supportedMediaTypes)
            {
                QueryStringMediaTypeMapping mapping = new QueryStringMediaTypeMapping(DollarFormat, supportedMediaType);
                formatter.MediaTypeMappings.Add(mapping);
            }
        }
Example #9
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);
        }
Example #10
0
 /// <summary>
 /// Internal method used for selecting the base address to be used with OData uris.
 /// If the consumer has provided a delegate for overriding our default implementation,
 /// we call that, otherwise we default to existing behavior below.
 /// </summary>
 /// <param name="request">The HttpRequest object for the given request.</param>
 /// <returns>The base address to be used as part of the service root; must terminate with a trailing '/'.</returns>
 private Uri GetBaseAddressInternal(HttpRequest request)
 {
     if (BaseAddressFactory != null)
     {
         return(BaseAddressFactory(request));
     }
     else
     {
         return(ODataOutputFormatter.GetDefaultBaseAddress(request));
     }
 }
Example #11
0
        private static ODataOutputFormatter CreateApplicationXml()
        {
            ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(
                ODataPayloadKind.MetadataDocument);

            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationXml);

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

            return(formatter);
        }
Example #12
0
 private static ODataOutputFormatter CreateFormatterWithoutMediaTypes(ODataSerializerProvider serializerProvider, params ODataPayloadKind[] payloadKinds)
 {
     ODataOutputFormatter formatter = new ODataOutputFormatter(serializerProvider, payloadKinds);
     AddSupportedEncodings(formatter);
     return formatter;
 }