Преглед изворни кода

Add extension methods for server.

release/3.x.x
Christian Kratky пре 5 година
родитељ
комит
9dfa0b32e4
1 измењених фајлова са 64 додато и 0 уклоњено
  1. +64
    -0
      Source/MQTTnet/Server/MqttServerExtensions.cs

+ 64
- 0
Source/MQTTnet/Server/MqttServerExtensions.cs Прегледај датотеку

@@ -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));


Loading…
Откажи
Сачувај