/// <summary>
        /// Sets up and adds additional converters for Perceelregister to the JsonSerializerSettings
        /// </summary>
        /// <param name="source"></param>
        /// <returns>the updated JsonSerializerSettings</returns>
        public static JsonSerializerSettings ConfigureForPerceelregister(this JsonSerializerSettings source)
        {
            var jsonSerializerSettings = JsonSerializerSettingsProvider.CreateSerializerSettings();

            source.ContractResolver = jsonSerializerSettings.ContractResolver;

            if (source.ContractResolver is DefaultContractResolver resolver)
            {
                resolver.NamingStrategy.ProcessDictionaryKeys = true;
            }

            source.DateFormatHandling = DateFormatHandling.IsoDateFormat;
            source.Converters.Add(new StringEnumConverter {
                CamelCaseText = true
            });

            //source.DateFormatString = "yyyy-MM-dd";
            //source.Converters.Add(new TrimStringConverter());
            //source.Converters.Add(new GuidConverter());

            return(source);
        }
Ejemplo n.º 2
0
        private static void Main(params string[] args)
        {
            var configureForBuildingRegistry = JsonSerializerSettingsProvider.CreateSerializerSettings().ConfigureForPerceelregister();

            JsonConvert.DefaultSettings = () => configureForBuildingRegistry;
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
                                .AddJsonFile($"appsettings.{Environment.MachineName.ToLowerInvariant()}.json", optional: true, reloadOnChange: false)
                                .AddEnvironmentVariables()
                                .AddCommandLine(args ?? new string[0])
                                .Build();

            var mailSettings = configuration.GetSection("ApplicationSettings").GetSection("SerilogMail");

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.File("tracing.log", LogEventLevel.Verbose)
                         .WriteTo.Console(LogEventLevel.Information)
                         .WriteTo.SendGridSmtp(
                mailSettings["apiKey"],
                mailSettings["subject"],
                mailSettings["fromEmail"],
                mailSettings["toEmail"],
                (LogEventLevel)Enum.Parse(typeof(LogEventLevel), mailSettings["restrictedToMinimumLevel"], true))
                         .ReadFrom.Configuration(configuration)
                         .CreateLogger();

            var crabConnectionString = configuration.GetConnectionString("CRABEntities");
            Func <CRABEntities> crabEntitiesFactory = () =>
            {
                var factory = new CRABEntities(crabConnectionString);
                factory.Database.CommandTimeout = 60 * 60;
                return(factory);
            };

            var settings = new SettingsBasedConfig(configuration.GetSection("ApplicationSettings"));

            try
            {
                var options = new ImportOptions(
                    args,
                    errors => WaitForExit(settings.WaitForUserInput, "Could not parse commandline options."));

                MapLogging.Log = s => _commandCounter++;

                var commandProcessor = new CommandProcessorBuilder <CaPaKey>(new CommandGenerator(crabEntitiesFactory))
                                       .WithCommandLineOptions(options.ImportArguments)
                                       .UseSerilog(cfg => cfg
                                                   .WriteTo.Console(LogEventLevel.Information))
                                       .UseHttpApiProxyConfig(settings)
                                       .UseCommandProcessorConfig(settings)
                                       .UseDefaultSerializerSettingsForCrabImports()
                                       .ConfigureProcessedKeySerialization(a => a.VbrCaPaKey, CaPaKey.CreateFrom)
                                       .UseImportFeed(new ImportFeed {
                    Name = settings.FeedName
                })
                                       .Build();

                WaitForStart(settings.WaitForUserInput);

                commandProcessor.Run(options, settings);

                WaitForExit(settings.WaitForUserInput);
            }
            catch (Exception exception)
            {
                WaitForExit(settings.WaitForUserInput, "General error occurred", exception);
            }
        }