diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index d3bd632d5..28ac47c39 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -14,6 +14,7 @@ * [Core] Fixed missing properties from PUBLISH packet in _MqttApplicationMessage_ (thanks to @pcbing). * [Core] Fixed wrong encoding of PUBREL and PUBCOMP packets for MQTTv5 (thanks to @perphilipp). * [Client] Added the authentication result to the disconnected handler (only set when connecting failed). +* [Client] Added new overloads for _MqttClientOptionsBuilder_. * [Server] Fixed a bug which returns wrong flag for existing session in CONNACK packet (thanks to @avengerstark). * [nuget] .NET Framework builds are now using 4.5.2 or 4.6.1 builds instead of netstandard 2.0. diff --git a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs index 20e008a33..c4d7e6cb3 100644 --- a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs +++ b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs @@ -136,6 +136,16 @@ public MqttClientOptionsBuilder WithTcpServer(string server, int? port = null) return this; } + public MqttClientOptionsBuilder WithTcpServer(Action optionsBuilder) + { + if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder)); + + _tcpOptions = new MqttClientTcpOptions(); + optionsBuilder.Invoke(_tcpOptions); + + return this; + } + public MqttClientOptionsBuilder WithProxy(string address, string username = null, string password = null, string domain = null, bool bypassOnLocal = false, string[] bypassList = null) { _proxyOptions = new MqttClientWebSocketProxyOptions @@ -151,6 +161,15 @@ public MqttClientOptionsBuilder WithProxy(string address, string username = null return this; } + public MqttClientOptionsBuilder WithProxy(Action optionsBuilder) + { + if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder)); + + _proxyOptions = new MqttClientWebSocketProxyOptions(); + optionsBuilder(_proxyOptions); + return this; + } + public MqttClientOptionsBuilder WithWebSocketServer(string uri, MqttClientOptionsBuilderWebSocketParameters parameters = null) { _webSocketOptions = new MqttClientWebSocketOptions @@ -163,9 +182,19 @@ public MqttClientOptionsBuilder WithWebSocketServer(string uri, MqttClientOption return this; } + public MqttClientOptionsBuilder WithWebSocketServer(Action optionsBuilder) + { + if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder)); + + _webSocketOptions = new MqttClientWebSocketOptions(); + optionsBuilder.Invoke(_webSocketOptions); + + return this; + } + public MqttClientOptionsBuilder WithTls(MqttClientOptionsBuilderTlsParameters parameters) { - _tlsParameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); + _tlsParameters = parameters; return this; } @@ -174,6 +203,15 @@ public MqttClientOptionsBuilder WithTls() return WithTls(new MqttClientOptionsBuilderTlsParameters { UseTls = true }); } + public MqttClientOptionsBuilder WithTls(Action optionsBuilder) + { + if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder)); + + _tlsParameters = new MqttClientOptionsBuilderTlsParameters(); + optionsBuilder(_tlsParameters); + return this; + } + public IMqttClientOptions Build() { if (_tcpOptions == null && _webSocketOptions == null)