private static void ConnectionStatusChangedCallback(ConnectionStatus status, ConnectionStatusChangeReason reason)
        {
            SimpleLogger.Debug($"Client connection Status: {status}, reason: {reason}");
            if (status != ConnectionStatus.Connected && LocalIoTHubConfiguration.Authentication.Identity == AuthenticationMethodProvider.AuthenticationIdentity.DPS)
            {
                SimpleLogger.Debug($"Client disconnected, trying to reprovision");

                var threeStageBackoff = new ThreeStageBackoff(10, TimeSpan.FromSeconds(1), 10, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(10));
                Retry.Do(() =>
                {
                    _client.ReInit(AuthenticationMethodProvider.GetNewModuleConnectionString(), LocalIoTHubConfiguration.IotInterface.TransportType);
                    _client.OpenAsync().Wait();
                }, threeStageBackoff);

                _client.SetConnectionStatusChangesHandler(ConnectionStatusChangedCallback);
            }
        }
        /// <summary>
        /// If a ModuleClient configuration is specified,
        /// creates a module client from the configuration,
        /// Otherwise creates a ModuleClientWrapper which delegates to the IoT sdk's ModuleClient.
        /// according to the LocalConfiguration.ClientConnectionString
        /// </summary>
        /// <returns>A new instance of IModuleClient</returns>
        private static IModuleClient CreateClient()
        {
            NameValueCollection agentConfig = (NameValueCollection)ConfigurationManager.GetSection("General");
            var moduleClientDll             = agentConfig["ModuleClientDll"];
            var moduleClientTypeName        = agentConfig["ModuleClientFullName"];

            if (!string.IsNullOrEmpty(moduleClientDll) && !string.IsNullOrEmpty(moduleClientTypeName))
            {
                Assembly assembly = Assembly.LoadFrom(Path.GetFullPath(moduleClientDll));
                Type     type     = assembly.GetType(moduleClientTypeName);

                return((IModuleClient)Activator.CreateInstance(type));
            }

            return(new ModuleClientWrapper(ModuleClient.CreateFromConnectionString(
                                               AuthenticationMethodProvider.GetModuleConnectionString(),
                                               LocalIoTHubConfiguration.IotInterface.TransportType)));
        }