Skip to content

Commit

Permalink
Avoid using obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Feb 29, 2024
1 parent f82d382 commit 2fd8e95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
37 changes: 22 additions & 15 deletions Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,7 +89,7 @@ public MqttClientOptions Build()

if (_tcpOptions.RemoteEndpoint == null)
{
_tcpOptions.RemoteEndpoint = _remoteEndPoint;
_tcpOptions.RemoteEndpoint = _remoteEndPoint;
}
}
else if (_webSocketOptions != null)
Expand Down Expand Up @@ -145,7 +145,6 @@ public MqttClientOptionsBuilder WithClientId(string value)
return this;
}

[Obsolete("Use WithTcpServer(... configure) or WithWebSocketServer(... configure) instead.")]
public MqttClientOptionsBuilder WithConnectionUri(Uri uri)
{
if (uri == null)
Expand All @@ -158,24 +157,33 @@ public MqttClientOptionsBuilder WithConnectionUri(Uri uri)
{
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))
Expand All @@ -189,7 +197,6 @@ public MqttClientOptionsBuilder WithConnectionUri(Uri uri)
return this;
}

[Obsolete("Use WithTcpServer(... configure) or WithWebSocketServer(... configure) instead.")]
public MqttClientOptionsBuilder WithConnectionUri(string uri)
{
return WithConnectionUri(new Uri(uri, UriKind.Absolute));
Expand Down Expand Up @@ -218,6 +225,14 @@ public MqttClientOptionsBuilder WithCredentials(IMqttClientCredentialsProvider c
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;
Expand Down Expand Up @@ -344,14 +359,6 @@ public MqttClientOptionsBuilder WithTcpServer(string server, int? port = null)

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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void DoWork(CancellationToken cancellationToken)
while (!cancellationToken.IsCancellationRequested)
{
TryProcessClients();
Sleep(_options.KeepAliveMonitorInterval);
Sleep(_options.KeepAliveOptions.MonitorInterval);
}
}
catch (OperationCanceledException)
Expand Down

0 comments on commit 2fd8e95

Please sign in to comment.