/// <summary>Main entry-point for this application.</summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            // setup our configuration (command line > environment > appsettings.json)
            Configuration = new ConfigurationBuilder()
                            .AddJsonFile("appsettings.json", optional: true)
                            .AddEnvironmentVariables()
                            .Build()
            ;

            // update configuration to make sure listen url is properly formatted
            Regex regex = new Regex(_regexBaseUrlMatch);
            Match match = regex.Match(Configuration["Basic_Internal_Url"]);

            Configuration["Basic_Internal_Url"] = match.ToString();

            // create our rest client
            _restClient = new HttpClient();

            // configure serialization
            _contractResolver = new CamelCasePropertyNamesContractResolver();

            // create our web host
            (new Thread(() =>
            {
                CreateWebHostBuilder(args).Build().Run();
            })).Start();

            // start our process
            StartProcessing();
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddConfigurationOptions(Configuration);

            services.AddHttpContextAccessor();
            services.AddPerformance();
            services.AddSecurity(Configuration);
            services.AddSingletonService();
            services.AddScopedService();
            services.AddDbContextService();
            services.AddRxWebLocalization();
            services.AddControllers();
            services.AddSwaggerOptions();
            services.AddMvc(options =>
            {
                options.AddRxWebSanitizers();
                options.AddValidation();
            }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0).AddNewtonsoftJson(
                oo =>
            {
                var resolver = new CamelCasePropertyNamesContractResolver();
                if (resolver != null)
                {
                    var res            = resolver as DefaultContractResolver;
                    res.NamingStrategy = null;
                }
                oo.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });
        }
Exemple #3
0
 public NFCertaJsonSerializer()
 {
     ContractResolver   = new CamelCasePropertyNamesContractResolver();
     DateFormatHandling = DateFormatHandling.IsoDateFormat;
     DateParseHandling  = DateParseHandling.DateTimeOffset;
     Converters.Add(new StringEnumConverter());
 }
        public static string GetFields(Type type)
        {
            var resolver = new CamelCasePropertyNamesContractResolver();
            var contract = (JsonObjectContract)resolver.ResolveContract(type);

            return(string.Join(",", contract.Properties.Select(p => p.PropertyName)));
        }
 /// <summary>
 /// Constructor method.
 /// </summary>
 public SharedJsonSettings()
 {
     NullValueHandling     = NullValueHandling.Ignore;
     ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
     Culture          = System.Threading.Thread.CurrentThread.CurrentCulture;
     ContractResolver = new CamelCasePropertyNamesContractResolver();
 }
        public Startup(IConfiguration configuration, IHostEnvironment env)
        {
            Startup.Configuration = configuration;

            // https://github.com/drwatson1/AspNet-Core-REST-Service/wiki#using-environment-variables-in-configuration-options
            var envPath = Path.Combine(env.ContentRootPath, ".env");

            DotNetEnv.Env.Load(envPath);

            // See: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki#content-formatting
            JsonConvert.DefaultSettings = () =>
            {
                var settings = new JsonSerializerSettings()
                {
                    ContractResolver      = new CamelCasePropertyNamesContractResolver(),
                    NullValueHandling     = NullValueHandling.Ignore,
                    DefaultValueHandling  = DefaultValueHandling.Include,
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
#if DEBUG
                    Formatting = Formatting.Indented
#else
                    Formatting = Formatting.None
#endif
                };
                settings.Converters.Add(new StringEnumConverter {
                    CamelCaseText = true
                });
                return(settings);
            };
        }
Exemple #7
0
 public JsonSettings()
 {
     ContractResolver  = new CamelCasePropertyNamesContractResolver();
     Formatting        = Formatting.Indented;
     TypeNameHandling  = TypeNameHandling.None;
     NullValueHandling = NullValueHandling.Include;
 }
Exemple #8
0
 public CamelCaseJsonSerializerSettings()
 {
     ContractResolver = new CamelCasePropertyNamesContractResolver();
     Converters.Add(new StringEnumConverter {
         CamelCaseText = true
     });
 }
 public CamelCaseJsonSerializer()
 {
     ContractResolver     = new CamelCasePropertyNamesContractResolver();
     DateFormatHandling   = DateFormatHandling.IsoDateFormat;
     DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
     Formatting           = Formatting.Indented;
 }
Exemple #10
0
        public Startup(IConfiguration configuration, IHostEnvironment env)
        {
            Startup.Configuration = configuration;

            var envPath = Path.Combine(env.ContentRootPath, ".env");

            if (File.Exists(envPath))
            {
                DotNetEnv.Env.Load();
            }

            JsonConvert.DefaultSettings = () =>
                                          new JsonSerializerSettings()
            {
                ContractResolver      = new CamelCasePropertyNamesContractResolver(),
                NullValueHandling     = NullValueHandling.Ignore,
                DefaultValueHandling  = DefaultValueHandling.Include,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
#if DEBUG
                Formatting = Formatting.Indented
#else
                Formatting = Formatting.None
#endif
            };
        }
Exemple #11
0
 public void SetUp()
 {
     _container = new Container
     {
         Name          = "Something",
         PaymentModels = new List <BasePaymentModel>
         {
             new AchInputModel
             {
                 PaymentType   = "ach",
                 PaymentEnum   = PaymentType.One,
                 PaymentNumber = 1,
                 AccountNumber = "123"
             },
             new CreditCardInputModel
             {
                 PaymentType   = "cc",
                 PaymentEnum   = PaymentType.Two,
                 PaymentNumber = 2,
                 Name          = "John"
             },
             new PayPalInputModel
             {
                 PaymentType   = "paypal",
                 PaymentEnum   = PaymentType.Three,
                 PaymentNumber = 3,
                 CancelUrl     = "https://cancel.com"
             }
         }
     };
     _resolver = new CamelCasePropertyNamesContractResolver();
 }
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            config.Formatters.Clear();
            config.Formatters.Add(new JsonMediaTypeFormatter());
            var item = new CamelCasePropertyNamesContractResolver();

            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = item;

            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            var corsAttr = new EnableCorsAttribute("*", "*", "*");

            config.EnableCors(corsAttr);


            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "SearchAPI",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional });

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional });
        }
Exemple #13
0
        /// <summary>
        /// Converts the inheriting class to a JSON-formatted string using programmed serializers adding in the contents from the specified generic dictionary.
        /// </summary>
        /// <param name="parameters">The dictionary that will have it contents added to resulting JSON string.</param>
        public virtual string ToJson(IDictionary parameters)
        {
            var camel      = new CamelCasePropertyNamesContractResolver();
            var cSerialize = new JsonSerializer
            {
                ContractResolver = camel
            };

            var serializer = new JsonSerializerSettings
            {
                ContractResolver      = camel,
                DateFormatHandling    = DateFormatHandling.IsoDateFormat,
                DateTimeZoneHandling  = DateTimeZoneHandling.Utc,
                DefaultValueHandling  = DefaultValueHandling.Populate,
                Formatting            = Formatting.Indented,
                NullValueHandling     = NullValueHandling.Include,
                MissingMemberHandling = MissingMemberHandling.Error
            };

            serializer.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy()));

            var job = JObject.FromObject(this, cSerialize);

            string[] keys = parameters.Keys.Cast <string>().ToArray();
            for (int i = 0; i < keys.Length; i++)
            {
                string key = keys[i];
                job.Add(key, JToken.FromObject(parameters[key], cSerialize));
            }

            return(JsonConvert.SerializeObject(job, serializer));
        }
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="value"></param>
        /// <param name="serializer"></param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var extension = value as UiExtension;

            if (extension == null)
            {
                return;
            }
            var extensionStructure = new
            {
                extension
            };

            var resolver = new CamelCasePropertyNamesContractResolver();

            resolver.NamingStrategy.OverrideSpecifiedNames = false;

            var settings = new JsonSerializerSettings
            {
                ContractResolver = resolver,
            };

            var jObject = JObject.FromObject(extensionStructure, JsonSerializer.Create(settings));

            serializer.Serialize(writer, jObject);
        }
        public ClientConfiguration()
        {
            UseSsl                          = false;
            SslPort                         = 11207;
            ApiPort                         = 8092;
            DirectPort                      = 11210;
            MgmtPort                        = 8091;
            HttpsMgmtPort                   = 18091;
            HttpsApiPort                    = 18092;
            ObserveInterval                 = 10;    //ms
            ObserveTimeout                  = 500;   //ms
            MaxViewRetries                  = 2;
            ViewHardTimeout                 = 30000; //ms
            HeartbeatConfigInterval         = 10000; //ms
            EnableConfigHeartBeat           = true;
            SerializationContractResolver   = new CamelCasePropertyNamesContractResolver();
            DeserializationContractResolver = new CamelCasePropertyNamesContractResolver();

            PoolConfiguration = new PoolConfiguration();
            BucketConfigs     = new Dictionary <string, BucketConfiguration>
            {
                { DefaultBucket, new BucketConfiguration
                  {
                      PoolConfiguration = PoolConfiguration
                  } }
            };
            Servers = new List <Uri> {
                _defaultServer
            };

            //Set back to default
            _serversChanged           = false;
            _poolConfigurationChanged = false;
        }
Exemple #16
0
        /// <summary>
        /// Converts string to camel-case formatted string
        /// </summary>
        /// <param name="str"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static string ToCamelCase(this string str, Action <CamelCasePropertyNamesContractResolver> config = null)
        {
            var camelCase = new CamelCasePropertyNamesContractResolver();

            config?.Invoke(camelCase);
            return(camelCase.GetResolvedPropertyName(str));
        }
Exemple #17
0
        /// <summary>
        /// Registers all Web API routes
        /// </summary>
        /// <param name="config"></param>
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "APIWithActions",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );


            var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");

            config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            //((DefaultContractResolver)config.Formatters.JsonFormatter.SerializerSettings.ContractResolver).IgnoreSerializableAttribute = true;
            var jsonFormatter    = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
            var contractResolver = new CamelCasePropertyNamesContractResolver();

            contractResolver.IgnoreSerializableAttribute      = true;
            jsonFormatter.SerializerSettings.ContractResolver = contractResolver;
        }
Exemple #18
0
        public static void Register(HttpConfiguration config)
        {
            config.Formatters.Remove(config.Formatters.FormUrlEncodedFormatter);
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            var formatting        = (DevEnvironment.IsDebug) ? Formatting.Indented : Formatting.None;
            var contractResolver  = new CamelCasePropertyNamesContractResolver();
            var dateTimeConverter = new IsoDateTimeConverter {
                DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fff"
            };

            var jsonSerializerSettings = config.Formatters.JsonFormatter.SerializerSettings;

            jsonSerializerSettings.Formatting       = formatting;
            jsonSerializerSettings.ContractResolver = contractResolver;
            jsonSerializerSettings.Converters.Add(dateTimeConverter);

            config.IncludeErrorDetailPolicy = DevEnvironment.IsDebug
                                                  ? IncludeErrorDetailPolicy.Always
                                                  : IncludeErrorDetailPolicy.Default;

            config.MapHttpAttributeRoutes();

            config.EnsureInitialized();
        }
 public CustomJsonSerializer()
 {
     Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
     ContractResolver     = new CamelCasePropertyNamesContractResolver();
     DateTimeZoneHandling = DateTimeZoneHandling.Local;
     NullValueHandling    = NullValueHandling.Ignore;
 }
Exemple #20
0
        public Startup(IConfiguration configuration, IHostingEnvironment env, ILogger <Startup> logger)
        {
            Logger = logger;
            Startup.Configuration = configuration;

            // https://github.com/drwatson1/AspNet-Core-REST-Service/wiki#using-environment-variables-in-configuration-options
            var envPath = Path.Combine(env.ContentRootPath, ".env");

            if (File.Exists(envPath))
            {
                DotNetEnv.Env.Load();
            }

            // See: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki#content-formatting
            JsonConvert.DefaultSettings = () =>
                                          new JsonSerializerSettings()
            {
                ContractResolver      = new CamelCasePropertyNamesContractResolver(),
                NullValueHandling     = NullValueHandling.Ignore,
                DefaultValueHandling  = DefaultValueHandling.Include,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
#if DEBUG
                Formatting = Formatting.Indented
#else
                Formatting = Formatting.None
#endif
            };
        }
        private void InitFormatters(HttpConfiguration config)
        {
            var json     = config.Formatters.JsonFormatter;
            var resolver = new CamelCasePropertyNamesContractResolver();

            resolver.NamingStrategy.ProcessDictionaryKeys = true;
            json.SerializerSettings.ContractResolver      = resolver;
        }
Exemple #22
0
 public ServiceJsonSerializerSettings()
 {
     Culture               = CultureInfo.InvariantCulture;
     ContractResolver      = new CamelCasePropertyNamesContractResolver();
     ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
     Converters.Add(new DateTimeJsonConverter());
     Converters.Add(new StringEnumConverter());
 }
Exemple #23
0
 public CamelCaseJsonSerializerSettings()
 {
     ContractResolver = new CamelCasePropertyNamesContractResolver();
     Converters.Add(new StringEnumConverter {
         NamingStrategy = new CamelCaseNamingStrategy()
     });
     NullValueHandling = NullValueHandling.Ignore;
 }
Exemple #24
0
 private MluviiApiJsonSerializerSettings()
 {
     ContractResolver = new CamelCasePropertyNamesContractResolver();
     Converters       = new List <JsonConverter>()
     {
         new SafeStringEnumConverter()
     };
 }
Exemple #25
0
        public static void ConfigureApi(this IServiceCollection services,
                                        FluentValidationOptions fluentValidationOptions, Action <MvcOptions> configureMvc = null,
                                        Action <MvcJsonOptions> configureJson = null)
        {
            /*************************
            * IConfiguration is not available yet
            *************************/

            services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");

            services.AddRouting(options =>
            {
                options.LowercaseUrls         = true;
                options.LowercaseQueryStrings = true;
            });

            services.AddApiVersioning(options =>
            {
                options.AssumeDefaultVersionWhenUnspecified = true;
                options.DefaultApiVersion = new ApiVersion(1, 0);
                options.ReportApiVersions = true;
                options.UseApiBehavior    = false;
            });

            var mvcBuilder = services.AddMvcCore(o =>
            {
                o.Filters.AddService(typeof(GlobalExceptionFilter));
                o.ModelValidatorProviders.Clear();

                configureMvc?.Invoke(o);
            })
                             .AddAuthorization()
                             .AddJsonFormatters()
                             .AddJsonOptions(options =>
            {
                var settings = options.SerializerSettings;

                var camelCasePropertyNamesContractResolver = new CamelCasePropertyNamesContractResolver();

                settings.ContractResolver = camelCasePropertyNamesContractResolver;
                settings.Converters.Add(new IsoDateTimeConverter());
                settings.Converters.Add(new StringEnumConverter(new DefaultNamingStrategy()));

                configureJson?.Invoke(options);
            });

            services.AddVersionedApiExplorer(options =>
            {
                options.GroupNameFormat           = "VVV";
                options.SubstituteApiVersionInUrl = true;
            });

            if (fluentValidationOptions.Enabled)
            {
                mvcBuilder.AddFluentValidation(
                    configuration => fluentValidationOptions.Configure?.Invoke(configuration));
            }
        }
        public static IEnumerable <string> GetPaths <T>(bool camelCase = false)
            where T : class
        {
            var resolver = new CamelCasePropertyNamesContractResolver();

            return(typeof(T).GetProperties()
                   .Where(p => p.GetCustomAttribute <UniqueKeyAttribute>() != null)
                   .Select(p => $"/{(camelCase ? resolver.GetResolvedPropertyName(p.Name) : p.Name)}"));
        }
Exemple #27
0
 public DefaultSerializerSettings()
 {
     ContractResolver = new CamelCasePropertyNamesContractResolver
     {
         NamingStrategy = new SnakeCaseNamingStrategy()
     };
     NullValueHandling = NullValueHandling.Ignore;
     Converters.Add(new EnumConverter());
 }
Exemple #28
0
 public GuidelineJsonSerializerSettings()
 {
     ContractResolver     = new CamelCasePropertyNamesContractResolver();
     TypeNameHandling     = TypeNameHandling.None;
     DateFormatHandling   = DateFormatHandling.IsoDateFormat;
     NullValueHandling    = NullValueHandling.Ignore;
     DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate;
     Converters.Add(new StringEnumConverter());
 }
        private static string Serialize <TItem>(TItem value)
        {
            var resolver = new CamelCasePropertyNamesContractResolver();
            var settings = new JsonSerializerSettings {
                ContractResolver = resolver
            };

            return(JsonConvert.SerializeObject(value, settings));
        }
        public RestSerializeSettings()
        {
            ReferenceLoopHandling      = ReferenceLoopHandling.Serialize;
            PreserveReferencesHandling = PreserveReferencesHandling.None;
            TypeNameHandling           = TypeNameHandling.All;
            Formatting = Formatting.None;

            ContractResolver = new CamelCasePropertyNamesContractResolver();
        }