Пример #1
0
        private async void ConnectionStatusHandler(ConnectionStatus status, ConnectionStatusChangeReason reason)
        {
            bool   isConnected = false;
            string deviceId    = "Unknown";

            if (status == ConnectionStatus.Connected)
            {
                isConnected = true;
            }
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (isConnected)
                {
                    statusBorder.BorderBrush = new SolidColorBrush(Colors.Green);
                    deviceId                = ExtractDeviceId(tbConnectionString.Text);
                    tbDeviceName.Text       = "DeviceName = " + deviceId.ToString();
                    tbConnectionStatus.Text = "ConnectionStatus = " + status.ToString();
                    tbConnectionStatusChangedReason.Text = "ChangedReason = " + reason.ToString();
                    ApplicationData.Current.LocalSettings.Values["deviceConnectionString"] = tbConnectionString.Text;
                }
                else
                {
                    statusBorder.BorderBrush             = new SolidColorBrush(Colors.Red);
                    tbDeviceName.Text                    = "DeviceName = Unknown";
                    tbConnectionStatus.Text              = "ConnectionStatus = " + status.ToString();
                    tbConnectionStatusChangedReason.Text = "ChangedReason = " + reason.ToString();
                }
            });
        }
        private void ResetConnection(ConnectionStatus status, ConnectionStatusChangeReason reason)
        {
            _logger.Debug("Resetting Connection");
            _logger.Debug($"Status: {status.ToString()}, Reason: {reason.ToString()}");

            // Attempt to close any existing connections before creating a new one
            if (_deviceClient != null)
            {
                try
                {
                    if (reason == ConnectionStatusChangeReason.Retry_Expired)
                    {
                        // It has been observed that closing the device client with reason 'Retry_Expired'
                        // results in an assert, so don't call close and log the action taken.
                        // Exception:
                        //     DotNetty.Transport.Channels.ClosedChannelException: I/O error occurred.
                        //
                        _logger.Debug($"As reason was {reason.ToString()} skipping '_deviceClient.CloseAsync().Wait()'");
                    }
                    else
                    {
                        _deviceClient.CloseAsync().Wait();
                    }
                }
                catch (AggregateException ae)
                {
                    //ANDREWDENN_TODO: Once "IotHubClientException" is public then make this catch
                    //explicitly look for IotHubClientException and SocketException
                    //https://docs.microsoft.com/en-us/dotnet/api/system.aggregateexception.flatten?view=netframework-4.7.2
                    _logger.Debug(ae, "_deviceClient.CloseAsync().Wait()");
                }
            }

            // Create new connection
            CreateDeviceClient();
        }
        private void DeviceClientConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason)
        {
            _logger.Debug($"Status: {status.ToString()}, Reason: {reason.ToString()}");

            switch (status)
            {
            case ConnectionStatus.Disabled:
            case ConnectionStatus.Disconnected:
                ResetConnection(status, reason);
                break;

            default:
                break;
            }
        }
Пример #4
0
        /// <summary>
        /// Callback for whenever the connection status changes
        /// Mostly we just log the new status and the reason.
        /// But for some disconnects we need to handle them here differently for our module to recover
        /// </summary>
        /// <param name="status"></param>
        /// <param name="reason"></param>
        private static void ConnectionStatusHandler(ConnectionStatus status, ConnectionStatusChangeReason reason)
        {
            Log.Information($"Module connection changed. New status={status.ToString()} Reason={reason.ToString()}");

            // Sometimes the connection can not be recovered if it is in either of those states.
            // To solve this, we exit the module. The Edge Agent will then restart it (retrying with backoff)
            if (reason == ConnectionStatusChangeReason.Retry_Expired)
            {
                Log.Error($"Connection can not be re-established. Exiting module");
                Environment.Exit(1);
            }
        }
 private void IoTHubStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason)
 {
     ShowLog($"IoT Hub Status Changed - State={status.ToString()},Reason={reason.ToString()}");
 }
Пример #6
0
        private void ConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason)
        {
            string logPrefix = "system".BuildLogPrefix();

            _logger.LogDebug($"{logPrefix}::{_deviceSettings.ArtifactId}::Connection status changed-New status:{status.ToString()}-Reason:{reason.ToString()}.");
        }
Пример #7
0
        /// <summary>
        /// Callback for whenever the connection status changes
        /// Mostly we just log the new status and the reason.
        /// But for some disconnects we need to handle them here differently for our module to recover
        /// </summary>
        /// <param name="status"></param>
        /// <param name="reason"></param>
        private static void ConnectionStatusHandler(ConnectionStatus status, ConnectionStatusChangeReason reason)
        {
            Console.WriteLine($"Module connection changed. New status={status.ToString()} Reason={reason.ToString()}");

            // Sometimes the connection can not be recovered if it is in either of those states.
            // To solve this, we exit the module. The Edge Agent will then restart it (retrying with backoff)
            if (reason == ConnectionStatusChangeReason.Retry_Expired || reason == ConnectionStatusChangeReason.Client_Close)
            {
                Console.WriteLine($"Connection can not be re-established. Exiting module");
                cts?.Cancel();
            }
        }