Exemplo n.º 1
0
        //private static ODataOutputFormatter CreateTextPlain(ODataSerializerProvider serializerProvider)
        //{
        //    ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(
        //        serializerProvider,
        //        ODataPayloadKind.Unsupported);
        //    formatter.SupportedMediaTypes.Add(ODataMediaTypes.TextPlain);

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

        //    return formatter;
        //}

        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);
        }
Exemplo n.º 2
0
 private static void AddSupportedEncodings(ODataOutputFormatter formatter)
 {
     // TODO: Restore this
     //formatter.SupportedEncodings.Add(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true));
     // TODO: Restore this
     //formatter.SupportedEncodings.Add(new UnicodeEncoding(bigEndian: false, byteOrderMark: true, throwOnInvalidBytes: true));
 }
Exemplo n.º 3
0
 private static void AddSupportedEncodings(ODataOutputFormatter formatter)
 {
     // TODO: Restore this
     //formatter.SupportedEncodings.Add(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true));
     // TODO: Restore this
     //formatter.SupportedEncodings.Add(new UnicodeEncoding(bigEndian: false, byteOrderMark: true, throwOnInvalidBytes: true));
 }
Exemplo n.º 4
0
        private static ODataOutputFormatter CreateFormatterWithoutMediaTypes(ODataSerializerProvider serializerProvider, params ODataPayloadKind[] payloadKinds)
        {
            ODataOutputFormatter formatter = new ODataOutputFormatter(serializerProvider, payloadKinds);

            AddSupportedEncodings(formatter);
            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 AddDollarFormatQueryStringMappings(this ODataOutputFormatter formatter)
        {
            MediaTypeCollection supportedMediaTypes = formatter.SupportedMediaTypes;

            foreach (string supportedMediaType in supportedMediaTypes)
            {
                QueryStringMediaTypeMapping mapping = new QueryStringMediaTypeMapping(DollarFormat, supportedMediaType);
                formatter.MediaTypeMappings.Add(mapping);
            }
        }
Exemplo n.º 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 ODataBinaryValueMediaTypeMapping());
            formatter.MediaTypeMappings.Add(new ODataCountMediaTypeMapping());
            return(formatter);
        }
Exemplo n.º 8
0
        private static ODataOutputFormatter CreateRawValue(ODataSerializerProvider serializerProvider)
        {
            ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(serializerProvider, ODataPayloadKind.Value);

            //formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/plain"));
            //formatter.MediaTypeMappings.Add(new ODataPrimitiveValueMediaTypeMapping());
            //formatter.MediaTypeMappings.Add(new ODataEnumValueMediaTypeMapping());
            //formatter.MediaTypeMappings.Add(new ODataBinaryValueMediaTypeMapping());
            //formatter.MediaTypeMappings.Add(new ODataCountMediaTypeMapping());
            return(formatter);
        }
 /// <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));
     }
 }
        private static ODataOutputFormatter CreateApplicationXml()
        {
            ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(
                ODataPayloadKind.MetadataDocument);

            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationXml);

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

            return(formatter);
        }
        private static ODataOutputFormatter CreateRawValue()
        {
            ODataOutputFormatter formatter = CreateFormatterWithoutMediaTypes(ODataPayloadKind.Value);

            formatter.SupportedMediaTypes.Add("text/plain");
            formatter.SupportedMediaTypes.Add("application/octet-stream");

            formatter.MediaTypeMappings.Add(new ODataPrimitiveValueMediaTypeMapping());
            formatter.MediaTypeMappings.Add(new ODataEnumValueMediaTypeMapping());
            formatter.MediaTypeMappings.Add(new ODataBinaryValueMediaTypeMapping());
            formatter.MediaTypeMappings.Add(new ODataCountMediaTypeMapping());
            formatter.MediaTypeMappings.Add(new ODataStreamMediaTypeMapping());
            return(formatter);
        }
Exemplo n.º 12
0
 private static ODataOutputFormatter CreateFormatterWithoutMediaTypes(ODataSerializerProvider serializerProvider, params ODataPayloadKind[] payloadKinds)
 {
     ODataOutputFormatter formatter = new ODataOutputFormatter(serializerProvider, payloadKinds);
     AddSupportedEncodings(formatter);
     return formatter;
 }