private async Task _logAsync(LogSeverity severity, string message) { await LogAsync?.Invoke(new LogMessage { Source = "Gotchi", Severity = severity, Message = message }); }
// ADDED: geertp 12/04/2018 <- // CHANGED: geertp 12/04/2018 - signature changed //public AzureIoTHubDeviceTwinProxy(DeviceClient deviceClient, ResetConnectionAsync resetConnectionAsyncHandler, LogAsync logAsyncHandler = null) public AzureIoTHubDeviceTwinProxy( DeviceClient deviceClient, ResetConnectionAsync resetConnectionAsyncHandler, LogAsync logAsyncHandler = null, ConnectionStatusChanged connectionStatusChangedHandler = null, WaitingForInternet waitingForInternetHandler = null) { this.deviceClient = deviceClient; this.resetConnectionAsyncHandler = resetConnectionAsyncHandler; this.logAsyncHandler = logAsyncHandler; // ADDED: geertp 12/04/2018 -> _connectionStatusChangedHandler = connectionStatusChangedHandler; _waitingForInternetHandler = waitingForInternetHandler; // ADDED: geertp 12/04/2018 <- this.deviceClient.SetConnectionStatusChangesHandler(async(ConnectionStatus status, ConnectionStatusChangeReason reason) => { string msg = "Connection changed: " + status.ToString() + " " + reason.ToString() + $" ({deviceClient.GetHashCode()})"; System.Diagnostics.Debug.WriteLine(msg); logAsyncHandler?.Invoke(msg, LoggingLevel.Verbose); // ADDED: geertp 12/04/2018 -> _connectionStatusChangedHandler?.Invoke(deviceClient, status, reason); // ADDED: geertp 12/04/2018 <- switch (reason) { case ConnectionStatusChangeReason.Connection_Ok: // No need to do anything, this is the expectation break; case ConnectionStatusChangeReason.Expired_SAS_Token: case ConnectionStatusChangeReason.Bad_Credential: case ConnectionStatusChangeReason.Retry_Expired: case ConnectionStatusChangeReason.No_Network: await InternalRefreshConnectionAsync(); break; case ConnectionStatusChangeReason.Client_Close: // ignore this ... part of client shutting down. break; case ConnectionStatusChangeReason.Communication_Error: case ConnectionStatusChangeReason.Device_Disabled: // These are not implemented in the Azure SDK break; default: break; } }); }
public AzureIoTHubDeviceTwinProxy(DeviceClient deviceClient, Twin twin, ResetConnectionAsync resetConnectionAsyncHandler, LogAsync logAsyncHandler = null) { _deviceClient = deviceClient; _twin = twin; _resetConnectionAsyncHandler = resetConnectionAsyncHandler; _logAsyncHandler = logAsyncHandler; _deviceClient.SetConnectionStatusChangesHandler(async(ConnectionStatus status, ConnectionStatusChangeReason reason) => { string msg = "Mock.Lib.Connection changed: " + status.ToString() + " " + reason.ToString(); Debug.WriteLine(msg); _logAsyncHandler?.Invoke(msg, LoggingLevel.Verbose); switch (reason) { case ConnectionStatusChangeReason.Connection_Ok: // No need to do anything, this is the expectation break; case ConnectionStatusChangeReason.Retry_Expired: await InternalRefreshConnectionAsync(); break; case ConnectionStatusChangeReason.Client_Close: // ignore this ... part of client shutting down. break; case ConnectionStatusChangeReason.Communication_Error: case ConnectionStatusChangeReason.Expired_SAS_Token: case ConnectionStatusChangeReason.Bad_Credential: case ConnectionStatusChangeReason.Device_Disabled: // These are not implemented in the Azure SDK break; case ConnectionStatusChangeReason.No_Network: // This seems to lead to Retry_Expired, so we can // ignore this ... maybe log the error. default: break; } }); }
public AzureIoTHubDeviceTwinProxy(DeviceClient deviceClient, EventWaitHandle iotHubOfflineEvent, LogAsync logAsyncHandler = null) { this.deviceClient = deviceClient; this.iotHubOfflineEvent = iotHubOfflineEvent; this.logAsyncHandler = logAsyncHandler; this.deviceClient.SetConnectionStatusChangesHandler(async(ConnectionStatus status, ConnectionStatusChangeReason reason) => { string msg = "Connection changed: " + status.ToString() + " " + reason.ToString(); System.Diagnostics.Debug.WriteLine(msg); logAsyncHandler?.Invoke(msg, LoggingLevel.Verbose); switch (reason) { case ConnectionStatusChangeReason.Connection_Ok: // No need to do anything, this is the expectation break; case ConnectionStatusChangeReason.Expired_SAS_Token: case ConnectionStatusChangeReason.Bad_Credential: case ConnectionStatusChangeReason.Retry_Expired: case ConnectionStatusChangeReason.No_Network: InternalRefreshConnection(); break; case ConnectionStatusChangeReason.Client_Close: // ignore this ... part of client shutting down. break; case ConnectionStatusChangeReason.Communication_Error: case ConnectionStatusChangeReason.Device_Disabled: // These are not implemented in the Azure SDK break; default: break; } }); }
private async Task _logAsync(LogSeverity severity, string message) { await LogAsync?.Invoke(new LogMessage(severity, "Gotchi", message)); }