mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
42 lines
1.9 KiB
C#
42 lines
1.9 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using MQTTnet.Protocol;
|
|
|
|
namespace MQTTnet
|
|
{
|
|
public static class ApplicationMessagePublisherExtensions
|
|
{
|
|
public static Task PublishAsync(this IApplicationMessagePublisher publisher, params MqttApplicationMessage[] applicationMessages)
|
|
{
|
|
if (publisher == null) throw new ArgumentNullException(nameof(publisher));
|
|
if (applicationMessages == null) throw new ArgumentNullException(nameof(applicationMessages));
|
|
|
|
return publisher.PublishAsync(applicationMessages);
|
|
}
|
|
|
|
public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic)
|
|
{
|
|
if (publisher == null) throw new ArgumentNullException(nameof(publisher));
|
|
if (topic == null) throw new ArgumentNullException(nameof(topic));
|
|
|
|
return publisher.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).Build());
|
|
}
|
|
|
|
public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload)
|
|
{
|
|
if (publisher == null) throw new ArgumentNullException(nameof(publisher));
|
|
if (topic == null) throw new ArgumentNullException(nameof(topic));
|
|
|
|
return publisher.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(payload).Build());
|
|
}
|
|
|
|
public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload, MqttQualityOfServiceLevel qualityOfServiceLevel)
|
|
{
|
|
if (publisher == null) throw new ArgumentNullException(nameof(publisher));
|
|
if (topic == null) throw new ArgumentNullException(nameof(topic));
|
|
|
|
return publisher.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(payload).WithQualityOfServiceLevel(qualityOfServiceLevel).Build());
|
|
}
|
|
}
|
|
}
|