Created
January 12, 2019 03:32
-
-
Save michaeldimoudis/6ceca92e785f243470eb4d6a86926327 to your computer and use it in GitHub Desktop.
Azure IoT Hub ConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task ConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason) | |
{ | |
// https://github.com/Azure/azure-iot-sdk-csharp/pull/741 | |
//Log.Information("Azure IoT Hub connection status Changed Status: {status} Reason: {reason}", status, reason); | |
//if (status == ConnectionStatus.Connected && reason == ConnectionStatusChangeReason.Connection_Ok) | |
//{ | |
// Log.Information("Client connected (initially and after a successful retry)."); | |
//} | |
if (status == ConnectionStatus.Disabled && reason == ConnectionStatusChangeReason.Client_Close) | |
{ | |
Log.Information("Application disposed the client."); | |
await TryClose(); | |
await Initialize(); | |
} | |
if (status == ConnectionStatus.Disconnected && reason == ConnectionStatusChangeReason.Communication_Error) | |
{ | |
Log.Information("If no callback subscriptions exist, the client will not automatically connect. A future operation will attempt to reconnect the client."); | |
await TryClose(); | |
await Initialize(); | |
} | |
if (status == ConnectionStatus.Disconnected_Retrying && reason == ConnectionStatusChangeReason.Communication_Error) | |
{ | |
Log.Information("If any callback subscriptions exist (methods, twin, events) and connectivity is lost, the client will try to reconnect."); | |
} | |
if (status == ConnectionStatus.Disconnected && reason == ConnectionStatusChangeReason.Retry_Expired) | |
{ | |
Log.Information("Retry timeout. The RetryHandler will attempt to recover links for a duration of OperationTimeoutInMilliseconds (default 4 minutes)."); | |
} | |
if (status == ConnectionStatus.Disconnected && reason == ConnectionStatusChangeReason.Bad_Credential) | |
{ | |
Log.Information("UnauthorizedException during Retry."); | |
await TryClose(); | |
await Initialize(); | |
} | |
if (status == ConnectionStatus.Disconnected && reason == ConnectionStatusChangeReason.Device_Disabled) | |
{ | |
Log.Information("DeviceDisabledException during Retry."); | |
await TryClose(); | |
await Initialize(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment