Beispiel #1
0
        private async Task RunAsyncInternal()
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                _container.RegisterSingleton <IController>(() => this);
                _container.RegisterServices();
                _options.ContainerConfigurator?.ConfigureContainer(_container);
                _container.Verify();

                _log = _container.GetInstance <ILogService>().CreatePublisher(nameof(Controller));

                _container.GetInstance <IInterruptMonitorService>().RegisterInterrupts();
                _container.GetInstance <IDeviceRegistryService>().RegisterDevices();
                _container.GetInstance <IRemoteSocketService>().RegisterRemoteSockets();

                _container.StartupServices(_log);
                _container.ExposeRegistrationsToApi();

                await TryConfigureAsync();

                StartupCompleted?.Invoke(this, new StartupCompletedEventArgs(stopwatch.Elapsed));

                _container.GetInstance <IScriptingService>().TryExecuteStartupScripts();
            }
            catch (Exception exception)
            {
                StartupFailed?.Invoke(this, new StartupFailedEventArgs(stopwatch.Elapsed, exception));
                _deferral?.Complete();
            }
        }
Beispiel #2
0
        public SystemEventsService(IController controller, INotificationService notificationService, IResourceService resourceService)
        {
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }
            _notificationService = notificationService ?? throw new ArgumentNullException(nameof(notificationService));

            controller.StartupCompleted += OnStartupCompleted;
            controller.StartupFailed    += (s, e) => StartupFailed?.Invoke(this, EventArgs.Empty);

            resourceService.RegisterText(SystemEventNotification.Booted, "System is booted.");
        }
Beispiel #3
0
 public void Start()
 {
     Task.Run(async() =>
     {
         try
         {
             await StartServices();
         }
         catch (Exception exception)
         {
             StartupFailed?.Invoke(exception);
         }
     });
 }
Beispiel #4
0
 public void Start()
 {
     Task.Run(async() =>
     {
         try
         {
             await StartServices(_cancellationTokenSource.Token);
         }
         catch (Exception exception)
         {
             StartupFailed?.Invoke(exception);
         }
     });
 }
Beispiel #5
0
        private void Startup()
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();

                RegisterServices();
                StartHttpServer();

                _container.StartupServices(_log);
                _container.ExposeRegistrationsToApi();

                TryConfigure();

                StartupCompleted?.Invoke(this, EventArgs.Empty);
                stopwatch.Stop();

                _container.GetInstance <IApiDispatcherService>().ConfigurationRequested += (s, e) =>
                {
                    var controllerSettings = _container.GetInstance <ISettingsService>().GetSettings <ControllerSettings>();
                    e.ApiContext.Result["Controller"] = JObject.FromObject(controllerSettings);
                };

                _log.Info("Startup completed after " + stopwatch.Elapsed);

                _container.GetInstance <ISystemInformationService>().Set("Health/StartupDuration", stopwatch.Elapsed);
                _container.GetInstance <ISystemInformationService>().Set("Health/StartupTimestamp", _container.GetInstance <IDateTimeService>().Now);

                _container.GetInstance <ITimerService>().Run();
            }
            catch (Exception exception)
            {
                _log?.Error(exception, "Failed to initialize.");
                StartupFailed?.Invoke(this, EventArgs.Empty);
            }
            finally
            {
                Shutdown?.Invoke(this, EventArgs.Empty);
                _deferral?.Complete();
            }
        }
Beispiel #6
0
        private void Startup()
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();

                SetupLogger();

                Log.Info("Starting...");

                RegisterServices();
                TryConfigure();

                StartupServices();
                ExposeRegistrationsToApi();
                StartHttpServer();

                StartupCompleted?.Invoke(this, EventArgs.Empty);
                stopwatch.Stop();

                Log.Info("Startup completed after " + stopwatch.Elapsed);

                _container.GetInstance <ISystemInformationService>().Set("Health/StartupDuration", stopwatch.Elapsed);
                _container.GetInstance <ISystemInformationService>().Set("Health/StartupTimestamp", _container.GetInstance <IDateTimeService>().Now);

                _container.GetInstance <ITimerService>().Run();
            }
            catch (Exception exception)
            {
                Log.Error(exception, "Failed to initialize.");
                StartupFailed?.Invoke(this, EventArgs.Empty);
            }
            finally
            {
                Shutdown?.Invoke(this, EventArgs.Empty);
                _deferral?.Complete();
            }
        }
Beispiel #7
0
 public void RaiseStartupFailed()
 {
     StartupFailed?.Invoke(this, new StartupFailedEventArgs(TimeSpan.Zero, new Exception()));
 }