internal HouseKeepingConfiguration(LiteServerConfiguration liteServer, InternalConfiguration configuration)
        {
            if (liteServer == null)
            {
                throw new ArgumentNullException(nameof(liteServer));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            LiteServer     = liteServer;
            _configuration = configuration;
        }
Esempio n. 2
0
        public HouseKeeping(IKernel kernel, InternalConfiguration configuration, Action <string> output)
        {
            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _logger        = kernel.Resolve <ILogger>();
            _uptime        = kernel.Resolve <IUptimeTextGenerator>();
            _configuration = configuration;
            _output        = message => output($"[{this}]: {message}");
            _cancellation  = new CancellationTokenSource();

            TaskScheduler scheduler = TaskScheduler.Current;

            IBackgroundServer[] servers = kernel
                                          .ResolveAll <IBackgroundWorker>()
                                          .Select(worker => new BackgroundWorkerServer(worker, scheduler))
                                          .Concat(kernel.ResolveAll <IBackgroundServer>())
                                          .ToArray();

            CancellationToken token = kernel.Resolve <IShutdown>().Token;

            _heartbeatLogging = CreateHeartbeatLoggingServerHost(_configuration, scheduler, kernel);

            _servers = servers
                       .Select(server => new BackgroundServerHost(server, scheduler, kernel, output))
                       .Concat(new[] { _heartbeatLogging })
                       .SkipNulls()
                       .ToArray();

            // To keep track of which servers are actually running.
            _isRunning = new HashSet <BackgroundServerHost>();

            // Spin off the housekeeping background server
            _task = Start(kernel, scheduler, token);

            // Keep track of when Housekeeping was started.
            _startedAt = Time.UtcNow;
        }
Esempio n. 3
0
        public LiteServerImpl(IKernel kernel, InternalConfiguration configuration)
        {
            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }

            _kernel        = kernel;
            _console       = kernel.Resolve <IConsoleWriter>();
            _configuration = configuration;

            Output("Starting");

            Execute(_configuration.OnStartup);

            _houseKeeping = new HouseKeeping(kernel, configuration, Output);

            Output("Started");
        }
        internal LiteServerConfiguration(ApplicationConfiguration application)
        {
            if (application == null)
            {
                throw new ArgumentNullException(nameof(application));
            }

            _servers = new ScanAddRemoveInstaller <IBackgroundServer>(configure: x => x.LifeStyle.Is(LifestyleType.Transient));
            _workers = new ScanAddRemoveInstaller <IBackgroundWorker>(configure: x => x.LifeStyle.Is(LifestyleType.Transient));

            Application = application
                          .Hosts(hosts => hosts.Host <LiteServerHost>())
                          .Services(services => services
                                    .Advanced(advanced => advanced
                                              .Install(_servers)
                                              .Install(_workers)));

            _configuration = new InternalConfiguration();
            _houseKeeping  = new HouseKeepingConfiguration(this, _configuration);
        }
Esempio n. 5
0
        private BackgroundServerHost CreateHeartbeatLoggingServerHost(InternalConfiguration configuration, TaskScheduler scheduler, IKernel kernel)
        {
            TimeSpan?interval = configuration.HeartbeatLoggingInterval;

            if (interval.HasValue)
            {
                IHeartbeatProvider[] providers = kernel
                                                 .ResolveAll <IHeartbeatProvider>()
                                                 .Prepend(this)
                                                 .ToArray();

                var repository = kernel.Resolve <IHeartbeatLoggingRepository>();

                var worker = new HeartbeatLoggingWorker(providers, interval.Value, repository);
                var server = new BackgroundWorkerServer(worker, scheduler);

                var host = new BackgroundServerHost(server, scheduler, kernel, _output, _cancellation.Token);

                return(host);
            }

            return(null);
        }
 public LiteServerFactory(IKernel kernel, InternalConfiguration configuration)
 {
     _kernel        = kernel;
     _configuration = configuration;
 }