Пример #1
0
        public void Stop()
        {
            try
            {
                _cancellationTokenSource?.Cancel(false);
                _cancellationTokenSource?.Dispose();
                _cancellationTokenSource = null;

                _adapter = null;

                _logger.LogInformation("Client '{0}': Disconnected.", ClientId);
            }
            finally
            {
                if (_willMessage != null)
                {
                    _sessionsManager.DispatchApplicationMessage(this, _willMessage);
                }
            }
        }
Пример #2
0
        public void Stop()
        {
            try
            {
                _cancellationTokenSource?.Cancel(false);
                _cancellationTokenSource?.Dispose();
                _cancellationTokenSource = null;

                _adapter = null;

                _logger.LogInformation("Client '{0}': Disconnected.", ClientId);
            }
            finally
            {
                var willMessage = _willMessage;
                if (willMessage != null)
                {
                    _willMessage = null; //clear willmessage so it is send just once
                    _sessionsManager.DispatchApplicationMessage(this, willMessage);
                }
            }
        }
Пример #3
0
        public void Publish(IEnumerable <MqttApplicationMessage> applicationMessages)
        {
            if (applicationMessages == null)
            {
                throw new ArgumentNullException(nameof(applicationMessages));
            }

            if (_cancellationTokenSource == null)
            {
                throw new InvalidOperationException("The server is not started.");
            }

            foreach (var applicationMessage in applicationMessages)
            {
                var interceptorContext = new MqttApplicationMessageInterceptorContext
                {
                    ApplicationMessage = applicationMessage
                };

                _options.ApplicationMessageInterceptor?.Invoke(interceptorContext);

                _clientSessionsManager.DispatchApplicationMessage(null, interceptorContext.ApplicationMessage);
            }
        }