Exemple #1
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (Logging.IsEnabled)
                {
                    Logging.Enter(this, disposing, $"{nameof(Dispose)}");
                }
                if (SetNotUsable() == 0)
                {
                    OnUnitDisconnected?.Invoke(false, EventArgs.Empty);
                }

                _amqpIoTSession?.Abort();
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, disposing, $"{nameof(Dispose)}");
                }
            }

            _disposed = true;
        }
Exemple #2
0
        public void OnConnectionDisconnected()
        {
            if (Logging.IsEnabled) Logging.Enter(this, $"{nameof(OnConnectionDisconnected)}");
            if (SetNotUsable() == 0)
            {
                _amqpAuthenticationRefresher?.StopLoop();
                OnUnitDisconnected?.Invoke(false, EventArgs.Empty);
            }

            if (Logging.IsEnabled) Logging.Exit(this, $"{nameof(OnConnectionDisconnected)}");
        }
Exemple #3
0
        private void OnLinkDisconnected(object o, EventArgs args)
        {
            if (Logging.IsEnabled) Logging.Enter(this, o, $"{nameof(OnLinkDisconnected)}");

            if (SetNotUsable() == 0)
            {
                _amqpAuthenticationRefresher?.StopLoop();
                OnUnitDisconnected?.Invoke(false, EventArgs.Empty);
            }

            if (Logging.IsEnabled) Logging.Exit(this, o, $"{nameof(OnLinkDisconnected)}");
        }
Exemple #4
0
        public async Task CloseAsync(TimeSpan timeout)
        {
            if (Logging.IsEnabled) Logging.Enter(this, timeout, $"{nameof(CloseAsync)}");

            if (SetNotUsable() == 0 && _amqpSession != null)
            {
                _amqpAuthenticationRefresher?.StopLoop();
                await _amqpSession.CloseAsync(timeout).ConfigureAwait(false);
                OnUnitDisconnected?.Invoke(true, EventArgs.Empty);
            }

            if (Logging.IsEnabled) Logging.Exit(this, timeout, $"{nameof(CloseAsync)}");
        }
Exemple #5
0
        public async Task OpenAsync(TimeSpan timeout)
        {
            if (Logging.IsEnabled) Logging.Enter(this, timeout, $"{nameof(OpenAsync)}");

            try
            {
                Debug.Assert(_amqpSession == null);
                Debug.Assert(IsUsable());

                _amqpSession = await _amqpSessionCreator.Invoke(
                    _deviceIdentity,
                    AmqpLinkFactory.GetInstance(),
                    _amqpSessionSettings,
                    timeout).ConfigureAwait(false);

                if (Logging.IsEnabled) Logging.Associate(this, _amqpSession, $"{nameof(_amqpSession)}");
                await _amqpSession.OpenAsync(timeout).ConfigureAwait(false);

                if (_deviceIdentity.AuthenticationModel == AuthenticationModel.SasIndividual)
                {
                    _amqpAuthenticationRefresher = await _amqpAuthenticationRefresherCreator.Invoke(_deviceIdentity, timeout).ConfigureAwait(false);
                    if (Logging.IsEnabled) Logging.Associate(this, _amqpAuthenticationRefresher, $"{nameof(_amqpAuthenticationRefresher)}");
                }

                _amqpSession.Closed += OnSessionDisconnected;

                _messageSendingLink = await AmqpLinkHelper.OpenTelemetrySenderLinkAsync(
                    _deviceIdentity,
                    _amqpSession,
                    timeout).ConfigureAwait(false);
                _messageSendingLink.Closed += OnLinkDisconnected;

                if (Logging.IsEnabled) Logging.Associate(this, _messageSendingLink, $"{nameof(_messageSendingLink)}");
            }
            catch (Exception ex) when (!ex.IsFatal())
            {
                if (SetNotUsable() == 0)
                {
                    OnUnitDisconnected?.Invoke(false, EventArgs.Empty);
                }

                throw;
            }
            finally
            {
                if (Logging.IsEnabled) Logging.Exit(this, timeout, $"{nameof(OpenAsync)}");
            }
        }
        public void OnConnectionDisconnected()
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, $"{nameof(OnConnectionDisconnected)}");
            }
            if (SetNotUsable() == 0)
            {
                OnUnitDisconnected?.Invoke(false, EventArgs.Empty);
            }

            if (Logging.IsEnabled)
            {
                Logging.Exit(this, $"{nameof(OnConnectionDisconnected)}");
            }
        }
        private void OnLinkDisconnected(object o, EventArgs args)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, o, $"{nameof(OnLinkDisconnected)}");
            }

            if (SetNotUsable() == 0)
            {
                OnUnitDisconnected?.Invoke(false, EventArgs.Empty);
            }

            if (Logging.IsEnabled)
            {
                Logging.Exit(this, o, $"{nameof(OnLinkDisconnected)}");
            }
        }
Exemple #8
0
        public async Task CloseAsync(TimeSpan timeout)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, timeout, $"{nameof(CloseAsync)}");
            }

            if (SetNotUsable() == 0 && _amqpIoTSession != null)
            {
                await _amqpIoTSession.CloseAsync(timeout).ConfigureAwait(false);

                OnUnitDisconnected?.Invoke(true, EventArgs.Empty);
            }

            if (Logging.IsEnabled)
            {
                Logging.Exit(this, timeout, $"{nameof(CloseAsync)}");
            }
        }
Exemple #9
0
        private void Dispose(bool disposing)
        {
            if (_disposed) return;

            if (disposing)
            {
                if (Logging.IsEnabled) Logging.Enter(this, disposing, $"{nameof(Dispose)}");
                if (SetNotUsable() == 0)
                {
                    OnUnitDisconnected?.Invoke(false, EventArgs.Empty);
                }

                _amqpAuthenticationRefresher?.Dispose();
                _amqpSession?.Abort();
                if (Logging.IsEnabled) Logging.Exit(this, disposing, $"{nameof(Dispose)}");
            }

            _disposed = true;
        }