// The connectFailed flag differentiates between calling this method while still retrying // vs calling this when no more retry attempts are being made. private void HandleConnectionStatusExceptions(Exception exception, bool connectFailed = false) { Logging.Info(this, $"Received exception: {exception}, connectFailed={connectFailed}", nameof(HandleConnectionStatusExceptions)); ConnectionStatusChangeReason reason = ConnectionStatusChangeReason.Communication_Error; ConnectionStatus status = ConnectionStatus.Disconnected; if (exception is IotHubException hubException) { if (hubException.IsTransient) { if (!connectFailed) { status = ConnectionStatus.Disconnected_Retrying; } else { reason = ConnectionStatusChangeReason.Retry_Expired; } } else if (hubException is UnauthorizedException) { reason = ConnectionStatusChangeReason.Bad_Credential; } else if (hubException is DeviceNotFoundException) { reason = ConnectionStatusChangeReason.Device_Disabled; } } _onConnectionStatusChanged(status, reason); Logging.Info(this, $"Connection status change: status={status}, reason={reason}", nameof(HandleConnectionStatusExceptions)); }
public void ConnectionStatusChangesHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { _connectionStatusChangesHandlerCount++; LastConnectionStatus = status; LastConnectionStatusChangeReason = reason; s_log.WriteLine($"{nameof(MultiplexingOverAmqp)}.{nameof(ConnectionStatusChangesHandler)}: status={status} statusChangeReason={reason} count={_connectionStatusChangesHandlerCount}"); }
public void ConnectionStatusChangesHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { ConnectionStatusChangesHandlerCount++; LastConnectionStatus = status; LastConnectionStatusChangeReason = reason; _logger.Trace($"{nameof(PoolingOverAmqp)}.{nameof(ConnectionStatusChangesHandler)}: status={status} statusChangeReason={reason} count={ConnectionStatusChangesHandlerCount}"); }
/// <summary> /// Handle status change event /// </summary> /// <param name="deviceId"></param> /// <param name="moduleId"></param> /// <param name="onConnectionLost"></param> /// <param name="logger"></param> /// <param name="status"></param> /// <param name="reason"></param> private void OnConnectionStatusChange(string deviceId, string moduleId, Action onConnectionLost, ILogger logger, ConnectionStatus status, ConnectionStatusChangeReason reason) { if (status == ConnectionStatus.Connected) { logger.Information("{counter}: Module {deviceId}_{moduleId} reconnected " + "due to {reason}.", _reconnectCounter, deviceId, moduleId, reason); _reconnectCounter++; return; } logger.Information("{counter}: Module {deviceId}_{moduleId} disconnected " + "due to {reason} - now {status}...", _reconnectCounter, deviceId, moduleId, reason, status); if (IsClosed) { // Already closed - nothing to do return; } if (status == ConnectionStatus.Disconnected || status == ConnectionStatus.Disabled) { // Force IsClosed = true; onConnectionLost?.Invoke(); } }
private void OnConnectionStatusChanges(ConnectionStatus status, ConnectionStatusChangeReason reason) { Console.WriteLine("Connection to IoT Hub closed. Trying to reconnect..."); Task.Delay(2000); _client.OpenAsync().Wait(); Console.WriteLine("Connected to IoT Hub."); }
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 ConnectionStatusChangeHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { Console.WriteLine(); Console.WriteLine($"Connection status changed to {status}."); Console.WriteLine($"Connection status changed reason is {reason}."); Console.WriteLine(); }
public ConnectionStatus(ConnectionStatusChangeReason changeReason, [CanBeNull] string serialPortName) { this.ChangeReason = changeReason; this.SerialPortName = serialPortName; this.IsConnected = changeReason == ConnectionStatusChangeReason.ConnectionRequested || changeReason == ConnectionStatusChangeReason.AutoRestoreConnection; }
private void ConnectionChange(ConnectionStatus status, ConnectionStatusChangeReason reason) { toolStripStatusLabel1.Text = status.ToString(); if (status == ConnectionStatus.Connected) { btnStart.Invoke((MethodInvoker) delegate { btnStart.Enabled = true; }); btnSend.Invoke((MethodInvoker) delegate { btnSend.Enabled = true; }); } else { btnStart.Invoke((MethodInvoker) delegate { btnStart.Enabled = false; }); btnSend.Invoke((MethodInvoker) delegate { btnSend.Enabled = false; }); } }
/// <summary> /// Handle status change event /// </summary> /// <param name="deviceId"></param> /// <param name="onConnectionLost"></param> /// <param name="logger"></param> /// <param name="status"></param> /// <param name="reason"></param> private void OnConnectionStatusChange(string deviceId, Action onConnectionLost, ILogger logger, ConnectionStatus status, ConnectionStatusChangeReason reason) { if (status == ConnectionStatus.Connected) { logger.Information("{counter}: Device {deviceId} reconnected " + "due to {reason}.", _reconnectCounter, deviceId, reason); kReconnectionStatus.WithLabels(deviceId, DateTime.UtcNow.ToString()).Set(_reconnectCounter); _reconnectCounter++; return; } logger.Information("{counter}: Device {deviceId} disconnected " + "due to {reason} - now {status}...", _reconnectCounter, deviceId, reason, status); kDisconnectionStatus.WithLabels(deviceId, DateTime.UtcNow.ToString()).Set(_reconnectCounter); if (IsClosed) { // Already closed - nothing to do return; } if (status == ConnectionStatus.Disconnected || status == ConnectionStatus.Disabled) { // Force IsClosed = true; onConnectionLost?.Invoke(); } }
static void ConnectionStatusChangeHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { Console.WriteLine(); Console.WriteLine("Connection Status Changed to {0}", status); Console.WriteLine("Connection Status Changed Reason is {0}", reason); Console.WriteLine(); }
public void ConnectionStatusChangesHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { ConnectionStatusChangeCount++; LastConnectionStatus = status; LastConnectionStatusChangeReason = reason; _logger.Trace($"{nameof(AmqpConnectionStatusChange)}.{nameof(ConnectionStatusChangesHandler)}: {_deviceId}: status={status} statusChangeReason={reason} count={ConnectionStatusChangeCount}"); }
public virtual async Task OnConnectionChanged(ConnectionStatus status, ConnectionStatusChangeReason reason) { Log.WriteLine("base connection changed. status {0} reason {1}", status, reason); Status = status; LastConnectionChangeReason = reason; await Task.CompletedTask; }
public void ConnectionStatusChangesHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { ConnectionStatusChangeCount++; LastConnectionStatus = status; LastConnectionStatusChangeReason = reason; s_log.WriteLine($"{nameof(FaultInjectionPoolingOverAmqp)}.{nameof(ConnectionStatusChangesHandler)}: {_deviceId}: status={status} statusChangeReason={reason} count={ConnectionStatusChangeCount}"); }
public override async Task OnConnectionChanged(ConnectionStatus status, ConnectionStatusChangeReason reason) { await base.OnConnectionChanged(status, reason); Log.WriteLine("derived connection changed. status {0} reason {1}", status, reason); return; }
private void HandleConnectionStatusExceptions(IotHubException hubException) { ConnectionStatusChangeReason status = ConnectionStatusChangeReason.Communication_Error; if (hubException.IsTransient) { status = ConnectionStatusChangeReason.Retry_Expired; } else if (hubException is UnauthorizedException) { status = ConnectionStatusChangeReason.Bad_Credential; } else if (hubException is DeviceDisabledException) { // This mapping along with the DeviceDisabledException class // needs to be removed because DeviceDisabledException is not used anywhere. status = ConnectionStatusChangeReason.Device_Disabled; } else if (hubException is DeviceNotFoundException) { status = ConnectionStatusChangeReason.Device_Disabled; } _onConnectionStatusChanged(ConnectionStatus.Disconnected, status); }
async void OnConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason) { try { Events.ConnectionStatusChanged(status, reason); // TODO: Change this to `Device_Not_Found` after that reason is added to the C# IoT SDK // and uncomment the following block to enable dynamic reprovisioning based on the // new ConnectionStatusChangeReason. // if (reason == ConnectionStatusChangeReason.Device_Not_Found) // { // await this.deviceManager.ReprovisionDeviceAsync(); // } if (this.pullOnReconnect && this.initTask.IsCompleted && status == ConnectionStatus.Connected) { using (await this.twinLock.LockAsync()) { await this.RefreshTwinAsync(); } } } catch (Exception ex) when(!ex.IsFatal()) { Events.ConnectionStatusChangedHandlingError(ex); } }
private void ConnectionStatusChangeHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { Console.WriteLine("Status Update received."); Console.WriteLine($"Status: {status}"); Console.WriteLine($"Reason: {reason}"); Console.WriteLine(); }
private void ConnectionStatusChangeHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { // callback when connection to IoT Hub/IoT Central changed Console.WriteLine(); Console.WriteLine($"Connection status changed to {status}."); Console.WriteLine($"Connection status changed reason is {reason}."); Console.WriteLine(); }
private void OnConnectionChanged(ConnectionStatus status, ConnectionStatusChangeReason reason) { if (status == ConnectionStatus.Connected) { DeviceClient.SetDesiredPropertyUpdateCallbackAsync(OnPropertyUpdate, this); DeviceClient.SetMethodDefaultHandlerAsync(OnMethodReceived, this); } }
/// <summary> /// Handle connection changes and drop /// </summary> /// <param name="status"></param> /// <param name="reason"></param> private void HandleConnectionStatusChange(ConnectionStatus status, ConnectionStatusChangeReason reason) { if (Connected && status == ConnectionStatus.Disconnected) { _logging.LogMessage($"HandleConnectionStatusChange Disconnected: reason: {reason}", LoggingLevel.Verbose); Connected = false; } }
static void ConnectionStatusChangeHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(); Console.WriteLine("Connection Status Changed to {0}", status); Console.WriteLine("Connection Status Changed Reason is {0}", reason); Console.WriteLine(); Console.ResetColor(); }
private void DeviceStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason) { Logger.LogWarning("Device connection changed to {DeviceConnectionStatus}. Reason {Reason}", status, reason); var telemetryContext = ComposeRequiredContextualInformation(); telemetryContext.TryAdd("Status", status); telemetryContext.TryAdd("Reason", reason); Logger.LogEvent("Device Connectivity Changed", telemetryContext); }
private void StatusChangeHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { if (status != ConnectionStatus.Connected) { _logger.Warning(StatusChangeMessage, status, reason); } else { _logger.Information(StatusChangeMessage, status, reason); } }
/// <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(); } }
/// <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); } }
static void OnConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason) { try { Console.WriteLine($"ConnectionStatus:{status}"); Console.WriteLine($"ConnectionStatusChangeReason:{reason}"); } catch (Exception ex) { Console.WriteLine(ex); } }
static void OnDeviceConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Connection Status Changed to {0}", status); Console.WriteLine("Connection Status Changed Reason is {0}", reason); Console.ResetColor(); if (status == ConnectionStatus.Connected) { UpdateTimerFrequency(TELEMETRY_FREQUENCY); } }
void InternalConnectionStatusChangedHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { Events.ReceivedDeviceSdkCallback(this.identity, status, reason); if (status == ConnectionStatus.Connected) { this.deviceConnectivityManager.CallSucceeded(); this.HandleDeviceConnectedEvent(); } else if (status == ConnectionStatus.Disconnected || status == ConnectionStatus.Disabled) { this.deviceConnectivityManager.CallTimedOut(); this.HandleDeviceDisconnectedEvent(); } }
void InternalConnectionStatusChangedHandler(ConnectionStatus status, ConnectionStatusChangeReason reason) { Events.ReceivedDeviceSdkCallback(this.identity, status, reason); // @TODO: Ignore callback from Device SDK since it seems to be generating a lot of spurious Connected/NotConnected callbacks //if (status == ConnectionStatus.Connected) //{ // this.deviceConnectivityManager.CallSucceeded(); //} //else //{ // this.deviceConnectivityManager.CallTimedOut(); //} //this.connectionStatusChangedHandler?.Invoke(status, reason); }