Esempio n. 1
0
        static void Main(string[] args)
        {
            using (ServerBuilder builder = new ServerBuilder())
            {
                builder.ConfigureAppConfiguration(config =>
                {
                    config.SetBasePath(Directory.GetCurrentDirectory())
                    .AddJsonFile("appconfig.json", false, true)
                    .AddEnvironmentVariables()
                    .AddCommandLine(args);
                })
                .ConfigureLogging((config, l) =>
                {
                    var debugLevel = config.GetValue <Extensions.Logging.LogLevel>("Logging:Debug:LogLevel:Default", Extensions.Logging.LogLevel.Debug);

                    l.AddConsole(config.GetSection("Logging").GetSection("Console"))
                    .AddDebug(debugLevel);
                })
                .ConfigureCloudOptions(c => c.GetSection("CloudOption").Get <CloudOption>())
                .AddTaskItemSource(async(u, c, l, token) => new TaskItemSource(
                                       await u.GetOrCreateJobDispatchQueueAsync(token),
                                       TimeSpan.FromSeconds(u.Option.VisibleTimeoutSeconds),
                                       l))
                .AddWorker(async(config, u, l, token) => new JobDispatcherWorker(
                               config,
                               l,
                               await u.GetOrCreateJobsTableAsync(token),
                               u));

                builder.BuildAndStart();

                while (Console.In.Peek() == -1)
                {
                    Task.Delay(1000).Wait();
                }
                var logger = builder.LoggerFactory.CreateLogger <Program>();
                logger.LogInformation("Stop message received, stopping");

                builder.Stop();
            }
        }