Skip to content

Instantly share code, notes, and snippets.

@michaeldimoudis
Created January 12, 2019 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeldimoudis/6ceca92e785f243470eb4d6a86926327 to your computer and use it in GitHub Desktop.
Save michaeldimoudis/6ceca92e785f243470eb4d6a86926327 to your computer and use it in GitHub Desktop.
Azure IoT Hub ConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason)
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