예제 #1
0
        public static void Main(string[] args)
        {
            Logs.Configure(new FuncLoggerFactory(i => new ConsoleLogger(i, (a, b) => true, false)));
            var configuration = new TumblerConfiguration();

            configuration.LoadArgs(args);
            try
            {
                IWebHost         host     = null;
                ExternalServices services = null;
                if (!configuration.OnlyMonitor)
                {
                    host = new WebHostBuilder()
                           .UseKestrel()
                           .UseAppConfiguration(configuration)
                           .UseContentRoot(Directory.GetCurrentDirectory())
                           .UseIISIntegration()
                           .UseStartup <Startup>()
                           .Build();
                    services = (ExternalServices)host.Services.GetService(typeof(ExternalServices));
                }
                else
                {
                    services = ExternalServices.CreateFromRPCClient(configuration.RPC.ConfigureRPCClient(configuration.Network), new DBreezeRepository(Path.Combine(configuration.DataDir, "db")));
                }

                CancellationTokenSource cts = new CancellationTokenSource();
                var job = new BroadcasterJob(services, Logs.Main);
                job.Start(cts.Token);
                Logs.Main.LogInformation("BroadcasterJob started");

                if (!configuration.OnlyMonitor)
                {
                    host.Run();
                }
                else
                {
                    Console.ReadLine();
                }
                cts.Cancel();
            }
            catch (ConfigException ex)
            {
                if (!string.IsNullOrEmpty(ex.Message))
                {
                    Logs.Main.LogError(ex.Message);
                }
            }
            catch (Exception exception)
            {
                Logs.Main.LogError("Exception thrown while running the server " + exception.Message);
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            Logs.Configure(new FuncLoggerFactory(i => new ConsoleLogger("Configuration", (a, b) => true, false)));
            var logger        = new ConsoleLogger("Main", (a, b) => true, false);
            var configuration = new TumblerConfiguration();

            configuration.LoadArgs(args);
            try
            {
                var host = new WebHostBuilder()
                           .UseKestrel()
                           .UseAppConfiguration(configuration)
                           .UseContentRoot(Directory.GetCurrentDirectory())
                           .UseIISIntegration()
                           .UseStartup <Startup>()
                           .Build();

                var services = (ExternalServices)host.Services.GetService(typeof(ExternalServices));
                CancellationTokenSource cts = new CancellationTokenSource();
                var job = new BroadcasterJob(services, logger);
                job.Start(cts.Token);
                host.Run();
                cts.Cancel();
            }
            catch (ConfigException ex)
            {
                if (!string.IsNullOrEmpty(ex.Message))
                {
                    logger.LogError(ex.Message);
                }
            }
            catch (Exception exception)
            {
                logger.LogError("Exception thrown while running the server " + exception.Message);
            }
        }