mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System;
|
|
using MQTTnet.Client;
|
|
|
|
namespace MQTTnet.ManagedClient
|
|
{
|
|
public class ManagedMqttClientOptionsBuilder
|
|
{
|
|
private readonly ManagedMqttClientOptions _options = new ManagedMqttClientOptions();
|
|
|
|
public ManagedMqttClientOptionsBuilder WithAutoReconnectDelay(TimeSpan value)
|
|
{
|
|
_options.AutoReconnectDelay = value;
|
|
return this;
|
|
}
|
|
|
|
public ManagedMqttClientOptionsBuilder WithStorage(IManagedMqttClientStorage value)
|
|
{
|
|
_options.Storage = value;
|
|
return this;
|
|
}
|
|
|
|
public ManagedMqttClientOptionsBuilder WithClientOptions(IMqttClientOptions value)
|
|
{
|
|
_options.ClientOptions = value ?? throw new ArgumentNullException(nameof(value));
|
|
return this;
|
|
}
|
|
|
|
public ManagedMqttClientOptionsBuilder WithClientOptions(Action<MqttClientOptionsBuilder> options)
|
|
{
|
|
if (options == null) throw new ArgumentNullException(nameof(options));
|
|
|
|
var builder = new MqttClientOptionsBuilder();
|
|
options(builder);
|
|
_options.ClientOptions = builder.Build();
|
|
|
|
return this;
|
|
}
|
|
|
|
public ManagedMqttClientOptions Build()
|
|
{
|
|
if (_options.ClientOptions == null)
|
|
{
|
|
throw new InvalidOperationException("The ClientOptions cannot be null.");
|
|
}
|
|
|
|
return _options;
|
|
}
|
|
}
|
|
}
|