Skip to content

Commit

Permalink
Add factories
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Nov 4, 2023
1 parent 8c45c27 commit bad1da7
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Source/MQTTnet/MqttFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using MQTTnet.Implementations;
using MQTTnet.LowLevelClient;
using MQTTnet.Server;
using MQTTnet.Server.Disconnecting;
using MqttClient = MQTTnet.Client.MqttClient;

namespace MQTTnet
Expand Down Expand Up @@ -175,6 +176,16 @@ public MqttServer CreateMqttServer(MqttServerOptions options, IEnumerable<IMqttS
return new MqttServer(options, serverAdapters, DefaultLogger);
}

public MqttServerClientDisconnectOptionsBuilder CreateMqttServerClientDisconnectOptionsBuilder()
{
return new MqttServerClientDisconnectOptionsBuilder();
}

public MqttServerStopOptionsBuilder CreateMqttServerStopOptionsBuilder()
{
return new MqttServerStopOptionsBuilder();
}

public MqttServerOptionsBuilder CreateServerOptionsBuilder()
{
return new MqttServerOptionsBuilder();
Expand Down
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 Source/MQTTnet/Server/Stopping/MqttServerStopOptionsBuilder.cs
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;
}
}
}

0 comments on commit bad1da7

Please sign in to comment.