Expose more properties to connection validator context.

This commit is contained in:
Christian Kratky
2019-06-14 20:37:06 +02:00
parent 7e7b36aadf
commit bd665c3d56
12 changed files with 302 additions and 67 deletions
@@ -1,10 +1,19 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using MQTTnet.Client.Receiving;
using MQTTnet.Diagnostics;
namespace MQTTnet.Server
{
public class MqttServerEventDispatcher
{
private readonly IMqttNetChildLogger _logger;
public MqttServerEventDispatcher(IMqttNetChildLogger logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public IMqttServerClientConnectedHandler ClientConnectedHandler { get; set; }
public IMqttServerClientDisconnectedHandler ClientDisconnectedHandler { get; set; }
@@ -26,15 +35,22 @@ namespace MQTTnet.Server
return handler.HandleClientConnectedAsync(new MqttServerClientConnectedEventArgs(clientId));
}
public Task HandleClientDisconnectedAsync(string clientId, MqttClientDisconnectType disconnectType)
public async Task TryHandleClientDisconnectedAsync(string clientId, MqttClientDisconnectType disconnectType)
{
var handler = ClientDisconnectedHandler;
if (handler == null)
try
{
return Task.FromResult(0);
}
var handler = ClientDisconnectedHandler;
if (handler == null)
{
return;
}
return handler.HandleClientDisconnectedAsync(new MqttServerClientDisconnectedEventArgs(clientId, disconnectType));
await handler.HandleClientDisconnectedAsync(new MqttServerClientDisconnectedEventArgs(clientId, disconnectType)).ConfigureAwait(false);
}
catch (Exception exception)
{
_logger.Error(exception, "Error while handling 'ClientDisconnected' event.");
}
}
public Task HandleClientSubscribedTopicAsync(string clientId, TopicFilter topicFilter)