Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

32 rader
1.2 KiB

  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. }