Added MqttClientUnsubscribeOptionsBuilderrelease/3.x.x
@@ -11,6 +11,7 @@ | |||||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | <requireLicenseAcceptance>false</requireLicenseAcceptance> | ||||
<description>MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker) and supports v3.1.0, v3.1.1 and v5.0.0 of the MQTT protocol.</description> | <description>MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker) and supports v3.1.0, v3.1.1 and v5.0.0 of the MQTT protocol.</description> | ||||
<releaseNotes> | <releaseNotes> | ||||
* [ManagedClient] Added builder class for MqttClientUnsubscribeOptions (thanks to @dominikviererbe). | |||||
* [ManagedClient] Added support for persisted sessions (thansk to @PMExtra). | * [ManagedClient] Added support for persisted sessions (thansk to @PMExtra). | ||||
* [Client] Improve connection stability (thanks to @jltjohanlindqvist). | * [Client] Improve connection stability (thanks to @jltjohanlindqvist). | ||||
* [ManagedClient] Fixed a memory leak (thanks to @zawodskoj). | * [ManagedClient] Fixed a memory leak (thanks to @zawodskoj). | ||||
@@ -1,7 +1,7 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||
<PropertyGroup> | <PropertyGroup> | ||||
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks> | |||||
<TargetFrameworks>netstandard2.0;netcoreapp2.1;netcoreapp3.1</TargetFrameworks> | |||||
<Product /> | <Product /> | ||||
<Company /> | <Company /> | ||||
<Authors /> | <Authors /> | ||||
@@ -14,7 +14,11 @@ | |||||
<DefineConstants>RELEASE;NETSTANDARD2_0</DefineConstants> | <DefineConstants>RELEASE;NETSTANDARD2_0</DefineConstants> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | |||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' "> | |||||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | |||||
</ItemGroup> | |||||
<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.1' "> | |||||
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="2.1.3" /> | <PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="2.1.3" /> | ||||
<PackageReference Include="Microsoft.AspNetCore.Http.Connections" Version="1.0.3" /> | <PackageReference Include="Microsoft.AspNetCore.Http.Connections" Version="1.0.3" /> | ||||
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.1.1" /> | <PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.1.1" /> | ||||
@@ -0,0 +1,60 @@ | |||||
using MQTTnet.Packets; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace MQTTnet.Client.Unsubscribing | |||||
{ | |||||
public class MqttClientUnsubscribeOptionsBuilder | |||||
{ | |||||
private readonly MqttClientUnsubscribeOptions _unsubscribeOptions = new MqttClientUnsubscribeOptions(); | |||||
public MqttClientUnsubscribeOptionsBuilder WithUserProperty(string name, string value) | |||||
{ | |||||
if (name is null) throw new ArgumentNullException(nameof(name)); | |||||
if (value is null) throw new ArgumentNullException(nameof(value)); | |||||
return WithUserProperty(new MqttUserProperty(name, value)); | |||||
} | |||||
public MqttClientUnsubscribeOptionsBuilder WithUserProperty(MqttUserProperty userProperty) | |||||
{ | |||||
if (userProperty is null) throw new ArgumentNullException(nameof(userProperty)); | |||||
if (_unsubscribeOptions.UserProperties is null) | |||||
{ | |||||
_unsubscribeOptions.UserProperties = new List<MqttUserProperty>(); | |||||
} | |||||
_unsubscribeOptions.UserProperties.Add(userProperty); | |||||
return this; | |||||
} | |||||
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(string topic) | |||||
{ | |||||
if (topic is null) throw new ArgumentNullException(nameof(topic)); | |||||
if (_unsubscribeOptions.TopicFilters is null) | |||||
{ | |||||
_unsubscribeOptions.TopicFilters = new List<string>(); | |||||
} | |||||
_unsubscribeOptions.TopicFilters.Add(topic); | |||||
return this; | |||||
} | |||||
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(TopicFilter topicFilter) | |||||
{ | |||||
if (topicFilter is null) throw new ArgumentNullException(nameof(topicFilter)); | |||||
return WithTopic(topicFilter.Topic); | |||||
} | |||||
public MqttClientUnsubscribeOptions Build() | |||||
{ | |||||
return _unsubscribeOptions; | |||||
} | |||||
} | |||||
} |