Avoid using obsolete code

This commit is contained in:
Christian
2024-02-29 18:35:13 +01:00
parent f82d382f23
commit 2fd8e95b54
2 changed files with 23 additions and 16 deletions
@@ -18,14 +18,14 @@ namespace MQTTnet.Client
public sealed class MqttClientOptionsBuilder public sealed class MqttClientOptionsBuilder
{ {
readonly MqttClientOptions _options = new MqttClientOptions(); readonly MqttClientOptions _options = new MqttClientOptions();
int? _port;
[Obsolete] MqttClientWebSocketProxyOptions _proxyOptions; [Obsolete] MqttClientWebSocketProxyOptions _proxyOptions;
EndPoint _remoteEndPoint;
MqttClientTcpOptions _tcpOptions; MqttClientTcpOptions _tcpOptions;
MqttClientTlsOptions _tlsOptions; MqttClientTlsOptions _tlsOptions;
EndPoint _remoteEndPoint;
int? _port;
[Obsolete] MqttClientOptionsBuilderTlsParameters _tlsParameters; [Obsolete] MqttClientOptionsBuilderTlsParameters _tlsParameters;
MqttClientWebSocketOptions _webSocketOptions; MqttClientWebSocketOptions _webSocketOptions;
@@ -89,7 +89,7 @@ namespace MQTTnet.Client
if (_tcpOptions.RemoteEndpoint == null) if (_tcpOptions.RemoteEndpoint == null)
{ {
_tcpOptions.RemoteEndpoint = _remoteEndPoint; _tcpOptions.RemoteEndpoint = _remoteEndPoint;
} }
} }
else if (_webSocketOptions != null) else if (_webSocketOptions != null)
@@ -145,7 +145,6 @@ namespace MQTTnet.Client
return this; return this;
} }
[Obsolete("Use WithTcpServer(... configure) or WithWebSocketServer(... configure) instead.")]
public MqttClientOptionsBuilder WithConnectionUri(Uri uri) public MqttClientOptionsBuilder WithConnectionUri(Uri uri)
{ {
if (uri == null) if (uri == null)
@@ -158,24 +157,33 @@ namespace MQTTnet.Client
{ {
case "tcp": case "tcp":
case "mqtt": case "mqtt":
{
WithTcpServer(uri.Host, port); WithTcpServer(uri.Host, port);
break; break;
}
case "mqtts": case "mqtts":
{
WithTcpServer(uri.Host, port) WithTcpServer(uri.Host, port)
.WithTlsOptions( .WithTlsOptions(
o => o =>
{ {
o.UseTls();
}); });
break; break;
}
case "ws": case "ws":
case "wss": case "wss":
{
WithWebSocketServer(o => o.WithUri(uri.ToString())); WithWebSocketServer(o => o.WithUri(uri.ToString()));
break; break;
}
default: default:
throw new ArgumentException("Unexpected scheme in uri."); {
throw new ArgumentException("Unexpected scheme in URI.");
}
} }
if (!string.IsNullOrEmpty(uri.UserInfo)) if (!string.IsNullOrEmpty(uri.UserInfo))
@@ -189,7 +197,6 @@ namespace MQTTnet.Client
return this; return this;
} }
[Obsolete("Use WithTcpServer(... configure) or WithWebSocketServer(... configure) instead.")]
public MqttClientOptionsBuilder WithConnectionUri(string uri) public MqttClientOptionsBuilder WithConnectionUri(string uri)
{ {
return WithConnectionUri(new Uri(uri, UriKind.Absolute)); return WithConnectionUri(new Uri(uri, UriKind.Absolute));
@@ -218,6 +225,14 @@ namespace MQTTnet.Client
return this; return this;
} }
public MqttClientOptionsBuilder WithEndPoint(EndPoint endPoint)
{
_remoteEndPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint));
_tcpOptions = new MqttClientTcpOptions();
return this;
}
public MqttClientOptionsBuilder WithExtendedAuthenticationExchangeHandler(IMqttExtendedAuthenticationExchangeHandler handler) public MqttClientOptionsBuilder WithExtendedAuthenticationExchangeHandler(IMqttExtendedAuthenticationExchangeHandler handler)
{ {
_options.ExtendedAuthenticationExchangeHandler = handler; _options.ExtendedAuthenticationExchangeHandler = handler;
@@ -344,14 +359,6 @@ namespace MQTTnet.Client
return this; return this;
} }
public MqttClientOptionsBuilder WithEndPoint(EndPoint endPoint)
{
_remoteEndPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint));
_tcpOptions = new MqttClientTcpOptions();
return this;
}
public MqttClientOptionsBuilder WithTcpServer(Action<MqttClientTcpOptions> optionsBuilder) public MqttClientOptionsBuilder WithTcpServer(Action<MqttClientTcpOptions> optionsBuilder)
{ {
@@ -57,7 +57,7 @@ namespace MQTTnet.Server
while (!cancellationToken.IsCancellationRequested) while (!cancellationToken.IsCancellationRequested)
{ {
TryProcessClients(); TryProcessClients();
Sleep(_options.KeepAliveMonitorInterval); Sleep(_options.KeepAliveOptions.MonitorInterval);
} }
} }
catch (OperationCanceledException) catch (OperationCanceledException)