コード例 #1
0
        static void Main(string[] args)
        {
            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 crabConnectionString = configuration.GetConnectionString("CRABEntities");
            Func <CRABEntities> crabEntitiesFactory = () => new CRABEntities(crabConnectionString);

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

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

                MapLogging.Log = s => _commandCounter++;

                var commandProcessor = new CommandProcessorBuilder <int>(new MunicipalityCommandGenerator(crabEntitiesFactory))
                                       .WithCommandLineOptions(options.ImportArguments)
                                       .UseSerilog(cfg => cfg
                                                   .WriteTo.File(
                                                       "tracing.log",
                                                       LogEventLevel.Verbose,
                                                       retainedFileCountLimit: 20,
                                                       fileSizeLimitBytes: 104857600,
                                                       rollOnFileSizeLimit: true,
                                                       rollingInterval: RollingInterval.Day)
                                                   .WriteTo.Console(LogEventLevel.Information))
                                       .UseApiProxyFactory(logger => new NonBatchedHttpApiProxyFactory(logger, settings))
                                       .UseCommandProcessorConfig(settings)
                                       .UseDefaultSerializerSettingsForCrabImports()
                                       .UseImportFeed(new ImportFeed {
                    Name = settings.FeedName
                })
                                       .Build();

                WaitForStart(settings);

                commandProcessor.Run(options, settings);

                WaitForExit(settings);
            }
            catch (Exception exception)
            {
                WaitForExit(settings, "General error occurred", exception);
            }
        }
コード例 #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);
            }
        }