Exemple #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              IServiceProvider serviceProvider,
                              RpcSettings rpcSettings)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var fullNode = serviceProvider.GetService <FullNode>();

            var    authorizedAccess = new RPCAuthorization();
            string cookieStr        = "__cookie__:" + new uint256(RandomUtils.GetBytes(32));

            File.WriteAllText(fullNode.DataFolder.RpcCookieFile, cookieStr);
            authorizedAccess.Authorized.Add(cookieStr);
            if (rpcSettings.RpcPassword != null)
            {
                authorizedAccess.Authorized.Add(rpcSettings.RpcUser + ":" + rpcSettings.RpcPassword);
            }
            authorizedAccess.AllowIp.AddRange(rpcSettings.AllowIp);

            MvcJsonOptions options = GetMVCOptions(serviceProvider);

            Serializer.RegisterFrontConverters(options.SerializerSettings, fullNode.Network);
            app.UseMiddleware(typeof(RPCMiddleware), authorizedAccess);
            app.UseRPC();
        }
        public MvcJsonMvcOptionsSetup(
            ILoggerFactory loggerFactory,
            IOptions <MvcJsonOptions> jsonOptions,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (jsonOptions == null)
            {
                throw new ArgumentNullException(nameof(jsonOptions));
            }

            if (charPool == null)
            {
                throw new ArgumentNullException(nameof(charPool));
            }

            if (objectPoolProvider == null)
            {
                throw new ArgumentNullException(nameof(objectPoolProvider));
            }

            _loggerFactory      = loggerFactory;
            _jsonOptions        = jsonOptions.Value;
            _charPool           = charPool;
            _objectPoolProvider = objectPoolProvider;
        }
        public MvcJsonHalMediaSetup(
            ILoggerFactory loggerFactory,
            IOptions <MvcJsonOptions> jsonOptions,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (jsonOptions == null)
            {
                throw new ArgumentNullException(nameof(jsonOptions));
            }

            if (charPool == null)
            {
                throw new ArgumentNullException(nameof(charPool));
            }

            if (objectPoolProvider == null)
            {
                throw new ArgumentNullException(nameof(objectPoolProvider));
            }

            this.loggerFactory      = loggerFactory;
            this.jsonOptions        = jsonOptions.Value;
            jsonSerializerSettings  = jsonOptions.Value.SerializerSettings;
            this.charPool           = charPool;
            this.objectPoolProvider = objectPoolProvider;
        }
Exemple #4
0
        /// <summary>
        /// Creates a new <see cref="JsonResultExecutor"/>.
        /// </summary>
        /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
        /// <param name="logger">The <see cref="ILogger{JsonResultExecutor}"/>.</param>
        /// <param name="options">The <see cref="IOptions{MvcJsonOptions}"/>.</param>
        /// <param name="charPool">The <see cref="ArrayPool{Char}"/> for creating <see cref="T:char[]"/> buffers.</param>
        public JsonResultExecutor(
            IHttpResponseStreamWriterFactory writerFactory,
            ILogger <JsonResultExecutor> logger,
            IOptions <MvcJsonOptions> options,
            ArrayPool <char> charPool)
        {
            if (writerFactory == null)
            {
                throw new ArgumentNullException(nameof(writerFactory));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (charPool == null)
            {
                throw new ArgumentNullException(nameof(charPool));
            }

            _writerFactory = writerFactory;
            _logger        = logger;
            _options       = options.Value;
            _charPool      = new JsonArrayPool <char>(charPool);
        }
Exemple #5
0
        /// <summary>
        /// 将 <see cref="MaybeJsonConverter"/> 注册到给定的 <see cref="MvcJsonOptions"/> 对象上。
        /// </summary>
        /// <param name="options"><see cref="MvcJsonOptions"/> 对象。</param>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> 为 null。</exception>
        public static MvcJsonOptions AddMaybeJsonConverter(this MvcJsonOptions options)
        {
            Contract.NotNull(options, nameof(options));

            options.SerializerSettings.Converters.Add(new MaybeJsonConverter());
            return(options);
        }
        private static void SetupMvcJsonOption(MvcJsonOptions options)
        {
            options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
            options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            JsonConvert.DefaultSettings = () => options.SerializerSettings;
        }
        /// <summary>
        /// Configures the casing behavior of JSON serialization to use the member's casing for property names,
        /// properties of dynamic types, and dictionary keys.
        /// </summary>
        /// <remarks>
        /// This method modifies <see cref="JsonSerializerSettings.ContractResolver"/>.
        /// </remarks>
        /// <param name="options"><see cref="MvcJsonOptions"/></param>
        /// <returns><see cref="MvcJsonOptions"/> with member casing settings.</returns>
        public static MvcJsonOptions UseMemberCasing(this MvcJsonOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.SerializerSettings.ContractResolver is DefaultContractResolver resolver)
            {
                resolver.NamingStrategy = new DefaultNamingStrategy();
            }
            else
            {
                if (options.SerializerSettings.ContractResolver == null)
                {
                    throw new InvalidOperationException(Resources.FormatContractResolverCannotBeNull(nameof(JsonSerializerSettings.ContractResolver)));
                }

                var contractResolverName = options.SerializerSettings.ContractResolver.GetType().Name;
                throw new InvalidOperationException(
                          Resources.FormatInvalidContractResolverForJsonCasingConfiguration(contractResolverName, nameof(DefaultContractResolver)));
            }

            return(options);
        }
 private static string SerializeToJson(MvcJsonOptions options, object value)
 {
     return(JsonConvert.SerializeObject(
                value: value,
                formatting: Formatting.None,
                settings: options.SerializerSettings));
 }
        // NOTE: This method was created to make sure to create a different instance of contract resolver as by default
        // MvcJsonOptions uses a static shared instance of resolver which when changed causes other tests to fail.
        private MvcJsonOptions CreateDefaultMvcJsonOptions()
        {
            var options = new MvcJsonOptions();

            options.SerializerSettings.ContractResolver = JsonSerializerSettingsProvider.CreateContractResolver();
            return(options);
        }
Exemple #10
0
 public static void Apply(this MvcJsonOptions options, JsonSerializerSettings settings)
 {
     options.SerializerSettings.CheckAdditionalContent = settings.CheckAdditionalContent;
     options.SerializerSettings.ConstructorHandling    = settings.ConstructorHandling;
     options.SerializerSettings.Context              = settings.Context;
     options.SerializerSettings.ContractResolver     = settings.ContractResolver;
     options.SerializerSettings.Converters           = settings.Converters;
     options.SerializerSettings.Culture              = settings.Culture;
     options.SerializerSettings.DateFormatHandling   = settings.DateFormatHandling;
     options.SerializerSettings.DateFormatString     = settings.DateFormatString;
     options.SerializerSettings.DateParseHandling    = settings.DateParseHandling;
     options.SerializerSettings.DateTimeZoneHandling = settings.DateTimeZoneHandling;
     options.SerializerSettings.DefaultValueHandling = settings.DefaultValueHandling;
     options.SerializerSettings.EqualityComparer     = settings.EqualityComparer;
     options.SerializerSettings.Error = settings.Error;
     options.SerializerSettings.FloatFormatHandling            = settings.FloatFormatHandling;
     options.SerializerSettings.FloatParseHandling             = settings.FloatParseHandling;
     options.SerializerSettings.Formatting                     = settings.Formatting;
     options.SerializerSettings.MaxDepth                       = settings.MaxDepth;
     options.SerializerSettings.MetadataPropertyHandling       = settings.MetadataPropertyHandling;
     options.SerializerSettings.MissingMemberHandling          = settings.MissingMemberHandling;
     options.SerializerSettings.NullValueHandling              = settings.NullValueHandling;
     options.SerializerSettings.ObjectCreationHandling         = settings.ObjectCreationHandling;
     options.SerializerSettings.PreserveReferencesHandling     = settings.PreserveReferencesHandling;
     options.SerializerSettings.ReferenceLoopHandling          = settings.ReferenceLoopHandling;
     options.SerializerSettings.ReferenceResolverProvider      = settings.ReferenceResolverProvider;
     options.SerializerSettings.SerializationBinder            = settings.SerializationBinder;
     options.SerializerSettings.StringEscapeHandling           = settings.StringEscapeHandling;
     options.SerializerSettings.TraceWriter                    = settings.TraceWriter;
     options.SerializerSettings.TypeNameAssemblyFormatHandling = settings.TypeNameAssemblyFormatHandling;
     options.SerializerSettings.TypeNameHandling               = settings.TypeNameHandling;
 }
Exemple #11
0
        public ExamplesOperationFilterTests()
        {
            var mvcJsonOptions = new MvcJsonOptions();
            var options        = Options.Create(mvcJsonOptions);

            sut = new ExamplesOperationFilter(options);
        }
Exemple #12
0
 private void AddOptionsForJson(MvcJsonOptions options)
 {
     if ((options != null) && (options.SerializerSettings.ContractResolver != null))
     {
         var castedResolver = options.SerializerSettings.ContractResolver as DefaultContractResolver;
         castedResolver.NamingStrategy = null;
     }
 }
Exemple #13
0
        private static void JsonSetup(MvcJsonOptions options)
        {
            var serializerSettings = GetSerializerSettings();

            options.SerializerSettings.SerializationBinder = serializerSettings.SerializationBinder;
            options.SerializerSettings.TypeNameHandling    = serializerSettings.TypeNameHandling;
            options.SerializerSettings.Formatting          = serializerSettings.Formatting;
        }
 private static void Json(MvcJsonOptions options)
 {
     options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
     options.SerializerSettings.DateFormatHandling    = DateFormatHandling.IsoDateFormat;
     options.SerializerSettings.DateParseHandling     = DateParseHandling.DateTimeOffset;
     options.SerializerSettings.DateTimeZoneHandling  = DateTimeZoneHandling.Utc;
     options.SerializerSettings.MissingMemberHandling = MissingMemberHandling.Ignore;
 }
#pragma warning restore CA1822 // Mark members as static

        /// <summary>
        /// Configure json options
        /// </summary>
        public void ConfigureJsonOptions(MvcJsonOptions options)
        {
            options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            options.SerializerSettings.Converters.Add(new StringEnumConverter
            {
                CamelCaseText = true
            });
        }
 public ErrorController(
     IOptions <UiBrandingHtmlConfiguration> brandingHtml,
     IOptions <MvcJsonOptions> mvcJsonOptions
     )
 {
     _mvcJsonOptions = mvcJsonOptions.Value;
     _brandingHtml   = brandingHtml.Value;
 }
 public CustomJsonInputFormatter(
     ILogger logger,
     JsonSerializerSettings serializerSettings,
     ArrayPool <char> charPool,
     ObjectPoolProvider objectPoolProvider,
     MvcOptions options,
     MvcJsonOptions jsonOptions) : base(logger, serializerSettings, charPool, objectPoolProvider, options, jsonOptions)
 {
 }
Exemple #18
0
        private static MvcJsonOptions MvcJsonOption(this MvcJsonOptions option)
        {
            option.SerializerSettings.Formatting       = Formatting.Indented;
            option.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            option.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            return(option);
        }
 public ConfigureJsonV1MvcOptions(
     ILogger <MvcOptions> logger,
     ObjectPoolProvider objectPoolProvider,
     IOptions <MvcJsonOptions> jsonOptions)
 {
     _logger             = logger;
     _objectPoolProvider = objectPoolProvider;
     _jsonOptions        = jsonOptions.Value;
 }
Exemple #20
0
 /// <summary>
 /// Define Json Format
 /// </summary>
 /// <param name="option"></param>
 private void SetJsonFormat(MvcJsonOptions option)
 {
     option.SerializerSettings.ContractResolver      = new DefaultContractResolver();
     option.SerializerSettings.NullValueHandling     = NullValueHandling.Ignore;
     option.SerializerSettings.Formatting            = Formatting.Indented;
     option.SerializerSettings.MaxDepth              = 4;
     option.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
     option.SerializerSettings.DateFormatString      = "yyyy-MM-ddThh:mm:ss.fff";
 }
 /// <summary>
 /// Registers the date time converter.
 /// </summary>
 /// <param name="option">The option.</param>
 /// <param name="serviceCollection">The service collection.</param>
 /// <returns></returns>
 public static MvcJsonOptions RegisterJsonDateTimeConverter(this MvcJsonOptions option,
                                                            IServiceCollection serviceCollection)
 {
     // TODO: BuildServiceProvider could be optimized
     option.SerializerSettings.Converters.Add(
         new JsonDateTimeConverter(() => serviceCollection.BuildServiceProvider().GetService <IUserInfoService>())
         );
     return(option);
 }
Exemple #22
0
        private static void JsonOptions(MvcJsonOptions options)
        {
            var settings = options.SerializerSettings;

            settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            settings.ContractResolver      = new DefaultContractResolver {
                NamingStrategy = new SnakeCaseNamingStrategy()
            };
        }
Exemple #23
0
        private void ConfigureNamingStrategy(MvcJsonOptions options)
        {
            var contractResolver = options.SerializerSettings?.ContractResolver as DefaultContractResolver;

            if (contractResolver != null)
            {
                contractResolver.NamingStrategy = new CamelCaseNamingStrategy();
            }
        }
Exemple #24
0
        public static MvcJsonOptions ConfigureSerializersSetttings(this MvcJsonOptions options)
        {
            JsonSerializerSettings settings = options.SerializerSettings;

            //options.SerializerSettings.Converters.Add(new JsonDecimalConverterHelper());
            //options.SerializerSettings.Converters.Add(new JsonDatetimeConverterHelper());

            return options;
        }
Exemple #25
0
 private void loadJsonOptions(MvcJsonOptions options)
 {
     options.SerializerSettings.ReferenceLoopHandling          = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
     options.SerializerSettings.MissingMemberHandling          = Newtonsoft.Json.MissingMemberHandling.Ignore;
     options.SerializerSettings.NullValueHandling              = Newtonsoft.Json.NullValueHandling.Ignore;
     options.SerializerSettings.TypeNameHandling               = Newtonsoft.Json.TypeNameHandling.None;
     options.SerializerSettings.TypeNameAssemblyFormatHandling = Newtonsoft.Json.TypeNameAssemblyFormatHandling.Simple;
     options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.None;
 }
        public static void Configure(MvcJsonOptions options)
        {
            var serializerSettings = options.SerializerSettings;

            serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            serializerSettings.Converters.Add(new StringEnumConverter());
            serializerSettings.DateFormatHandling   = DateFormatHandling.IsoDateFormat;
            serializerSettings.DateParseHandling    = DateParseHandling.DateTimeOffset;
            serializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
        }
Exemple #27
0
 public JsonPatchInputFormatter(
     ILogger logger,
     JsonSerializerSettings serializerSettings,
     ArrayPool <char> charPool,
     ObjectPoolProvider objectPoolProvider,
     MvcOptions options,
     MvcJsonOptions jsonOptions) :
     base(logger, serializerSettings, charPool, objectPoolProvider, options, jsonOptions)
 {
     _resolvers = new Dictionary <ITextTransform, JsonContractResolver>();
 }
Exemple #28
0
        private void AddJsonOptions(MvcJsonOptions opcoes)
        {
            //ignore nulls no json
            opcoes.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;

            //Usa camel case no json
            opcoes.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            //não identa o Json (ocupa menos espaço)
            opcoes.SerializerSettings.Formatting = Formatting.None;
        }
        public NdjsonTextWriterFactory(IHttpResponseStreamWriterFactory httpResponseStreamWriterFactory, IOptions <MvcJsonOptions> options, ArrayPool <char> innerJsonArrayPool)
        {
            _httpResponseStreamWriterFactory = httpResponseStreamWriterFactory ?? throw new ArgumentNullException(nameof(httpResponseStreamWriterFactory));
            _options = options?.Value ?? throw new ArgumentNullException(nameof(options));

            if (innerJsonArrayPool == null)
            {
                throw new ArgumentNullException(nameof(innerJsonArrayPool));
            }
            _jsonArrayPool = new JsonArrayPool <char>(innerJsonArrayPool);
        }
Exemple #30
0
        void ConfigureJson(MvcJsonOptions options)
        {
            options.SerializerSettings.ContractResolver = new DefaultContractResolver()
            {
                NamingStrategy = new SnakeCaseNamingStrategy(),
            };

            options.SerializerSettings.Converters.Add(this.bitcoinAddressConverter);
            options.SerializerSettings.Converters.Add(this.moneyConverter);
            options.SerializerSettings.Converters.Add(this.propertyAmountConverter);
            options.SerializerSettings.Converters.Add(this.uint256Converter);
        }