mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 17:23:04 +08:00
Add convenience extensions to the managed client
This commit is contained in:
@@ -3,12 +3,39 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client.Publishing;
|
||||
using MQTTnet.Client.Receiving;
|
||||
using MQTTnet.Protocol;
|
||||
|
||||
namespace MQTTnet.Extensions.ManagedClient
|
||||
{
|
||||
public static class ManagedMqttClientExtensions
|
||||
{
|
||||
public static IManagedMqttClient UseReceivedApplicationMessageHandler(this IManagedMqttClient client, Func<MqttApplicationMessageHandlerContext, Task> handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
client.ReceivedApplicationMessageHandler = null;
|
||||
return client;
|
||||
}
|
||||
|
||||
client.ReceivedApplicationMessageHandler = new MqttApplicationMessageHandlerDelegate(handler);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
public static IManagedMqttClient UseReceivedApplicationMessageHandler(this IManagedMqttClient client, Action<MqttApplicationMessageHandlerContext> handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
client.ReceivedApplicationMessageHandler = null;
|
||||
return client;
|
||||
}
|
||||
|
||||
client.ReceivedApplicationMessageHandler = new MqttApplicationMessageHandlerDelegate(handler);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
public static Task SubscribeAsync(this IManagedMqttClient managedClient, params TopicFilter[] topicFilters)
|
||||
{
|
||||
if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));
|
||||
|
||||
Reference in New Issue
Block a user