From fb8b60fcccf5d3922ea010dd37ee51aa70e5eb80 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Fri, 8 Dec 2017 21:12:05 +0100 Subject: [PATCH] Add overload for subscribing. --- Build/MQTTnet.nuspec | 1 + .../ManagedClient/ManagedMqttClientExtensions.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index ee3138c6..e7ed1cd6 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -19,6 +19,7 @@ * [Client] Fixed an issue in _ManagedClient_ which can cause the client to stop when publishing subscriptions. * [Client] Fixed an issue in _ManagedClient_ which prevents changing the QoS of an existing subscription (BREAKING CHANGE!). * [Client] Fixed an issue in _MqttClientOptionsBuilder_ which prevents adding TLS options to the client options when calling _Build()_. (Thanks to @cvellan). +* [Client] Added an overload for subscribing at both clients which reduces required code. * [Server] The application message interceptor can now delete any received application message. * [Server] Added a ConnectionValidator context to align with other APIs (BREAKING CHANGE! Please find new example in Wiki). * [Server] Added an interface for the _MqttServerOptions_. diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs index e1346679..d75117a5 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using MQTTnet.Protocol; namespace MQTTnet.ManagedClient { @@ -12,7 +13,15 @@ namespace MQTTnet.ManagedClient return managedClient.SubscribeAsync(topicFilters); } - public static Task UnsubscribeAsync(this IManagedMqttClient managedClient, params TopicFilter[] topicFilters) + public static Task SubscribeAsync(this IManagedMqttClient managedClient, string topic, MqttQualityOfServiceLevel qualityOfServiceLevel) + { + if (managedClient == null) throw new ArgumentNullException(nameof(managedClient)); + if (topic == null) throw new ArgumentNullException(nameof(topic)); + + return managedClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(topic).WithQualityOfServiceLevel(qualityOfServiceLevel).Build()); + } + + public static Task UnsubscribeAsync(this IManagedMqttClient managedClient, params string[] topicFilters) { if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));