Example #1
0
        private void Tick(object sender, TimerTickEventArgs e)
        {
            if (_ledTimeout.IsRunning)
            {
                _ledTimeout.Tick(e.ElapsedTime);
                if (_ledTimeout.IsElapsed)
                {
                    ToggleStatusLed();
                }
            }

            _durations.Add((int)e.ElapsedTime.TotalMilliseconds);
            if (_durations.Count == _durations.Capacity)
            {
                _averageTimerDuration = _durations.Sum() / (float)_durations.Count;
                _durations.Clear();

                _systemInformationService.Set("Health/SystemTime", DateTime.Now);

                if (!_maxTimerDuration.HasValue || _averageTimerDuration > _maxTimerDuration.Value)
                {
                    _maxTimerDuration = _averageTimerDuration;
                    _systemInformationService.Set("Health/TimerDurationAverageMax", _averageTimerDuration);
                }

                if (!_minTimerDuration.HasValue || _averageTimerDuration < _minTimerDuration.Value)
                {
                    _minTimerDuration = _averageTimerDuration;
                    _systemInformationService.Set("Health/TimerDurationAverageMin", _averageTimerDuration);
                }
            }
        }
Example #2
0
        private void Refresh()
        {
            if (!Settings.IsEnabled)
            {
                Log.Verbose("Fetching Open Weather Map Service is disabled.");
                return;
            }

            Log.Verbose("Fetching Open Weather Map weather data.");

            var response = FetchWeatherData();

            if (!string.Equals(response, _previousResponse))
            {
                if (TryParseData(response))
                {
                    _storageService.Write(StorageFilename, response);
                    PushData();
                }

                _previousResponse = response;

                _systemInformationService.Set("OpenWeatherMapService/LastUpdatedTimestamp", _dateTimeService.Now);
            }

            _systemInformationService.Set("OpenWeatherMapService/LastFetchedTimestamp", _dateTimeService.Now);
        }
        public AreaService(
            IComponentService componentService,
            IAutomationService automationService,
            ISystemEventsService systemEventsService,
            ISystemInformationService systemInformationService,
            IApiService apiService,
            ISettingsService settingsService)
        {
            if (componentService == null) throw new ArgumentNullException(nameof(componentService));
            if (automationService == null) throw new ArgumentNullException(nameof(automationService));
            if (systemEventsService == null) throw new ArgumentNullException(nameof(systemEventsService));
            if (systemInformationService == null) throw new ArgumentNullException(nameof(systemInformationService));
            if (apiService == null) throw new ArgumentNullException(nameof(apiService));
            if (settingsService == null) throw new ArgumentNullException(nameof(settingsService));

            _componentService = componentService;
            _automationService = automationService;
            _apiService = apiService;
            _settingsService = settingsService;

            systemEventsService.StartupCompleted += (s, e) =>
            {
                systemInformationService.Set("Areas/Count", _areas.GetAll().Count);
            };

            apiService.ConfigurationRequested += HandleApiConfigurationRequest;
        }
Example #4
0
        public TelegramBotService(
            ISettingsService settingsService,
            IPersonalAgentService personalAgentService,
            ISystemInformationService systemInformationService,
            ILogService logService,
            IScriptingService scriptingService)
        {
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }
            if (scriptingService == null)
            {
                throw new ArgumentNullException(nameof(scriptingService));
            }

            _personalAgentService = personalAgentService ?? throw new ArgumentNullException(nameof(personalAgentService));

            _log = logService.CreatePublisher(nameof(TelegramBotService));

            settingsService.CreateSettingsMonitor <TelegramBotServiceSettings>(s => Settings = s.NewSettings);
            systemInformationService.Set("TelegramBotService/IsConnected", () => _isConnected);

            scriptingService.RegisterScriptProxy(s => new TelegramBotScriptProxy(this));
        }
Example #5
0
        public ComponentRegistryService(
            ISystemInformationService systemInformationService,
            IApiDispatcherService apiService,
            ISettingsService settingsService,
            IScriptingService scriptingService,
            ILogService logService)
        {
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }
            if (scriptingService == null)
            {
                throw new ArgumentNullException(nameof(scriptingService));
            }

            _log             = logService.CreatePublisher(nameof(ComponentRegistryService));
            _apiService      = apiService ?? throw new ArgumentNullException(nameof(apiService));
            _settingsService = settingsService ?? throw new ArgumentNullException(nameof(settingsService));

            apiService.StatusRequested += HandleApiStatusRequest;

            systemInformationService.Set("Components/Count", () => _components.Count);

            scriptingService.RegisterScriptProxy(s => new ComponentRegistryScriptProxy(this, s));
        }
Example #6
0
        public AreaRegistryService(
            IComponentRegistryService componentService,
            IAutomationRegistryService automationService,
            ISystemEventsService systemEventsService,
            ISystemInformationService systemInformationService,
            IApiDispatcherService apiService,
            ISettingsService settingsService)
        {
            if (systemEventsService == null)
            {
                throw new ArgumentNullException(nameof(systemEventsService));
            }
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }
            if (apiService == null)
            {
                throw new ArgumentNullException(nameof(apiService));
            }

            _componentService  = componentService ?? throw new ArgumentNullException(nameof(componentService));
            _automationService = automationService ?? throw new ArgumentNullException(nameof(automationService));
            _settingsService   = settingsService ?? throw new ArgumentNullException(nameof(settingsService));

            systemEventsService.StartupCompleted += (s, e) =>
            {
                systemInformationService.Set("Areas/Count", _areas.Count);
            };

            apiService.ConfigurationRequested += HandleApiConfigurationRequest;
        }
Example #7
0
        public AreaRegistryService(
            IComponentRegistryService componentService,
            IAutomationRegistryService automationService,
            ISystemInformationService systemInformationService,
            IApiDispatcherService apiService,
            ISettingsService settingsService,
            IScriptingService scriptingService)
        {
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }
            if (apiService == null)
            {
                throw new ArgumentNullException(nameof(apiService));
            }
            if (scriptingService == null)
            {
                throw new ArgumentNullException(nameof(scriptingService));
            }

            _componentService  = componentService ?? throw new ArgumentNullException(nameof(componentService));
            _automationService = automationService ?? throw new ArgumentNullException(nameof(automationService));
            _settingsService   = settingsService ?? throw new ArgumentNullException(nameof(settingsService));

            apiService.ConfigurationRequested += HandleApiConfigurationRequest;

            systemInformationService.Set("Areas/Count", () => _areas.Count);

            scriptingService.RegisterScriptProxy(s => new AreaRegistryScriptProxy(this));
        }
        public AutomationRegistryService(
            ISettingsService settingsService,
            ISystemEventsService systemEventsService,
            ISystemInformationService systemInformationService,
            IApiDispatcherService apiService)
        {
            _settingsService = settingsService ?? throw new ArgumentNullException(nameof(settingsService));
            if (systemEventsService == null)
            {
                throw new ArgumentNullException(nameof(systemEventsService));
            }
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }
            if (apiService == null)
            {
                throw new ArgumentNullException(nameof(apiService));
            }
            if (apiService == null)
            {
                throw new ArgumentNullException(nameof(apiService));
            }

            systemEventsService.StartupCompleted += (s, e) =>
            {
                systemInformationService.Set("Automations/Count", _automations.Count);
            };

            apiService.StatusRequested += HandleApiStatusRequest;
        }
Example #9
0
        public AutomationService(
            ISystemEventsService systemEventsService,
            ISystemInformationService systemInformationService,
            IApiService apiService)
        {
            if (systemEventsService == null)
            {
                throw new ArgumentNullException(nameof(systemEventsService));
            }
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }
            if (apiService == null)
            {
                throw new ArgumentNullException(nameof(apiService));
            }
            if (apiService == null)
            {
                throw new ArgumentNullException(nameof(apiService));
            }

            systemEventsService.StartupCompleted += (s, e) =>
            {
                systemInformationService.Set("Automations/Count", _automations.GetAll().Count);
            };

            apiService.StatusRequested += HandleApiStatusRequest;
        }
Example #10
0
        private void Refresh()
        {
            Log.Verbose("Fetching OWM weather data");
            string response = FetchWeatherData();

            if (!string.Equals(response, _previousResponse))
            {
                PersistWeatherData(response);
                ParseWeatherData(response);

                _previousResponse = response;

                _systemInformationService.Set("OpenWeatherMapService/LastUpdatedTimestamp", _dateTimeService.GetDateTime());
            }

            _systemInformationService.Set("OpenWeatherMapService/LastFetchedTimestamp", _dateTimeService.GetDateTime());
        }
Example #11
0
        private void OnCodeReceived(object sender, Ldp433MhzCodeReceivedEventArgs e)
        {
            _systemInformationService.Set($"{nameof(RemoteSocketService)}/LastReceivedCode", e.Code);

            lock (_syncRoot)
            {
                _lastReceivedLpd433MhzCode = e.Code;
            }
        }
Example #12
0
        private async Task RefreshAsync()
        {
            if (!Settings.IsEnabled)
            {
                _log.Verbose("OpenWeatherMapService is disabled.");
                return;
            }

            _log.Verbose("Fetching OpenWeatherMap data.");

            var response = await FetchWeatherDataAsync();

            if (TryParseWeatherData(response))
            {
                PushData();
            }

            _systemInformationService.Set($"{nameof(OpenWeatherMapService)}/Timestamp", _dateTimeService.Now);
        }
Example #13
0
        public CloudConnectorService(IApiDispatcherService apiDispatcherService, ISettingsService settingsService, ISystemInformationService systemInformationService, ILogService logService)
        {
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }
            _log = logService?.CreatePublisher(nameof(CloudConnectorService)) ?? throw new ArgumentNullException(nameof(logService));
            _apiDispatcherService = apiDispatcherService ?? throw new ArgumentNullException(nameof(apiDispatcherService));

            _settings = settingsService?.GetSettings <CloudConnectorServiceSettings>() ?? throw new ArgumentNullException(nameof(settingsService));

            _receiveRequestsUri = $"{_settings.ServerAddress}/api/ControllerProxy/ReceiveRequests";
            _sendResponseUri    = $"{_settings.ServerAddress}/api/ControllerProxy/SendResponse";

            systemInformationService.Set("CloudConnector/IsConnected", () => _isConnected);
        }
Example #14
0
        public override void Startup()
        {
            foreach (var actuator in _components.GetAll <IActuator>())
            {
                try
                {
                    actuator.ResetState();
                }
                catch (Exception exception)
                {
                    Log.Warning(exception, $"Error while initially reset of state for actuator '{actuator.Id}'.");
                }
            }

            _systemInformationService.Set("Components/Count", _components.GetAll().Count);
        }
Example #15
0
        public DeviceRegistryService(
            ISystemEventsService systemEventsService,
            ISystemInformationService systemInformationService)
        {
            if (systemEventsService == null)
            {
                throw new ArgumentNullException(nameof(systemEventsService));
            }
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }

            systemEventsService.StartupCompleted += (s, e) =>
            {
                systemInformationService.Set("Devices/Count", _devices.Count);
            };
        }
Example #16
0
        public DeviceRegistryService(
            IConfigurationService configurationService,
            ISystemInformationService systemInformationService,
            ILogService logService)
        {
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }
            if (logService == null)
            {
                throw new ArgumentNullException(nameof(logService));
            }
            _configurationService = configurationService ?? throw new ArgumentNullException(nameof(configurationService));

            systemInformationService.Set("Devices/Count", () => _devices.Count);

            _log = logService.CreatePublisher(nameof(DeviceRegistryService));
        }
        public override void Startup()
        {
            lock (_components)
            {
                foreach (var actuator in _components.Values)
                {
                    try
                    {
                        actuator.ExecuteCommand(new ResetCommand());
                    }
                    catch (Exception exception)
                    {
                        _log.Warning(exception, $"Error while initially reset of state for actuator '{actuator.Id}'.");
                    }
                }

                _systemInformationService.Set("Components/Count", _components.Count);
            }
        }
Example #18
0
        public HealthService(
            IConfigurationService configurationService,
            IController controller,
            ITimerService timerService,
            IGpioService gpioService,
            IDateTimeService dateTimeService,
            ISystemInformationService systemInformationService,
            ILogService logService)
        {
            if (configurationService == null)
            {
                throw new ArgumentNullException(nameof(configurationService));
            }
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }
            if (timerService == null)
            {
                throw new ArgumentNullException(nameof(timerService));
            }
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }

            _log = logService?.CreatePublisher(nameof(HealthService)) ?? throw new ArgumentNullException(nameof(logService));

            var startupTimestamp = dateTimeService.Now;

            systemInformationService.Set("Health/SystemTime", () => dateTimeService.Now);
            systemInformationService.Set("Health/TimerDuration/Average", () => _averageTimerDuration);
            systemInformationService.Set("Health/TimerDuration/AverageMax", () => _maxTimerDuration);
            systemInformationService.Set("Health/TimerDuration/AverageMin", () => _minTimerDuration);
            systemInformationService.Set("Health/StartupTimestamp", startupTimestamp);
            systemInformationService.Set("Health/UpTime", () => dateTimeService.Now - startupTimestamp);
            systemInformationService.Set("Log/Errors/Count", () => logService.ErrorsCount);
            systemInformationService.Set("Log/Warnings/Count", () => logService.WarningsCount);

            controller.StartupCompleted += (sender, args) =>
            {
                _log.Info("Startup completed after " + args.Duration);
                systemInformationService.Set("Health/StartupDuration", args.Duration);
            };

            controller.StartupFailed += (sender, args) =>
            {
                _log.Error(args.Exception, "Startup failed after " + args.Duration);
            };

            timerService.Tick += UpdateStatistics;

            var configuration = configurationService.GetConfiguration <HealthServiceConfiguration>("HealthServiceConfiguration");

            if (configuration.StatusLed.Gpio.HasValue)
            {
                var gpio = gpioService.GetOutput(configuration.StatusLed.Gpio.Value);
                if (configuration.StatusLed.IsInverted)
                {
                    gpio = gpio.WithInvertedState();
                }

                var statusLed = new StatusLed(gpio);
                timerService.Tick += (s, e) => statusLed.Update();
            }
        }
 public void Set(string key, object value)
 {
     _systemInformationService.Set(key, value);
 }