Browse Source

Merge pull request #869 from dominikviererbe/feature/MqttClientUnsubscribeOptionsBuilder

Added MqttClientUnsubscribeOptionsBuilder
release/3.x.x
Christian 4 years ago
committed by GitHub
parent
commit
799005803e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 2 deletions
  1. +1
    -0
      Build/MQTTnet.nuspec
  2. +6
    -2
      Source/MQTTnet.AspnetCore/MQTTnet.AspNetCore.csproj
  3. +60
    -0
      Source/MQTTnet/Client/Unsubscribing/MqttClientUnsubscribeOptionsBuilder.cs

+ 1
- 0
Build/MQTTnet.nuspec View File

@@ -11,6 +11,7 @@
<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>
<releaseNotes>
* [ManagedClient] Added builder class for MqttClientUnsubscribeOptions (thanks to @dominikviererbe).
* [ManagedClient] Added support for persisted sessions (thansk to @PMExtra).
* [Client] Improve connection stability (thanks to @jltjohanlindqvist).
* [ManagedClient] Fixed a memory leak (thanks to @zawodskoj).


+ 6
- 2
Source/MQTTnet.AspnetCore/MQTTnet.AspNetCore.csproj View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<Product />
<Company />
<Authors />
@@ -14,7 +14,11 @@
<DefineConstants>RELEASE;NETSTANDARD2_0</DefineConstants>
</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.Http.Connections" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.1.1" />


+ 60
- 0
Source/MQTTnet/Client/Unsubscribing/MqttClientUnsubscribeOptionsBuilder.cs View File

@@ -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;
}
}
}

Loading…
Cancel
Save