Add topic filter builder

This commit is contained in:
Christian Kratky
2017-10-22 14:44:06 +02:00
parent 4386ef1e56
commit 3f080e04b9
6 changed files with 99 additions and 8 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ namespace MQTTnet.Core.Server
public Func<MqttConnectPacket, MqttConnectReturnCode> ConnectionValidator { get; set; }
public Action<MqttApplicationMessage> ApplicationMessageInterceptor { get; set; }
public Func<MqttApplicationMessage, MqttApplicationMessage> ApplicationMessageInterceptor { get; set; }
public IMqttServerStorage Storage { get; set; }
}
@@ -1,6 +1,6 @@
using MQTTnet.Core.Protocol;
namespace MQTTnet.Core.Packets
namespace MQTTnet.Core
{
public sealed class TopicFilter
{
+51
View File
@@ -0,0 +1,51 @@
using MQTTnet.Core.Protocol;
using MQTTnet.Core.Exceptions;
namespace MQTTnet.Core
{
public class TopicFilterBuilder
{
private string _topic;
private MqttQualityOfServiceLevel _qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;
public TopicFilterBuilder WithTopic(string topic)
{
_topic = topic;
return this;
}
public TopicFilterBuilder WithQualityOfServiceLevel(MqttQualityOfServiceLevel qualityOfServiceLevel)
{
_qualityOfServiceLevel = qualityOfServiceLevel;
return this;
}
public TopicFilterBuilder WithAtLeastOnceQoS()
{
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce;
return this;
}
public TopicFilterBuilder WithAtMostOnceQoS()
{
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;
return this;
}
public TopicFilterBuilder WithExactlyOnceQoS()
{
_qualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce;
return this;
}
public TopicFilter Build()
{
if (string.IsNullOrEmpty(_topic))
{
throw new MqttProtocolViolationException("Topic is not set.");
}
return new TopicFilter(_topic, _qualityOfServiceLevel);
}
}
}