Example #1
0
        public HistoryService(
            ComponentRegistryService componentRegistryService,
            StorageService storageService,
            MessageBusService messageBusService,
            SystemStatusService systemStatusService,
            SystemCancellationToken systemCancellationToken,
            DiagnosticsService diagnosticsService,
            ILogger <HistoryService> logger)
        {
            _componentRegistryService = componentRegistryService ?? throw new ArgumentNullException(nameof(componentRegistryService));
            _storageService           = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _messageBusService        = messageBusService ?? throw new ArgumentNullException(nameof(messageBusService));
            _systemCancellationToken  = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (diagnosticsService == null)
            {
                throw new ArgumentNullException(nameof(diagnosticsService));
            }
            _updateRateCounter = diagnosticsService.CreateOperationsPerSecondCounter("history.update_rate");

            if (systemStatusService == null)
            {
                throw new ArgumentNullException(nameof(systemStatusService));
            }
            systemStatusService.Set("history.component_status.pending_updates_count", _pendingComponentStatusValues.Count);
            systemStatusService.Set("history.component_status.update_rate", () => _updateRateCounter.Count);
            systemStatusService.Set("history.component_status.update_duration", () => _componentStatusUpdateDuration);
        }
Example #2
0
        public MqttService(
            SystemCancellationToken systemCancellationToken,
            DiagnosticsService diagnosticsService,
            StorageService storageService,
            SystemStatusService systemStatusService,
            ILogger <MqttService> logger)
        {
            _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _storageService          = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (diagnosticsService == null)
            {
                throw new ArgumentNullException(nameof(diagnosticsService));
            }
            _inboundCounter  = diagnosticsService.CreateOperationsPerSecondCounter("mqtt.inbound_rate");
            _outboundCounter = diagnosticsService.CreateOperationsPerSecondCounter("mqtt.outbound_rate");

            if (systemStatusService is null)
            {
                throw new ArgumentNullException(nameof(systemStatusService));
            }
            systemStatusService.Set("mqtt.subscribers_count", () => _subscribers.Count);
            systemStatusService.Set("mqtt.incoming_messages_count", () => _incomingMessages.Count);
            systemStatusService.Set("mqtt.inbound_rate", () => _inboundCounter.Count);
            systemStatusService.Set("mqtt.outbound_rate", () => _outboundCounter.Count);
            systemStatusService.Set("mqtt.connected_clients_count", () => _mqttServer.GetClientStatusAsync().GetAwaiter().GetResult().Count);

            _topicImportManager = new MqttTopicImportManager(this, _logger);
        }
Example #3
0
        public NotificationsService(
            StorageService storageService,
            SystemStatusService systemStatusService,
            ResourceService resourcesService,
            MessageBusService messageBusService,
            SystemCancellationToken systemCancellationToken,
            ILogger <NotificationsService> logger)
        {
            _storageService          = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _resourcesService        = resourcesService ?? throw new ArgumentNullException(nameof(resourcesService));
            _messageBusService       = messageBusService ?? throw new ArgumentNullException(nameof(messageBusService));
            _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (systemStatusService == null)
            {
                throw new ArgumentNullException(nameof(systemStatusService));
            }
            systemStatusService.Set("notifications.count", () =>
            {
                lock (_notifications)
                {
                    return(_notifications.Count);
                }
            });
        }
        public MessageBusService(
            StorageService storageService,
            SystemStatusService systemStatusService,
            DiagnosticsService diagnosticsService,
            SystemCancellationToken systemCancellationToken,
            ILogger <MessageBusService> logger)
        {
            _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (storageService == null)
            {
                throw new ArgumentNullException(nameof(storageService));
            }
            storageService.SafeReadSerializedValue(out _options, DefaultDirectoryNames.Configuration, MessageBusServiceOptions.Filename);

            if (diagnosticsService == null)
            {
                throw new ArgumentNullException(nameof(diagnosticsService));
            }
            _inboundCounter        = diagnosticsService.CreateOperationsPerSecondCounter("message_bus.inbound_rate");
            _processingRateCounter = diagnosticsService.CreateOperationsPerSecondCounter("message_bus.processing_rate");

            if (systemStatusService == null)
            {
                throw new ArgumentNullException(nameof(systemStatusService));
            }
            systemStatusService.Set("message_bus.queued_messages_count", () => _messageQueue.Count);
            systemStatusService.Set("message_bus.subscribers_count", () => _subscribers.Count);
            systemStatusService.Set("message_bus.inbound_rate", () => _inboundCounter.Count);
            systemStatusService.Set("message_bus.processing_rate", () => _processingRateCounter.Count);

            _options.ToString(); // TODO: Remove or add new settings.
        }
Example #5
0
        public MqttService(
            SystemCancellationToken systemCancellationToken,
            DiagnosticsService diagnosticsService,
            StorageService storageService,
            SystemStatusService systemStatusService,
            ILoggerFactory loggerFactory)
        {
            _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _storageService          = storageService ?? throw new ArgumentNullException(nameof(storageService));

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            _logger = loggerFactory.CreateLogger <MqttService>();

            if (diagnosticsService == null)
            {
                throw new ArgumentNullException(nameof(diagnosticsService));
            }
            _inboundCounter  = diagnosticsService.CreateOperationsPerSecondCounter("mqtt.inbound_rate");
            _outboundCounter = diagnosticsService.CreateOperationsPerSecondCounter("mqtt.outbound_rate");

            systemStatusService.Set("mqtt.subscribers_count", () => _subscribers.Count);
            systemStatusService.Set("mqtt.incoming_messages_count", () => _incomingMessages.Count);
            systemStatusService.Set("mqtt.inbound_rate", () => _inboundCounter.Count);
            systemStatusService.Set("mqtt.outbound_rate", () => _outboundCounter.Count);
        }
Example #6
0
        public CloudService(StorageService storageService, SystemCancellationToken systemCancellationToken, SystemStatusService systemStatusService, ILogger <CloudService> logger)
        {
            _storageService          = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (systemStatusService is null)
            {
                throw new ArgumentNullException(nameof(systemStatusService));
            }
            systemStatusService.Set("cloud.is_connected", () => _isConnected);
            systemStatusService.Set("cloud.connection_error", () => _connectionError?.ToString());
            systemStatusService.Set("cloud.bytes_sent", () => _channel?.GetStatistics()?.BytesSent);
            systemStatusService.Set("cloud.bytes_received", () => _channel?.GetStatistics()?.BytesReceived);
            systemStatusService.Set("cloud.connected", () => _channel?.GetStatistics()?.Connected.ToString("O"));
            systemStatusService.Set("cloud.last_message_received", () => _channel?.GetStatistics()?.LastMessageReceived?.ToString("O"));
            systemStatusService.Set("cloud.last_message_sent", () => _channel?.GetStatistics()?.LastMessageSent?.ToString("O"));
            systemStatusService.Set("cloud.messages_received", () => _channel?.GetStatistics()?.MessagesReceived);
            systemStatusService.Set("cloud.messages_sent", () => _channel?.GetStatistics()?.MessagesSent);
            systemStatusService.Set("cloud.malformed_messages_received", () => _channel?.GetStatistics()?.MalformedMessagesReceived);
            systemStatusService.Set("cloud.receive_errors", () => _channel?.GetStatistics()?.ReceiveErrors);
            systemStatusService.Set("cloud.send_errors", () => _channel?.GetStatistics()?.SendErrors);

            _httpClient.BaseAddress = new Uri("http://127.0.0.1:80");
            // Disable compression for loopback connections
            _httpClient.DefaultRequestHeaders.AcceptEncoding.TryParseAdd("*;q=0");

            _cloudMessageFactory = new CloudMessageFactory(_cloudMessageSerializer);
        }
Example #7
0
        public MessageBusService(
            StorageService storageService,
            SystemStatusService systemStatusService,
            DiagnosticsService diagnosticsService,
            SystemCancellationToken systemCancellationToken,
            ILogger <MessageBusService> logger)
        {
            _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (storageService == null)
            {
                throw new ArgumentNullException(nameof(storageService));
            }
            storageService.TryReadOrCreate(out _options, MessageBusServiceOptions.Filename);

            if (diagnosticsService == null)
            {
                throw new ArgumentNullException(nameof(diagnosticsService));
            }
            _inboundCounter        = diagnosticsService.CreateOperationsPerSecondCounter("message_bus.inbound_rate");
            _processingRateCounter = diagnosticsService.CreateOperationsPerSecondCounter("message_bus.processing_rate");

            if (systemStatusService == null)
            {
                throw new ArgumentNullException(nameof(systemStatusService));
            }
            systemStatusService.Set("message_bus.queued_messages_count", () => _messageQueue.Count);
            systemStatusService.Set("message_bus.subscribers_count", () => _subscribers.Count);
            systemStatusService.Set("message_bus.inbound_rate", () => _inboundCounter.Count);
            systemStatusService.Set("message_bus.processing_rate", () => _processingRateCounter.Count);
        }
        public DiagnosticsService(SystemCancellationToken systemCancellationToken, ILoggerFactory loggerFactory)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));

            _logger = loggerFactory.CreateLogger <DiagnosticsService>();
        }
        public DiscoveryService(StorageService storageService, SystemCancellationToken systemCancellationToken, ILogger <DiscoveryService> logger)
        {
            _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (storageService is null)
            {
                throw new ArgumentNullException(nameof(storageService));
            }
            storageService.SafeReadSerializedValue(out _options, DefaultDirectoryNames.Configuration, DiscoveryServiceOptions.Filename);
        }
Example #10
0
 public MqttService(
     SystemCancellationToken systemCancellationToken,
     IConfiguration configuration,
     ILogger <MqttService> logger,
     IRepositoryFactory repositoryFactory,
     IHubContext <DeviceStateHub, IDeviceStateHub> hubContext)
 {
     _systemCancellationToken = systemCancellationToken;
     _configuration           = configuration;
     _logger            = logger;
     _repositoryFactory = repositoryFactory;
     _hubContext        = hubContext;
 }
Example #11
0
        public SchedulerService(
            SystemStatusService systemStatusService,
            SystemCancellationToken systemCancellationToken,
            StorageService storageService,
            ILogger <SchedulerService> logger)
        {
            _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _storageService          = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            systemStatusService.Set("scheduler.active_threads", () => _activeThreads.Count);
            systemStatusService.Set("scheduler.active_timers", () => _activeTimers.Count);
            systemStatusService.Set("scheduler.active_countdowns", () => _activeCountdowns.Count);
        }
Example #12
0
    public SystemService(SystemStatusService systemStatusService,
                         SystemLaunchArguments systemLaunchArguments,
                         SystemCancellationToken systemCancellationToken,
                         NotificationsService notificationsService,
                         MessageBusService messageBusService,
                         ILogger <SystemService> logger)
    {
        _systemStatusService     = systemStatusService ?? throw new ArgumentNullException(nameof(systemStatusService));
        _systemLaunchArguments   = systemLaunchArguments ?? throw new ArgumentNullException(nameof(systemLaunchArguments));
        _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
        _notificationsService    = notificationsService ?? throw new ArgumentNullException(nameof(notificationsService));
        _messageBusService       = messageBusService ?? throw new ArgumentNullException(nameof(messageBusService));
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));

        _creationTimestamp = DateTime.Now;
    }
Example #13
0
        public ComponentHistoryService(
            ComponentRegistryService componentRegistryService,
            HistoryService historyService,
            StorageService storageService,
            SystemStatusService systemStatusService,
            SystemCancellationToken systemCancellationToken,
            BackupService backupService,
            ILogger <ComponentHistoryService> logger)
        {
            _componentRegistryService = componentRegistryService ?? throw new ArgumentNullException(nameof(componentRegistryService));
            _historyService           = historyService ?? throw new ArgumentNullException(nameof(historyService));
            _storageService           = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _systemCancellationToken  = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
            _backupService            = backupService ?? throw new ArgumentNullException(nameof(backupService));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (systemStatusService == null)
            {
                throw new ArgumentNullException(nameof(systemStatusService));
            }
            systemStatusService.Set("component_history.pending_status_work_items", _pendingStatusWorkItems.Count);

            _componentRegistryService.ComponentStatusChanged += OnComponentStatusChanged;
        }
Example #14
0
 public DiagnosticsService(SystemCancellationToken systemCancellationToken, ILogger <DiagnosticsService> logger)
 {
     _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public MqttServerStorage(StorageService storageService, SystemCancellationToken systemCancellationToken, ILogger logger)
 {
     _storageService          = storageService ?? throw new ArgumentNullException(nameof(storageService));
     _systemCancellationToken = systemCancellationToken ?? throw new ArgumentNullException(nameof(systemCancellationToken));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }