public async Task <AmqpIotConnection> OpenConnectionAsync(CancellationToken cancellationToken)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, nameof(OpenConnectionAsync));
            }

            var amqpTransportProvider = new AmqpTransportProvider();

            amqpTransportProvider.Versions.Add(s_amqpVersion_1_0_0);

            var amqpSettings = new AmqpSettings();

            amqpSettings.TransportProviders.Add(amqpTransportProvider);

            var amqpConnectionSettings = new AmqpConnectionSettings
            {
                MaxFrameSize = AmqpConstants.DefaultMaxFrameSize,
                ContainerId  = CommonResources.GetNewStringGuid(),
                HostName     = _hostName,
                IdleTimeOut  = Convert.ToUInt32(_amqpTransportSettings.IdleTimeout.TotalMilliseconds),
            };

            _amqpIotTransport = new AmqpIotTransport(amqpSettings, _amqpTransportSettings, _hostName, s_disableServerCertificateValidation);

            TransportBase transportBase = await _amqpIotTransport.InitializeAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                var amqpConnection    = new AmqpConnection(transportBase, amqpSettings, amqpConnectionSettings);
                var amqpIotConnection = new AmqpIotConnection(amqpConnection);
                amqpConnection.Closed += amqpIotConnection.AmqpConnectionClosed;
                await amqpConnection.OpenAsync(cancellationToken).ConfigureAwait(false);

                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, $"{nameof(OpenConnectionAsync)}");
                }

                return(amqpIotConnection);
            }
            catch (Exception ex) when(!ex.IsFatal())
            {
                transportBase?.Close();
                _amqpIotTransport?.Dispose();
                throw;
            }
            finally
            {
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, nameof(OpenConnectionAsync));
                }
            }
        }
 public void Dispose()
 {
     _amqpIotTransport?.Dispose();
     _amqpIotTransport = null;
 }