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.
 
 
 
 

35 regels
1.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using MQTTnet.Core.Packets;
  6. namespace MQTTnet.Core.Client
  7. {
  8. public static class MqttClientExtensions
  9. {
  10. public static Task PublishAsync(this IMqttClient client, params MqttApplicationMessage[] applicationMessages)
  11. {
  12. if (client == null) throw new ArgumentNullException(nameof(client));
  13. if (applicationMessages == null) throw new ArgumentNullException(nameof(applicationMessages));
  14. return client.PublishAsync(applicationMessages);
  15. }
  16. public static Task<IList<MqttSubscribeResult>> SubscribeAsync(this IMqttClient client, params TopicFilter[] topicFilters)
  17. {
  18. if (client == null) throw new ArgumentNullException(nameof(client));
  19. if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
  20. return client.SubscribeAsync(topicFilters.ToList());
  21. }
  22. public static Task UnsubscribeAsync(this IMqttClient client, params string[] topicFilters)
  23. {
  24. if (client == null) throw new ArgumentNullException(nameof(client));
  25. if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
  26. return client.UnsubscribeAsync(topicFilters.ToList());
  27. }
  28. }
  29. }