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
{
readonly MqttClientOptions _options = new MqttClientOptions();
int? _port;
[Obsolete] MqttClientWebSocketProxyOptions _proxyOptions;
EndPoint _remoteEndPoint;
MqttClientTcpOptions _tcpOptions;
MqttClientTlsOptions _tlsOptions;
EndPoint _remoteEndPoint;
int? _port;
[Obsolete] MqttClientOptionsBuilderTlsParameters _tlsParameters;
MqttClientWebSocketOptions _webSocketOptions;
@@ -89,7 +89,7 @@ namespace MQTTnet.Client
if (_tcpOptions.RemoteEndpoint == null)
{
_tcpOptions.RemoteEndpoint = _remoteEndPoint;
_tcpOptions.RemoteEndpoint = _remoteEndPoint;
}
}
else if (_webSocketOptions != null)
@@ -145,7 +145,6 @@ namespace MQTTnet.Client
return this;
}
[Obsolete("Use WithTcpServer(... configure) or WithWebSocketServer(... configure) instead.")]
public MqttClientOptionsBuilder WithConnectionUri(Uri uri)
{
if (uri == null)
@@ -158,24 +157,33 @@ namespace MQTTnet.Client
{
case "tcp":
case "mqtt":
{
WithTcpServer(uri.Host, port);
break;
}
case "mqtts":
{
WithTcpServer(uri.Host, port)
.WithTlsOptions(
o =>
{
o.UseTls();
});
break;
}
case "ws":
case "wss":
{
WithWebSocketServer(o => o.WithUri(uri.ToString()));
break;
}
default:
throw new ArgumentException("Unexpected scheme in uri.");
{
throw new ArgumentException("Unexpected scheme in URI.");
}
}
if (!string.IsNullOrEmpty(uri.UserInfo))
@@ -189,7 +197,6 @@ namespace MQTTnet.Client
return this;
}
[Obsolete("Use WithTcpServer(... configure) or WithWebSocketServer(... configure) instead.")]
public MqttClientOptionsBuilder WithConnectionUri(string uri)
{
return WithConnectionUri(new Uri(uri, UriKind.Absolute));
@@ -218,6 +225,14 @@ namespace MQTTnet.Client
return this;
}
public MqttClientOptionsBuilder WithEndPoint(EndPoint endPoint)
{
_remoteEndPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint));
_tcpOptions = new MqttClientTcpOptions();
return this;
}
public MqttClientOptionsBuilder WithExtendedAuthenticationExchangeHandler(IMqttExtendedAuthenticationExchangeHandler handler)
{
_options.ExtendedAuthenticationExchangeHandler = handler;
@@ -344,14 +359,6 @@ namespace MQTTnet.Client
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)
{
@@ -57,7 +57,7 @@ namespace MQTTnet.Server
while (!cancellationToken.IsCancellationRequested)
{
TryProcessClients();
Sleep(_options.KeepAliveMonitorInterval);
Sleep(_options.KeepAliveOptions.MonitorInterval);
}
}
catch (OperationCanceledException)