mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
Refactor platform detection for unsupported features.
This commit is contained in:
@@ -141,7 +141,7 @@ namespace MQTTnet.Implementations
|
||||
|
||||
if (options.TlsOptions.Certificates.Count > 1)
|
||||
{
|
||||
throw new NotSupportedException("Only one client certificate is supported for UWP.");
|
||||
throw new NotSupportedException("Only one client certificate is supported when using 'uap10.0'.");
|
||||
}
|
||||
|
||||
return new Certificate(options.TlsOptions.Certificates.First().AsBuffer());
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace MQTTnet.Implementations
|
||||
|
||||
if (options.TlsEndpointOptions.IsEnabled)
|
||||
{
|
||||
throw new NotSupportedException("TLS servers are not supported for UWP apps.");
|
||||
throw new NotSupportedException("TLS servers are not supported when using 'uap10.0'.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,10 +156,20 @@ namespace MQTTnet.Implementations
|
||||
}
|
||||
|
||||
var certificateValidationHandler = _options.TlsOptions?.CertificateValidationHandler;
|
||||
#if NETSTANDARD2_1
|
||||
if (certificateValidationHandler != null)
|
||||
{
|
||||
clientWebSocket.Options.RemoteCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, sslPolicyErrors) =>
|
||||
#if NETSTANDARD1_3
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'netstandard1.3'.");
|
||||
#elif NETSTANDARD2_0
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'netstandard2.0'.");
|
||||
#elif WINDOWS_UWP
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'uap10.0'.");
|
||||
#elif NET452
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'net452'.");
|
||||
#elif NET461
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'net461'.");
|
||||
#else
|
||||
clientWebSocket.Options.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
|
||||
{
|
||||
// TODO: Find a way to add client options to same callback. Problem is that they have a different type.
|
||||
var context = new MqttClientCertificateValidationCallbackContext
|
||||
@@ -171,14 +181,9 @@ namespace MQTTnet.Implementations
|
||||
};
|
||||
|
||||
return certificateValidationHandler(context);
|
||||
});
|
||||
}
|
||||
#else
|
||||
if (certificateValidationHandler != null)
|
||||
{
|
||||
throw new NotSupportedException("The remote certificate validation callback for Web Sockets is only supported for netstandard 2.1+");
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Cleanup()
|
||||
@@ -207,9 +212,9 @@ namespace MQTTnet.Implementations
|
||||
}
|
||||
|
||||
#if WINDOWS_UWP
|
||||
throw new NotSupportedException("Proxies are not supported in UWP.");
|
||||
throw new NotSupportedException("Proxies are not supported when using 'uap10.0'.");
|
||||
#elif NETSTANDARD1_3
|
||||
throw new NotSupportedException("Proxies are not supported in netstandard 1.3.");
|
||||
throw new NotSupportedException("Proxies are not supported when using 'netstandard 1.3'.");
|
||||
#else
|
||||
var proxyUri = new Uri(_options.ProxyOptions.Address);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user