You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ManagedMqttClientExtensions.cs 1.2 KiB

преди 7 години
преди 7 години
преди 7 години
преди 7 години
преди 7 години
преди 7 години
преди 7 години
преди 7 години
12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Threading.Tasks;
  3. using MQTTnet.Protocol;
  4. namespace MQTTnet.ManagedClient
  5. {
  6. public static class ManagedMqttClientExtensions
  7. {
  8. public static Task SubscribeAsync(this IManagedMqttClient managedClient, params TopicFilter[] topicFilters)
  9. {
  10. if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));
  11. return managedClient.SubscribeAsync(topicFilters);
  12. }
  13. public static Task SubscribeAsync(this IManagedMqttClient managedClient, string topic, MqttQualityOfServiceLevel qualityOfServiceLevel)
  14. {
  15. if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));
  16. if (topic == null) throw new ArgumentNullException(nameof(topic));
  17. return managedClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(topic).WithQualityOfServiceLevel(qualityOfServiceLevel).Build());
  18. }
  19. public static Task UnsubscribeAsync(this IManagedMqttClient managedClient, params string[] topicFilters)
  20. {
  21. if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));
  22. return managedClient.UnsubscribeAsync(topicFilters);
  23. }
  24. }
  25. }