-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Source/MQTTnet/Server/Disconnecting/MqttServerClientDisconnectOptionsBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using MQTTnet.Packets; | ||
using MQTTnet.Protocol; | ||
|
||
namespace MQTTnet.Server.Disconnecting | ||
{ | ||
public sealed class MqttServerClientDisconnectOptionsBuilder | ||
{ | ||
readonly MqttServerClientDisconnectOptions _options = new MqttServerClientDisconnectOptions(); | ||
|
||
public MqttServerClientDisconnectOptions Build() | ||
{ | ||
return _options; | ||
} | ||
|
||
public MqttServerClientDisconnectOptionsBuilder WithReasonCode(MqttDisconnectReasonCode value) | ||
{ | ||
_options.ReasonCode = value; | ||
return this; | ||
} | ||
|
||
public MqttServerClientDisconnectOptionsBuilder WithReasonString(string value) | ||
{ | ||
_options.ReasonString = value; | ||
return this; | ||
} | ||
|
||
public MqttServerClientDisconnectOptionsBuilder WithServerReference(string value) | ||
{ | ||
_options.ServerReference = value; | ||
return this; | ||
} | ||
|
||
public MqttServerClientDisconnectOptionsBuilder WithUserProperties(List<MqttUserProperty> value) | ||
{ | ||
_options.UserProperties = value; | ||
return this; | ||
} | ||
|
||
public MqttServerClientDisconnectOptionsBuilder WithUserProperty(string name, string value) | ||
{ | ||
if (_options.UserProperties == null) | ||
{ | ||
_options.UserProperties = new List<MqttUserProperty>(); | ||
} | ||
|
||
_options.UserProperties.Add(new MqttUserProperty(name, value)); | ||
return this; | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Source/MQTTnet/Server/Stopping/MqttServerStopOptionsBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using MQTTnet.Server.Disconnecting; | ||
|
||
namespace MQTTnet.Server | ||
{ | ||
public sealed class MqttServerStopOptionsBuilder | ||
{ | ||
readonly MqttServerStopOptions _options = new MqttServerStopOptions(); | ||
|
||
public MqttServerStopOptionsBuilder WithDefaultClientDisconnectOptions(MqttServerClientDisconnectOptions value) | ||
{ | ||
_options.DefaultClientDisconnectOptions = value; | ||
return this; | ||
} | ||
|
||
public MqttServerStopOptionsBuilder WithDefaultClientDisconnectOptions(Action<MqttServerClientDisconnectOptionsBuilder> builder) | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
var optionsBuilder = new MqttServerClientDisconnectOptionsBuilder(); | ||
builder.Invoke(optionsBuilder); | ||
|
||
_options.DefaultClientDisconnectOptions = optionsBuilder.Build(); | ||
return this; | ||
} | ||
|
||
public MqttServerStopOptions Build() | ||
{ | ||
return _options; | ||
} | ||
} | ||
} |