No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

42 líneas
1.9 KiB

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