From 9dfa0b32e4272b39951a8b7cf96fba3a69713a9a Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Tue, 23 Apr 2019 14:49:12 +0200 Subject: [PATCH] Add extension methods for server. --- Source/MQTTnet/Server/MqttServerExtensions.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/Source/MQTTnet/Server/MqttServerExtensions.cs b/Source/MQTTnet/Server/MqttServerExtensions.cs index f4d4423..c38aac7 100644 --- a/Source/MQTTnet/Server/MqttServerExtensions.cs +++ b/Source/MQTTnet/Server/MqttServerExtensions.cs @@ -10,6 +10,70 @@ namespace MQTTnet.Server { public static class MqttServerExtensions { + public static IMqttServer UseClientConnectedHandler(this IMqttServer server, Func 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 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 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 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 handler) { if (server == null) throw new ArgumentNullException(nameof(server));