// 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; } }); }