Example #1
0
        public CloudService(StorageService storageService, SystemStatusService systemStatusService, ILogger <CloudService> logger)
        {
            _storageService = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _logger         = logger ?? throw new ArgumentNullException(nameof(logger));

            if (systemStatusService == null)
            {
                throw new ArgumentNullException(nameof(systemStatusService));
            }
            systemStatusService.Set("cloud.is_connected", () => _isConnected);
            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");

            _cloudMessageSerializer = new CloudMessageSerializer();
            _cloudMessageFactory    = new CloudMessageFactory(_cloudMessageSerializer);
        }
Example #2
0
        public CloudService(StorageService storageService, SystemStatusService systemStatusService, ILogger <CloudService> logger)
        {
            _storageService = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _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);
        }