public static JsonSerializerSettings CreateDefault()
        {
            var s = JsonNetSerializerSettings.CreateDefault();

            s.ContractResolver = new CustomSignalRContractResolverBecauseOfIssue500InSignalR();
            return(s);
        }
コード例 #2
0
        public void Configuration(IAppBuilder appBuilder, Assembly additionalAssembly = null)
        {
            appBuilder.Map("/api", map =>
            {
                map.Use <BodyUrlRouteFix>();
                var config = new HttpConfiguration();

                var jsonMediaTypeFormatter = config.Formatters.JsonFormatter;
                jsonMediaTypeFormatter.SerializerSettings = JsonNetSerializerSettings.CreateDefault();
                jsonMediaTypeFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/vnd.particular.1+json"));
                config.Formatters.Remove(config.Formatters.XmlFormatter);

                config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
                config.Services.Replace(typeof(IAssembliesResolver), new OnlyExecutingAssemblyResolver(additionalAssembly));
                config.MapHttpAttributeRoutes();

                map.UseCors(Cors.AuditCorsOptions);

                config.MessageHandlers.Add(new XParticularVersionHttpHandler());
                config.MessageHandlers.Add(new CompressionEncodingHttpHandler());
                config.MessageHandlers.Add(new CachingHttpHandler());
                config.MessageHandlers.Add(new NotModifiedStatusHttpHandler());

                map.UseWebApi(config);
            });
        }
コード例 #3
0
        static RemoteInstanceSetting[] GetRemoteInstances()
        {
            var valueRead = SettingsReader <string> .Read("RemoteInstances");

            if (!string.IsNullOrEmpty(valueRead))
            {
                var jsonSerializer = JsonSerializer.Create(JsonNetSerializerSettings.CreateDefault());
                using (var jsonReader = new JsonTextReader(new StringReader(valueRead)))
                {
                    return(jsonSerializer.Deserialize <RemoteInstanceSetting[]>(jsonReader) ?? new RemoteInstanceSetting[0]);
                }
            }

            return(new RemoteInstanceSetting[0]);
        }
コード例 #4
0
        public void Should_use_invariant_culture_when_converting_property_names_to_underscore()
        {
            var expected = "{\"message_id\":\"1234\"}";

            using (new DisposableCulture("tr-TR"))
            {
                var serializer = JsonSerializer.Create(JsonNetSerializerSettings.CreateDefault());
                var stream     = new MemoryStream();
                var messages   = CreateMessages();

                using (var writer = new JsonTextWriter(new StreamWriter(stream)))
                {
                    serializer.Serialize(writer, messages);
                }

                Assert.AreEqual(expected, Encoding.Default.GetString(stream.ToArray()));
            }
        }
コード例 #5
0
        public void Configuration(IAppBuilder app)
        {
            app.Use <LogApiCalls>();

            app.UseCors(Cors.GetDefaultCorsOptions());

            var config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();

            var jsonMediaTypeFormatter = config.Formatters.JsonFormatter;

            jsonMediaTypeFormatter.SerializerSettings = JsonNetSerializerSettings.CreateDefault();
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            config.MessageHandlers.Add(new CachingHttpHandler());
            app.UseWebApi(config);
        }
コード例 #6
0
        public void Configuration(IAppBuilder app, Assembly additionalAssembly = null)
        {
            app.Map("/metrics", b =>
            {
                Metric.Config
                    .WithOwin(middleware => b.Use(middleware), config => config
                        .WithMetricsEndpoint(endpointConfig => endpointConfig.MetricsEndpoint(string.Empty)))
                    .WithAllCounters();
            });

            app.Map("/api", b =>
            {
                b.Use<BodyUrlRouteFix>();
                b.Use<LogApiCalls>();

                b.UseCors(Cors.AuditCorsOptions);

                ConfigureSignalR(b);

                var config = new HttpConfiguration();
                config.Services.Replace(typeof(IAssembliesResolver), new OnlyExecutingAssemblyResolver(additionalAssembly));
                config.MapHttpAttributeRoutes();

                config.Services.Replace(typeof(IAssembliesResolver), new OnlyExecutingAssemblyResolver(additionalAssembly));

                var jsonMediaTypeFormatter = config.Formatters.JsonFormatter;
                jsonMediaTypeFormatter.SerializerSettings = JsonNetSerializerSettings.CreateDefault();
                jsonMediaTypeFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/vnd.particular.1+json"));
                config.Formatters.Remove(config.Formatters.XmlFormatter);

                config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

                config.MessageHandlers.Add(new XParticularVersionHttpHandler());
                config.MessageHandlers.Add(new CompressionEncodingHttpHandler());
                config.MessageHandlers.Add(new CachingHttpHandler());
                config.MessageHandlers.Add(new NotModifiedStatusHttpHandler());

                b.UseWebApi(config);
            });
        }