Пример #1
0
        private void FilterTcpStatistics()
        {
            switch (_transportType)
            {
            case Client.TransportType.Http1:
            case Client.TransportType.Amqp_WebSocket_Only:
            case Client.TransportType.Mqtt_WebSocket_Only:
                SystemMetrics.TcpFilterPort(443);
                break;

            case Client.TransportType.Amqp_Tcp_Only:
                SystemMetrics.TcpFilterPort(5671);
                break;

            case Client.TransportType.Mqtt_Tcp_Only:
                SystemMetrics.TcpFilterPort(8883);
                break;
            }
        }
        private async void OnConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason)
        {
            try
            {
                await _connectionStatusChangedSemaphore.WaitAsync().ConfigureAwait(false);

                switch (status)
                {
                case ConnectionStatus.Disconnected:
                    if (_connected)
                    {
                        SystemMetrics.DeviceDisconnected();
                        _connected = false;
                    }

                    _mConnectionStatus.OperationType = TelemetryMetrics.DeviceStateDisconnected;
                    _waitForDisconnectSemaphore.Release();
                    break;

                case ConnectionStatus.Connected:
                    if (!_connected)
                    {
                        SystemMetrics.DeviceConnected();
                        _connected = true;
                    }

                    _mConnectionStatus.OperationType = TelemetryMetrics.DeviceStateConnected;
                    break;

                case ConnectionStatus.Disconnected_Retrying:
                    if (_connected)
                    {
                        SystemMetrics.DeviceDisconnected();
                        _connected = false;
                    }

                    _mConnectionStatus.OperationType = TelemetryMetrics.DeviceStateDisconnectedRetrying;
                    _waitForDisconnectSemaphore.Release();
                    break;

                case ConnectionStatus.Disabled:
                    if (_connected)
                    {
                        SystemMetrics.DeviceDisconnected();
                        _connected = false;
                    }

                    _mConnectionStatus.OperationType = TelemetryMetrics.DeviceStateDisconnected;
                    break;

                default:
                    _mConnectionStatus.OperationType = TelemetryMetrics.DeviceStateUnknown;
                    break;
                }

                _mConnectionStatus.ErrorMessage = $"ConnectionStatus: {status} reason: {reason}";
                await _writer.WriteAsync(_mConnectionStatus).ConfigureAwait(false);
            }
            finally
            {
                _connectionStatusChangedSemaphore.Release();
            }
        }