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.

ApplicationMessagePublisherExtensions.cs 1.9 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Threading.Tasks;
  3. using MQTTnet.Protocol;
  4. namespace MQTTnet
  5. {
  6. public static class ApplicationMessagePublisherExtensions
  7. {
  8. public static Task PublishAsync(this IApplicationMessagePublisher publisher, params MqttApplicationMessage[] applicationMessages)
  9. {
  10. if (publisher == null) throw new ArgumentNullException(nameof(publisher));
  11. if (applicationMessages == null) throw new ArgumentNullException(nameof(applicationMessages));
  12. return publisher.PublishAsync(applicationMessages);
  13. }
  14. public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic)
  15. {
  16. if (publisher == null) throw new ArgumentNullException(nameof(publisher));
  17. if (topic == null) throw new ArgumentNullException(nameof(topic));
  18. return publisher.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).Build());
  19. }
  20. public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload)
  21. {
  22. if (publisher == null) throw new ArgumentNullException(nameof(publisher));
  23. if (topic == null) throw new ArgumentNullException(nameof(topic));
  24. return publisher.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(payload).Build());
  25. }
  26. public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload, MqttQualityOfServiceLevel qualityOfServiceLevel)
  27. {
  28. if (publisher == null) throw new ArgumentNullException(nameof(publisher));
  29. if (topic == null) throw new ArgumentNullException(nameof(topic));
  30. return publisher.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(payload).WithQualityOfServiceLevel(qualityOfServiceLevel).Build());
  31. }
  32. }
  33. }