Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ManagedMqttClientExtensions.cs 1.6 KiB

7 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839
  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 SubscribeAsync(this IManagedMqttClient managedClient, string topic)
  20. {
  21. if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));
  22. if (topic == null) throw new ArgumentNullException(nameof(topic));
  23. return managedClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(topic).Build());
  24. }
  25. public static Task UnsubscribeAsync(this IManagedMqttClient managedClient, params string[] topicFilters)
  26. {
  27. if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));
  28. return managedClient.UnsubscribeAsync(topicFilters);
  29. }
  30. }
  31. }