protected override void Dispose(bool disposing)
        {
            try
            {
                if (Logging.IsEnabled)
                {
                    Logging.Enter(this, $"{nameof(DefaultDelegatingHandler)}.Disposed={_disposed}; disposing={disposing}", $"{nameof(AmqpTransportHandler)}.{nameof(Dispose)}");
                }

                lock (_lock)
                {
                    if (!_disposed)
                    {
                        base.Dispose(disposing);
                        if (disposing)
                        {
                            _closed = true;
                            AmqpUnitManager.GetInstance()?.RemoveAmqpUnit(_amqpUnit);
                            _disposed = true;
                        }
                    }

                    // the _disposed flag is inherited from the base class DefaultDelegatingHandler and is finally set to null there.
                }
            }
            finally
            {
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, $"{nameof(DefaultDelegatingHandler)}.Disposed={_disposed}; disposing={disposing}", $"{nameof(AmqpTransportHandler)}.{nameof(Dispose)}");
                }
            }
        }
        internal AmqpTransportHandler(
            PipelineContext context,
            IotHubConnectionString connectionString,
            AmqpTransportSettings transportSettings,
            Func <MethodRequestInternal, Task> onMethodCallback          = null,
            Action <TwinCollection> onDesiredStatePatchReceivedCallback  = null,
            Func <string, Message, Task> onModuleMessageReceivedCallback = null,
            Func <Message, Task> onDeviceMessageReceivedCallback         = null)
            : base(context, transportSettings)
        {
            _operationTimeout            = transportSettings.OperationTimeout;
            _onDesiredStatePatchListener = onDesiredStatePatchReceivedCallback;
            IDeviceIdentity deviceIdentity = new DeviceIdentity(connectionString, transportSettings, context.ProductInfo, context.ClientOptions);

            _amqpUnit = AmqpUnitManager.GetInstance().CreateAmqpUnit(
                deviceIdentity,
                onMethodCallback,
                TwinMessageListener,
                onModuleMessageReceivedCallback,
                onDeviceMessageReceivedCallback,
                OnDisconnected);

            if (Logging.IsEnabled)
            {
                Logging.Associate(this, _amqpUnit, nameof(_amqpUnit));
            }
        }
        internal AmqpTransportHandler(
            IPipelineContext context,
            IotHubConnectionString connectionString,
            AmqpTransportSettings transportSettings,
            Func <MethodRequestInternal, Task> methodHandler = null,
            Action <TwinCollection> desiredPropertyListener  = null,
            Func <string, Message, Task> eventListener       = null)
            : base(context, transportSettings)
        {
            _operationTimeout        = transportSettings.OperationTimeout;
            _desiredPropertyListener = desiredPropertyListener;
            DeviceIdentity deviceIdentity = new DeviceIdentity(connectionString, transportSettings, context.Get <ProductInfo>());

            _amqpUnit = AmqpUnitManager.GetInstance().CreateAmqpUnit(
                deviceIdentity,
                methodHandler,
                TwinMessageListener,
                eventListener,
                OnDisconnected
                );

            if (Logging.IsEnabled)
            {
                Logging.Associate(this, _amqpUnit, $"{nameof(_amqpUnit)}");
            }
        }
        protected override void Dispose(bool disposing)
        {
            lock (_lock)
            {
                if (_disposed)
                {
                    return;
                }

                Logging.Info(this, $"{nameof(disposing)}");

                if (disposing)
                {
                    _closed = true;
                    OnTransportClosedGracefully();
                    AmqpUnitManager.GetInstance().RemoveAmqpUnit(_amqpUnit);
                    _disposed = true;
                }
            }
        }
Ejemplo n.º 5
0
        protected override void Dispose(bool disposing)
        {
            lock (_lock)
            {
                if (_disposed)
                {
                    return;
                }

                base.Dispose(disposing);

                Logging.Info(this, nameof(disposing));

                if (disposing)
                {
                    _closed = true;
                    AmqpUnitManager.GetInstance()?.RemoveAmqpUnit(_amqpUnit);
                    _disposed = true;
                }
            }
        }