|
|
@@ -10,6 +10,70 @@ namespace MQTTnet.Server |
|
|
|
{ |
|
|
|
public static class MqttServerExtensions |
|
|
|
{ |
|
|
|
public static IMqttServer UseClientConnectedHandler(this IMqttServer server, Func<MqttServerClientConnectedEventArgs, Task> handler) |
|
|
|
{ |
|
|
|
if (server == null) throw new ArgumentNullException(nameof(server)); |
|
|
|
|
|
|
|
if (handler == null) |
|
|
|
{ |
|
|
|
return server.UseClientConnectedHandler((IMqttServerClientConnectedHandler)null); |
|
|
|
} |
|
|
|
|
|
|
|
return server.UseClientConnectedHandler(new MqttServerClientConnectedHandlerDelegate(handler)); |
|
|
|
} |
|
|
|
|
|
|
|
public static IMqttServer UseClientConnectedHandler(this IMqttServer server, Action<MqttServerClientConnectedEventArgs> handler) |
|
|
|
{ |
|
|
|
if (server == null) throw new ArgumentNullException(nameof(server)); |
|
|
|
|
|
|
|
if (handler == null) |
|
|
|
{ |
|
|
|
return server.UseClientConnectedHandler((IMqttServerClientConnectedHandler)null); |
|
|
|
} |
|
|
|
|
|
|
|
return server.UseClientConnectedHandler(new MqttServerClientConnectedHandlerDelegate(handler)); |
|
|
|
} |
|
|
|
|
|
|
|
public static IMqttServer UseClientConnectedHandler(this IMqttServer server, IMqttServerClientConnectedHandler handler) |
|
|
|
{ |
|
|
|
if (server == null) throw new ArgumentNullException(nameof(server)); |
|
|
|
|
|
|
|
server.ClientConnectedHandler = handler; |
|
|
|
return server; |
|
|
|
} |
|
|
|
|
|
|
|
public static IMqttServer UseClientDisconnectedHandler(this IMqttServer server, Func<MqttServerClientDisconnectedEventArgs, Task> handler) |
|
|
|
{ |
|
|
|
if (server == null) throw new ArgumentNullException(nameof(server)); |
|
|
|
|
|
|
|
if (handler == null) |
|
|
|
{ |
|
|
|
return server.UseClientDisconnectedHandler((IMqttServerClientDisconnectedHandler)null); |
|
|
|
} |
|
|
|
|
|
|
|
return server.UseClientDisconnectedHandler(new MqttServerClientDisconnectedHandlerDelegate(handler)); |
|
|
|
} |
|
|
|
|
|
|
|
public static IMqttServer UseClientDisconnectedHandler(this IMqttServer server, Action<MqttServerClientDisconnectedEventArgs> handler) |
|
|
|
{ |
|
|
|
if (server == null) throw new ArgumentNullException(nameof(server)); |
|
|
|
|
|
|
|
if (handler == null) |
|
|
|
{ |
|
|
|
return server.UseClientDisconnectedHandler((IMqttServerClientDisconnectedHandler)null); |
|
|
|
} |
|
|
|
|
|
|
|
return server.UseClientDisconnectedHandler(new MqttServerClientDisconnectedHandlerDelegate(handler)); |
|
|
|
} |
|
|
|
|
|
|
|
public static IMqttServer UseClientDisconnectedHandler(this IMqttServer server, IMqttServerClientDisconnectedHandler handler) |
|
|
|
{ |
|
|
|
if (server == null) throw new ArgumentNullException(nameof(server)); |
|
|
|
|
|
|
|
server.ClientDisconnectedHandler = handler; |
|
|
|
return server; |
|
|
|
} |
|
|
|
|
|
|
|
public static IMqttServer UseApplicationMessageReceivedHandler(this IMqttServer server, Func<MqttApplicationMessageReceivedEventArgs, Task> handler) |
|
|
|
{ |
|
|
|
if (server == null) throw new ArgumentNullException(nameof(server)); |
|
|
|