mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-22 04:43:04 +08:00
Convert null checks to modern ThrowIfNull checks (#2089)
Convert null check to modern ThrowIfNull checks
This commit is contained in:
@@ -102,10 +102,7 @@ public static class Server_Retained_Messages_Samples
|
|||||||
|
|
||||||
public static MqttRetainedMessageModel Create(MqttApplicationMessage message)
|
public static MqttRetainedMessageModel Create(MqttApplicationMessage message)
|
||||||
{
|
{
|
||||||
if (message == null)
|
ArgumentNullException.ThrowIfNull(message);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttRetainedMessageModel
|
return new MqttRetainedMessageModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ namespace MQTTnet.AspNetCore
|
|||||||
{
|
{
|
||||||
public static void MapMqtt(this IEndpointRouteBuilder endpoints, string pattern)
|
public static void MapMqtt(this IEndpointRouteBuilder endpoints, string pattern)
|
||||||
{
|
{
|
||||||
if (endpoints == null)
|
ArgumentNullException.ThrowIfNull(endpoints);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(endpoints));
|
|
||||||
}
|
|
||||||
|
|
||||||
endpoints.MapConnectionHandler<MqttConnectionHandler>(pattern, options =>
|
endpoints.MapConnectionHandler<MqttConnectionHandler>(pattern, options =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ public static class MqttSubProtocolSelector
|
|||||||
{
|
{
|
||||||
public static string SelectSubProtocol(HttpRequest request)
|
public static string SelectSubProtocol(HttpRequest request)
|
||||||
{
|
{
|
||||||
if (request == null)
|
ArgumentNullException.ThrowIfNull(request);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
string subProtocol = null;
|
string subProtocol = null;
|
||||||
if (request.Headers.TryGetValue("Sec-WebSocket-Protocol", out var requestedSubProtocolValues))
|
if (request.Headers.TryGetValue("Sec-WebSocket-Protocol", out var requestedSubProtocolValues))
|
||||||
@@ -29,10 +26,7 @@ public static class MqttSubProtocolSelector
|
|||||||
|
|
||||||
public static string SelectSubProtocol(IList<string> requestedSubProtocolValues)
|
public static string SelectSubProtocol(IList<string> requestedSubProtocolValues)
|
||||||
{
|
{
|
||||||
if (requestedSubProtocolValues == null)
|
ArgumentNullException.ThrowIfNull(requestedSubProtocolValues);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(requestedSubProtocolValues));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Order the protocols to also match "mqtt", "mqttv-3.1", "mqttv-3.11" etc.
|
// Order the protocols to also match "mqtt", "mqttv-3.1", "mqttv-3.11" etc.
|
||||||
return requestedSubProtocolValues.OrderByDescending(p => p.Length).FirstOrDefault(p => p.ToLower().StartsWith("mqtt"));
|
return requestedSubProtocolValues.OrderByDescending(p => p.Length).FirstOrDefault(p => p.ToLower().StartsWith("mqtt"));
|
||||||
|
|||||||
@@ -26,10 +26,7 @@ public sealed class MqttWebSocketServerAdapter : IMqttServerAdapter
|
|||||||
|
|
||||||
public async Task RunWebSocketConnectionAsync(WebSocket webSocket, HttpContext httpContext)
|
public async Task RunWebSocketConnectionAsync(WebSocket webSocket, HttpContext httpContext)
|
||||||
{
|
{
|
||||||
if (webSocket == null)
|
ArgumentNullException.ThrowIfNull(webSocket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(webSocket));
|
|
||||||
}
|
|
||||||
|
|
||||||
var endpoint = $"{httpContext.Connection.RemoteIpAddress}:{httpContext.Connection.RemotePort}";
|
var endpoint = $"{httpContext.Connection.RemoteIpAddress}:{httpContext.Connection.RemotePort}";
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ public static class ReaderExtensions
|
|||||||
out SequencePosition observed,
|
out SequencePosition observed,
|
||||||
out int bytesRead)
|
out int bytesRead)
|
||||||
{
|
{
|
||||||
if (formatter == null)
|
ArgumentNullException.ThrowIfNull(formatter);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(formatter));
|
|
||||||
}
|
|
||||||
|
|
||||||
packet = null;
|
packet = null;
|
||||||
consumed = input.Start;
|
consumed = input.Start;
|
||||||
|
|||||||
@@ -16,15 +16,8 @@ public static class ServiceCollectionExtensions
|
|||||||
{
|
{
|
||||||
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, MqttServerOptions options)
|
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, MqttServerOptions options)
|
||||||
{
|
{
|
||||||
if (services == null)
|
ArgumentNullException.ThrowIfNull(services);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
throw new ArgumentNullException(nameof(services));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
services.AddSingleton(options);
|
services.AddSingleton(options);
|
||||||
services.AddHostedMqttServer();
|
services.AddHostedMqttServer();
|
||||||
@@ -34,10 +27,7 @@ public static class ServiceCollectionExtensions
|
|||||||
|
|
||||||
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, Action<MqttServerOptionsBuilder> configure)
|
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, Action<MqttServerOptionsBuilder> configure)
|
||||||
{
|
{
|
||||||
if (services == null)
|
ArgumentNullException.ThrowIfNull(services);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(services));
|
|
||||||
}
|
|
||||||
|
|
||||||
var serverOptionsBuilder = new MqttServerOptionsBuilder();
|
var serverOptionsBuilder = new MqttServerOptionsBuilder();
|
||||||
|
|
||||||
@@ -61,10 +51,7 @@ public static class ServiceCollectionExtensions
|
|||||||
|
|
||||||
public static IServiceCollection AddHostedMqttServerWithServices(this IServiceCollection services, Action<AspNetMqttServerOptionsBuilder> configure)
|
public static IServiceCollection AddHostedMqttServerWithServices(this IServiceCollection services, Action<AspNetMqttServerOptionsBuilder> configure)
|
||||||
{
|
{
|
||||||
if (services == null)
|
ArgumentNullException.ThrowIfNull(services);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(services));
|
|
||||||
}
|
|
||||||
|
|
||||||
services.AddSingleton(
|
services.AddSingleton(
|
||||||
s =>
|
s =>
|
||||||
@@ -89,20 +76,14 @@ public static class ServiceCollectionExtensions
|
|||||||
|
|
||||||
public static void AddMqttLogger(this IServiceCollection services, IMqttNetLogger logger)
|
public static void AddMqttLogger(this IServiceCollection services, IMqttNetLogger logger)
|
||||||
{
|
{
|
||||||
if (services == null)
|
ArgumentNullException.ThrowIfNull(services);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(services));
|
|
||||||
}
|
|
||||||
|
|
||||||
services.AddSingleton(logger);
|
services.AddSingleton(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddMqttServer(this IServiceCollection serviceCollection, Action<MqttServerOptionsBuilder> configure = null)
|
public static IServiceCollection AddMqttServer(this IServiceCollection serviceCollection, Action<MqttServerOptionsBuilder> configure = null)
|
||||||
{
|
{
|
||||||
if (serviceCollection is null)
|
ArgumentNullException.ThrowIfNull(serviceCollection);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(serviceCollection));
|
|
||||||
}
|
|
||||||
|
|
||||||
serviceCollection.AddMqttConnectionHandler();
|
serviceCollection.AddMqttConnectionHandler();
|
||||||
serviceCollection.AddHostedMqttServer(configure);
|
serviceCollection.AddHostedMqttServer(configure);
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ namespace MQTTnet.Benchmarks
|
|||||||
out SequencePosition observed,
|
out SequencePosition observed,
|
||||||
out int bytesRead)
|
out int bytesRead)
|
||||||
{
|
{
|
||||||
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
|
ArgumentNullException.ThrowIfNull(formatter);
|
||||||
|
|
||||||
packet = null;
|
packet = null;
|
||||||
consumed = input.Start;
|
consumed = input.Start;
|
||||||
|
|||||||
@@ -73,15 +73,8 @@ namespace MQTTnet.Benchmarks
|
|||||||
|
|
||||||
static bool LegacyMethodByStringSplit(string topic, string filter)
|
static bool LegacyMethodByStringSplit(string topic, string filter)
|
||||||
{
|
{
|
||||||
if (topic == null)
|
ArgumentNullException.ThrowIfNull(topic);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(filter);
|
||||||
throw new ArgumentNullException(nameof(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(filter));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.Equals(topic, filter, StringComparison.Ordinal))
|
if (string.Equals(topic, filter, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,10 +10,7 @@ namespace MQTTnet.Extensions.Rpc
|
|||||||
{
|
{
|
||||||
public MqttRpcTopicPair CreateRpcTopics(TopicGenerationContext context)
|
public MqttRpcTopicPair CreateRpcTopics(TopicGenerationContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
ArgumentNullException.ThrowIfNull(context);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.MethodName.Contains("/") || context.MethodName.Contains("+") || context.MethodName.Contains("#"))
|
if (context.MethodName.Contains("/") || context.MethodName.Contains("+") || context.MethodName.Contains("#"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,15 +20,8 @@ namespace MQTTnet.Extensions.Rpc
|
|||||||
|
|
||||||
public static IMqttRpcClient CreateMqttRpcClient(this MqttClientFactory _, IMqttClient mqttClient, MqttRpcClientOptions rpcClientOptions)
|
public static IMqttRpcClient CreateMqttRpcClient(this MqttClientFactory _, IMqttClient mqttClient, MqttRpcClientOptions rpcClientOptions)
|
||||||
{
|
{
|
||||||
if (mqttClient == null)
|
ArgumentNullException.ThrowIfNull(mqttClient);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(rpcClientOptions);
|
||||||
throw new ArgumentNullException(nameof(mqttClient));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rpcClientOptions == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(rpcClientOptions));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttRpcClient(mqttClient, rpcClientOptions);
|
return new MqttRpcClient(mqttClient, rpcClientOptions);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,10 +65,7 @@ namespace MQTTnet.Extensions.Rpc
|
|||||||
|
|
||||||
public async Task<byte[]> ExecuteAsync(string methodName, byte[] payload, MqttQualityOfServiceLevel qualityOfServiceLevel, IDictionary<string, object> parameters = null, CancellationToken cancellationToken = default)
|
public async Task<byte[]> ExecuteAsync(string methodName, byte[] payload, MqttQualityOfServiceLevel qualityOfServiceLevel, IDictionary<string, object> parameters = null, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (methodName == null)
|
ArgumentNullException.ThrowIfNull(methodName);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(methodName));
|
|
||||||
}
|
|
||||||
|
|
||||||
var context = new TopicGenerationContext(_mqttClient, _options, methodName, parameters, qualityOfServiceLevel);
|
var context = new TopicGenerationContext(_mqttClient, _options, methodName, parameters, qualityOfServiceLevel);
|
||||||
var topicNames = _options.TopicGenerationStrategy.CreateRpcTopics(context);
|
var topicNames = _options.TopicGenerationStrategy.CreateRpcTopics(context);
|
||||||
|
|||||||
@@ -41,10 +41,7 @@ public sealed class MqttTopicTemplate : IEquatable<MqttTopicTemplate>
|
|||||||
/// </exception>
|
/// </exception>
|
||||||
public MqttTopicTemplate(string topicTemplate)
|
public MqttTopicTemplate(string topicTemplate)
|
||||||
{
|
{
|
||||||
if (topicTemplate == null)
|
ArgumentNullException.ThrowIfNull(topicTemplate);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicTemplate));
|
|
||||||
}
|
|
||||||
|
|
||||||
MqttTopicValidator.ThrowIfInvalidSubscribe(topicTemplate);
|
MqttTopicValidator.ThrowIfInvalidSubscribe(topicTemplate);
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ public static class MqttConnAckPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttConnAckPacket Create(ValidatingConnectionEventArgs validatingConnectionEventArgs)
|
public static MqttConnAckPacket Create(ValidatingConnectionEventArgs validatingConnectionEventArgs)
|
||||||
{
|
{
|
||||||
if (validatingConnectionEventArgs == null)
|
ArgumentNullException.ThrowIfNull(validatingConnectionEventArgs);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(validatingConnectionEventArgs));
|
|
||||||
}
|
|
||||||
|
|
||||||
var connAckPacket = new MqttConnAckPacket
|
var connAckPacket = new MqttConnAckPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,15 +11,8 @@ public static class MqttPubAckPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttPubAckPacket Create(MqttPublishPacket publishPacket, DispatchApplicationMessageResult dispatchApplicationMessageResult)
|
public static MqttPubAckPacket Create(MqttPublishPacket publishPacket, DispatchApplicationMessageResult dispatchApplicationMessageResult)
|
||||||
{
|
{
|
||||||
if (publishPacket == null)
|
ArgumentNullException.ThrowIfNull(publishPacket);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(dispatchApplicationMessageResult);
|
||||||
throw new ArgumentNullException(nameof(publishPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dispatchApplicationMessageResult == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(dispatchApplicationMessageResult));
|
|
||||||
}
|
|
||||||
|
|
||||||
var pubAckPacket = new MqttPubAckPacket
|
var pubAckPacket = new MqttPubAckPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ public static class MqttPubCompPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttPubCompPacket Create(MqttPubRelPacket pubRelPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
public static MqttPubCompPacket Create(MqttPubRelPacket pubRelPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
||||||
{
|
{
|
||||||
if (pubRelPacket == null)
|
ArgumentNullException.ThrowIfNull(pubRelPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(pubRelPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttPubCompPacket
|
return new MqttPubCompPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ public static class MqttPubRecPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttPacket Create(MqttPublishPacket publishPacket, DispatchApplicationMessageResult dispatchApplicationMessageResult)
|
public static MqttPacket Create(MqttPublishPacket publishPacket, DispatchApplicationMessageResult dispatchApplicationMessageResult)
|
||||||
{
|
{
|
||||||
if (publishPacket == null)
|
ArgumentNullException.ThrowIfNull(publishPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(publishPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
var pubRecPacket = new MqttPubRecPacket
|
var pubRecPacket = new MqttPubRecPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ public static class MqttPubRelPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttPubRelPacket Create(MqttPubRecPacket pubRecPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
public static MqttPubRelPacket Create(MqttPubRecPacket pubRecPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
||||||
{
|
{
|
||||||
if (pubRecPacket == null)
|
ArgumentNullException.ThrowIfNull(pubRecPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(pubRecPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttPubRelPacket
|
return new MqttPubRelPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ public static class MqttPublishPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttPublishPacket Create(MqttConnectPacket connectPacket)
|
public static MqttPublishPacket Create(MqttConnectPacket connectPacket)
|
||||||
{
|
{
|
||||||
if (connectPacket == null)
|
ArgumentNullException.ThrowIfNull(connectPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(connectPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!connectPacket.WillFlag)
|
if (!connectPacket.WillFlag)
|
||||||
{
|
{
|
||||||
@@ -46,10 +43,7 @@ public static class MqttPublishPacketFactory
|
|||||||
|
|
||||||
public static MqttPublishPacket Create(MqttApplicationMessage applicationMessage)
|
public static MqttPublishPacket Create(MqttApplicationMessage applicationMessage)
|
||||||
{
|
{
|
||||||
if (applicationMessage == null)
|
ArgumentNullException.ThrowIfNull(applicationMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy all values to their matching counterparts.
|
// Copy all values to their matching counterparts.
|
||||||
// The not supported values in MQTT 3.1.1 are not serialized (excluded) later.
|
// The not supported values in MQTT 3.1.1 are not serialized (excluded) later.
|
||||||
@@ -75,10 +69,7 @@ public static class MqttPublishPacketFactory
|
|||||||
|
|
||||||
public static MqttPublishPacket Create(MqttRetainedMessageMatch retainedMessage)
|
public static MqttPublishPacket Create(MqttRetainedMessageMatch retainedMessage)
|
||||||
{
|
{
|
||||||
if (retainedMessage == null)
|
ArgumentNullException.ThrowIfNull(retainedMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(retainedMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
var publishPacket = Create(retainedMessage.ApplicationMessage);
|
var publishPacket = Create(retainedMessage.ApplicationMessage);
|
||||||
publishPacket.QualityOfServiceLevel = retainedMessage.SubscriptionQualityOfServiceLevel;
|
publishPacket.QualityOfServiceLevel = retainedMessage.SubscriptionQualityOfServiceLevel;
|
||||||
|
|||||||
@@ -10,15 +10,8 @@ public static class MqttSubAckPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttSubAckPacket Create(MqttSubscribePacket subscribePacket, SubscribeResult subscribeResult)
|
public static MqttSubAckPacket Create(MqttSubscribePacket subscribePacket, SubscribeResult subscribeResult)
|
||||||
{
|
{
|
||||||
if (subscribePacket == null)
|
ArgumentNullException.ThrowIfNull(subscribePacket);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(subscribeResult);
|
||||||
throw new ArgumentNullException(nameof(subscribePacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subscribeResult == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(subscribeResult));
|
|
||||||
}
|
|
||||||
|
|
||||||
var subAckPacket = new MqttSubAckPacket
|
var subAckPacket = new MqttSubAckPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,15 +10,8 @@ namespace MQTTnet.Server.Internal.Formatter
|
|||||||
{
|
{
|
||||||
public static MqttUnsubAckPacket Create(MqttUnsubscribePacket unsubscribePacket, UnsubscribeResult unsubscribeResult)
|
public static MqttUnsubAckPacket Create(MqttUnsubscribePacket unsubscribePacket, UnsubscribeResult unsubscribeResult)
|
||||||
{
|
{
|
||||||
if (unsubscribePacket == null)
|
ArgumentNullException.ThrowIfNull(unsubscribePacket);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(unsubscribeResult);
|
||||||
throw new ArgumentNullException(nameof(unsubscribePacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unsubscribeResult == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(unsubscribeResult));
|
|
||||||
}
|
|
||||||
|
|
||||||
var unsubAckPacket = new MqttUnsubAckPacket
|
var unsubAckPacket = new MqttUnsubAckPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,10 +38,7 @@ public sealed class MqttClientSessionsManager : ISubscriptionChangedNotification
|
|||||||
|
|
||||||
public MqttClientSessionsManager(MqttServerOptions options, MqttRetainedMessagesManager retainedMessagesManager, MqttServerEventContainer eventContainer, IMqttNetLogger logger)
|
public MqttClientSessionsManager(MqttServerOptions options, MqttRetainedMessagesManager retainedMessagesManager, MqttServerEventContainer eventContainer, IMqttNetLogger logger)
|
||||||
{
|
{
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger = logger.WithSource(nameof(MqttClientSessionsManager));
|
_logger = logger.WithSource(nameof(MqttClientSessionsManager));
|
||||||
_rootLogger = logger;
|
_rootLogger = logger;
|
||||||
@@ -53,10 +50,7 @@ public sealed class MqttClientSessionsManager : ISubscriptionChangedNotification
|
|||||||
|
|
||||||
public async Task CloseAllConnections(MqttServerClientDisconnectOptions options)
|
public async Task CloseAllConnections(MqttServerClientDisconnectOptions options)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<MqttConnectedClient> connections;
|
List<MqttConnectedClient> connections;
|
||||||
lock (_clients)
|
lock (_clients)
|
||||||
@@ -481,15 +475,8 @@ public sealed class MqttClientSessionsManager : ISubscriptionChangedNotification
|
|||||||
|
|
||||||
public async Task SubscribeAsync(string clientId, ICollection<MqttTopicFilter> topicFilters)
|
public async Task SubscribeAsync(string clientId, ICollection<MqttTopicFilter> topicFilters)
|
||||||
{
|
{
|
||||||
if (clientId == null)
|
ArgumentNullException.ThrowIfNull(clientId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topicFilters);
|
||||||
throw new ArgumentNullException(nameof(clientId));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topicFilters == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilters));
|
|
||||||
}
|
|
||||||
|
|
||||||
var fakeSubscribePacket = new MqttSubscribePacket();
|
var fakeSubscribePacket = new MqttSubscribePacket();
|
||||||
fakeSubscribePacket.TopicFilters.AddRange(topicFilters);
|
fakeSubscribePacket.TopicFilters.AddRange(topicFilters);
|
||||||
@@ -510,15 +497,8 @@ public sealed class MqttClientSessionsManager : ISubscriptionChangedNotification
|
|||||||
|
|
||||||
public Task UnsubscribeAsync(string clientId, ICollection<string> topicFilters)
|
public Task UnsubscribeAsync(string clientId, ICollection<string> topicFilters)
|
||||||
{
|
{
|
||||||
if (clientId == null)
|
ArgumentNullException.ThrowIfNull(clientId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topicFilters);
|
||||||
throw new ArgumentNullException(nameof(clientId));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topicFilters == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilters));
|
|
||||||
}
|
|
||||||
|
|
||||||
var fakeUnsubscribePacket = new MqttUnsubscribePacket();
|
var fakeUnsubscribePacket = new MqttUnsubscribePacket();
|
||||||
fakeUnsubscribePacket.TopicFilters.AddRange(topicFilters);
|
fakeUnsubscribePacket.TopicFilters.AddRange(topicFilters);
|
||||||
|
|||||||
@@ -50,10 +50,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
|
|
||||||
public void HandleReceivedPacket(MqttPacket packet)
|
public void HandleReceivedPacket(MqttPacket packet)
|
||||||
{
|
{
|
||||||
if (packet == null)
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
// This class is tracking all values from Clients perspective!
|
// This class is tracking all values from Clients perspective!
|
||||||
LastPacketSentTimestamp = DateTime.UtcNow;
|
LastPacketSentTimestamp = DateTime.UtcNow;
|
||||||
@@ -74,10 +71,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
|
|
||||||
public void HandleSentPacket(MqttPacket packet)
|
public void HandleSentPacket(MqttPacket packet)
|
||||||
{
|
{
|
||||||
if (packet == null)
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
// This class is tracking all values from Clients perspective!
|
// This class is tracking all values from Clients perspective!
|
||||||
LastPacketReceivedTimestamp = DateTime.UtcNow;
|
LastPacketReceivedTimestamp = DateTime.UtcNow;
|
||||||
|
|||||||
@@ -161,10 +161,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
|
|
||||||
public async Task<SubscribeResult> Subscribe(MqttSubscribePacket subscribePacket, CancellationToken cancellationToken)
|
public async Task<SubscribeResult> Subscribe(MqttSubscribePacket subscribePacket, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (subscribePacket == null)
|
ArgumentNullException.ThrowIfNull(subscribePacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(subscribePacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
var retainedApplicationMessages = await _retainedMessagesManager.GetMessages().ConfigureAwait(false);
|
var retainedApplicationMessages = await _retainedMessagesManager.GetMessages().ConfigureAwait(false);
|
||||||
var result = new SubscribeResult(subscribePacket.TopicFilters.Count);
|
var result = new SubscribeResult(subscribePacket.TopicFilters.Count);
|
||||||
@@ -222,10 +219,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
|
|
||||||
public async Task<UnsubscribeResult> Unsubscribe(MqttUnsubscribePacket unsubscribePacket, CancellationToken cancellationToken)
|
public async Task<UnsubscribeResult> Unsubscribe(MqttUnsubscribePacket unsubscribePacket, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (unsubscribePacket == null)
|
ArgumentNullException.ThrowIfNull(unsubscribePacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(unsubscribePacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = new UnsubscribeResult();
|
var result = new UnsubscribeResult();
|
||||||
|
|
||||||
|
|||||||
@@ -48,10 +48,7 @@ public sealed class MqttConnectedClient : IDisposable
|
|||||||
Endpoint = channelAdapter.Endpoint;
|
Endpoint = channelAdapter.Endpoint;
|
||||||
Session = session ?? throw new ArgumentNullException(nameof(session));
|
Session = session ?? throw new ArgumentNullException(nameof(session));
|
||||||
|
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger = logger.WithSource(nameof(MqttConnectedClient));
|
_logger = logger.WithSource(nameof(MqttConnectedClient));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
{
|
{
|
||||||
_eventContainer = eventContainer ?? throw new ArgumentNullException(nameof(eventContainer));
|
_eventContainer = eventContainer ?? throw new ArgumentNullException(nameof(eventContainer));
|
||||||
|
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
|
|
||||||
_logger = logger.WithSource(nameof(MqttRetainedMessagesManager));
|
_logger = logger.WithSource(nameof(MqttRetainedMessagesManager));
|
||||||
}
|
}
|
||||||
@@ -53,10 +52,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
|
|
||||||
public async Task UpdateMessage(string clientId, MqttApplicationMessage applicationMessage)
|
public async Task UpdateMessage(string clientId, MqttApplicationMessage applicationMessage)
|
||||||
{
|
{
|
||||||
if (applicationMessage == null)
|
ArgumentNullException.ThrowIfNull(applicationMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,10 +27,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
_options = options ?? throw new ArgumentNullException(nameof(options));
|
_options = options ?? throw new ArgumentNullException(nameof(options));
|
||||||
_sessionsManager = sessionsManager ?? throw new ArgumentNullException(nameof(sessionsManager));
|
_sessionsManager = sessionsManager ?? throw new ArgumentNullException(nameof(sessionsManager));
|
||||||
|
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger = logger.WithSource(nameof(MqttServerKeepAliveMonitor));
|
_logger = logger.WithSource(nameof(MqttServerKeepAliveMonitor));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
|
|
||||||
public bool TryGetSession(string id, out MqttSession session)
|
public bool TryGetSession(string id, out MqttSession session)
|
||||||
{
|
{
|
||||||
if (id == null)
|
ArgumentNullException.ThrowIfNull(id);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_sessions.TryGetValue(id, out session))
|
if (!_sessions.TryGetValue(id, out session))
|
||||||
{
|
{
|
||||||
@@ -63,10 +60,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
|
|
||||||
public bool TryRemoveSession(string id, out MqttSession session)
|
public bool TryRemoveSession(string id, out MqttSession session)
|
||||||
{
|
{
|
||||||
if (id == null)
|
ArgumentNullException.ThrowIfNull(id);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_sessions.TryGetValue(id, out session))
|
if (_sessions.TryGetValue(id, out session))
|
||||||
{
|
{
|
||||||
@@ -79,10 +73,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
|
|
||||||
public void UpdateSession(string id, MqttSession session)
|
public void UpdateSession(string id, MqttSession session)
|
||||||
{
|
{
|
||||||
if (id == null)
|
ArgumentNullException.ThrowIfNull(id);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
_sessions[id] = session;
|
_sessions[id] = session;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,7 @@ public class MqttServer : Disposable
|
|||||||
{
|
{
|
||||||
_options = options ?? throw new ArgumentNullException(nameof(options));
|
_options = options ?? throw new ArgumentNullException(nameof(options));
|
||||||
|
|
||||||
if (adapters == null)
|
ArgumentNullException.ThrowIfNull(adapters);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(adapters));
|
|
||||||
}
|
|
||||||
|
|
||||||
_adapters = adapters.ToList();
|
_adapters = adapters.ToList();
|
||||||
|
|
||||||
@@ -202,15 +199,8 @@ public class MqttServer : Disposable
|
|||||||
|
|
||||||
public Task DisconnectClientAsync(string id, MqttServerClientDisconnectOptions options)
|
public Task DisconnectClientAsync(string id, MqttServerClientDisconnectOptions options)
|
||||||
{
|
{
|
||||||
if (id == null)
|
ArgumentNullException.ThrowIfNull(id);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
throw new ArgumentNullException(nameof(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
ThrowIfNotStarted();
|
ThrowIfNotStarted();
|
||||||
|
|
||||||
@@ -226,10 +216,7 @@ public class MqttServer : Disposable
|
|||||||
|
|
||||||
public Task<MqttApplicationMessage> GetRetainedMessageAsync(string topic)
|
public Task<MqttApplicationMessage> GetRetainedMessageAsync(string topic)
|
||||||
{
|
{
|
||||||
if (topic == null)
|
ArgumentNullException.ThrowIfNull(topic);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
ThrowIfNotStarted();
|
ThrowIfNotStarted();
|
||||||
|
|
||||||
@@ -252,15 +239,8 @@ public class MqttServer : Disposable
|
|||||||
|
|
||||||
public Task InjectApplicationMessage(InjectedMqttApplicationMessage injectedApplicationMessage, CancellationToken cancellationToken = default)
|
public Task InjectApplicationMessage(InjectedMqttApplicationMessage injectedApplicationMessage, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (injectedApplicationMessage == null)
|
ArgumentNullException.ThrowIfNull(injectedApplicationMessage);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(injectedApplicationMessage.ApplicationMessage);
|
||||||
throw new ArgumentNullException(nameof(injectedApplicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (injectedApplicationMessage.ApplicationMessage == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(injectedApplicationMessage.ApplicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
MqttTopicValidator.ThrowIfInvalid(injectedApplicationMessage.ApplicationMessage.Topic);
|
MqttTopicValidator.ThrowIfInvalid(injectedApplicationMessage.ApplicationMessage.Topic);
|
||||||
|
|
||||||
@@ -306,10 +286,7 @@ public class MqttServer : Disposable
|
|||||||
|
|
||||||
public async Task StopAsync(MqttServerStopOptions options)
|
public async Task StopAsync(MqttServerStopOptions options)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -343,15 +320,8 @@ public class MqttServer : Disposable
|
|||||||
|
|
||||||
public Task SubscribeAsync(string clientId, ICollection<MqttTopicFilter> topicFilters)
|
public Task SubscribeAsync(string clientId, ICollection<MqttTopicFilter> topicFilters)
|
||||||
{
|
{
|
||||||
if (clientId == null)
|
ArgumentNullException.ThrowIfNull(clientId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topicFilters);
|
||||||
throw new ArgumentNullException(nameof(clientId));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topicFilters == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilters));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var topicFilter in topicFilters)
|
foreach (var topicFilter in topicFilters)
|
||||||
{
|
{
|
||||||
@@ -366,15 +336,8 @@ public class MqttServer : Disposable
|
|||||||
|
|
||||||
public Task UnsubscribeAsync(string clientId, ICollection<string> topicFilters)
|
public Task UnsubscribeAsync(string clientId, ICollection<string> topicFilters)
|
||||||
{
|
{
|
||||||
if (clientId == null)
|
ArgumentNullException.ThrowIfNull(clientId);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topicFilters);
|
||||||
throw new ArgumentNullException(nameof(clientId));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topicFilters == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilters));
|
|
||||||
}
|
|
||||||
|
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
ThrowIfNotStarted();
|
ThrowIfNotStarted();
|
||||||
@@ -384,10 +347,7 @@ public class MqttServer : Disposable
|
|||||||
|
|
||||||
public Task UpdateRetainedMessageAsync(MqttApplicationMessage retainedMessage)
|
public Task UpdateRetainedMessageAsync(MqttApplicationMessage retainedMessage)
|
||||||
{
|
{
|
||||||
if (retainedMessage == null)
|
ArgumentNullException.ThrowIfNull(retainedMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(retainedMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
ThrowIfNotStarted();
|
ThrowIfNotStarted();
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ public static class MqttServerExtensions
|
|||||||
{
|
{
|
||||||
public static Task DisconnectClientAsync(this MqttServer server, string id, MqttDisconnectReasonCode reasonCode = MqttDisconnectReasonCode.NormalDisconnection)
|
public static Task DisconnectClientAsync(this MqttServer server, string id, MqttDisconnectReasonCode reasonCode = MqttDisconnectReasonCode.NormalDisconnection)
|
||||||
{
|
{
|
||||||
if (server == null)
|
ArgumentNullException.ThrowIfNull(server);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(server));
|
|
||||||
}
|
|
||||||
|
|
||||||
return server.DisconnectClientAsync(id, new MqttServerClientDisconnectOptions { ReasonCode = reasonCode });
|
return server.DisconnectClientAsync(id, new MqttServerClientDisconnectOptions { ReasonCode = reasonCode });
|
||||||
}
|
}
|
||||||
@@ -28,15 +25,8 @@ public static class MqttServerExtensions
|
|||||||
MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce,
|
MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce,
|
||||||
bool retain = false)
|
bool retain = false)
|
||||||
{
|
{
|
||||||
if (server == null)
|
ArgumentNullException.ThrowIfNull(server);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topic);
|
||||||
throw new ArgumentNullException(nameof(server));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topic == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
var payloadBuffer = EmptyBuffer.Array;
|
var payloadBuffer = EmptyBuffer.Array;
|
||||||
if (payload is string stringPayload)
|
if (payload is string stringPayload)
|
||||||
@@ -57,50 +47,25 @@ public static class MqttServerExtensions
|
|||||||
|
|
||||||
public static Task StopAsync(this MqttServer server)
|
public static Task StopAsync(this MqttServer server)
|
||||||
{
|
{
|
||||||
if (server == null)
|
ArgumentNullException.ThrowIfNull(server);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(server));
|
|
||||||
}
|
|
||||||
|
|
||||||
return server.StopAsync(new MqttServerStopOptions());
|
return server.StopAsync(new MqttServerStopOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task SubscribeAsync(this MqttServer server, string clientId, params MqttTopicFilter[] topicFilters)
|
public static Task SubscribeAsync(this MqttServer server, string clientId, params MqttTopicFilter[] topicFilters)
|
||||||
{
|
{
|
||||||
if (server == null)
|
ArgumentNullException.ThrowIfNull(server);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(clientId);
|
||||||
throw new ArgumentNullException(nameof(server));
|
ArgumentNullException.ThrowIfNull(topicFilters);
|
||||||
}
|
|
||||||
|
|
||||||
if (clientId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientId));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topicFilters == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilters));
|
|
||||||
}
|
|
||||||
|
|
||||||
return server.SubscribeAsync(clientId, topicFilters);
|
return server.SubscribeAsync(clientId, topicFilters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task SubscribeAsync(this MqttServer server, string clientId, string topic)
|
public static Task SubscribeAsync(this MqttServer server, string clientId, string topic)
|
||||||
{
|
{
|
||||||
if (server == null)
|
ArgumentNullException.ThrowIfNull(server);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(clientId);
|
||||||
throw new ArgumentNullException(nameof(server));
|
ArgumentNullException.ThrowIfNull(topic);
|
||||||
}
|
|
||||||
|
|
||||||
if (clientId == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientId));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topic == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
var topicFilters = new MqttTopicFilterBuilder().WithTopic(topic).Build();
|
var topicFilters = new MqttTopicFilterBuilder().WithTopic(topic).Build();
|
||||||
return server.SubscribeAsync(clientId, topicFilters);
|
return server.SubscribeAsync(clientId, topicFilters);
|
||||||
|
|||||||
@@ -39,10 +39,7 @@ public sealed class MqttServerFactory
|
|||||||
|
|
||||||
public MqttServer CreateMqttServer(MqttServerOptions options, IMqttNetLogger logger)
|
public MqttServer CreateMqttServer(MqttServerOptions options, IMqttNetLogger logger)
|
||||||
{
|
{
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
var serverAdapters = DefaultServerAdapters.Select(a => a.Invoke(this));
|
var serverAdapters = DefaultServerAdapters.Select(a => a.Invoke(this));
|
||||||
return CreateMqttServer(options, serverAdapters, logger);
|
return CreateMqttServer(options, serverAdapters, logger);
|
||||||
@@ -50,25 +47,15 @@ public sealed class MqttServerFactory
|
|||||||
|
|
||||||
public MqttServer CreateMqttServer(MqttServerOptions options, IEnumerable<IMqttServerAdapter> serverAdapters, IMqttNetLogger logger)
|
public MqttServer CreateMqttServer(MqttServerOptions options, IEnumerable<IMqttServerAdapter> serverAdapters, IMqttNetLogger logger)
|
||||||
{
|
{
|
||||||
if (serverAdapters == null)
|
ArgumentNullException.ThrowIfNull(serverAdapters);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
throw new ArgumentNullException(nameof(serverAdapters));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttServer(options, serverAdapters, logger);
|
return new MqttServer(options, serverAdapters, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MqttServer CreateMqttServer(MqttServerOptions options, IEnumerable<IMqttServerAdapter> serverAdapters)
|
public MqttServer CreateMqttServer(MqttServerOptions options, IEnumerable<IMqttServerAdapter> serverAdapters)
|
||||||
{
|
{
|
||||||
if (serverAdapters == null)
|
ArgumentNullException.ThrowIfNull(serverAdapters);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(serverAdapters));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttServer(options, serverAdapters, DefaultLogger);
|
return new MqttServer(options, serverAdapters, DefaultLogger);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,10 +180,7 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public MqttServerOptionsBuilder WithEncryptionCertificate(byte[] value, IMqttServerCertificateCredentials credentials = null)
|
public MqttServerOptionsBuilder WithEncryptionCertificate(byte[] value, IMqttServerCertificateCredentials credentials = null)
|
||||||
{
|
{
|
||||||
if (value == null)
|
ArgumentNullException.ThrowIfNull(value);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
_options.TlsEndpointOptions.CertificateProvider = new BlobCertificateProvider(value)
|
_options.TlsEndpointOptions.CertificateProvider = new BlobCertificateProvider(value)
|
||||||
{
|
{
|
||||||
@@ -195,10 +192,7 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public MqttServerOptionsBuilder WithEncryptionCertificate(X509Certificate2 certificate)
|
public MqttServerOptionsBuilder WithEncryptionCertificate(X509Certificate2 certificate)
|
||||||
{
|
{
|
||||||
if (certificate == null)
|
ArgumentNullException.ThrowIfNull(certificate);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(certificate));
|
|
||||||
}
|
|
||||||
|
|
||||||
_options.TlsEndpointOptions.CertificateProvider = new X509CertificateProvider(certificate);
|
_options.TlsEndpointOptions.CertificateProvider = new X509CertificateProvider(certificate);
|
||||||
return this;
|
return this;
|
||||||
@@ -206,10 +200,7 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public MqttServerOptionsBuilder WithEncryptionCertificate(ICertificateProvider certificateProvider)
|
public MqttServerOptionsBuilder WithEncryptionCertificate(ICertificateProvider certificateProvider)
|
||||||
{
|
{
|
||||||
if (certificateProvider == null)
|
ArgumentNullException.ThrowIfNull(certificateProvider);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(certificateProvider));
|
|
||||||
}
|
|
||||||
|
|
||||||
_options.TlsEndpointOptions.CertificateProvider = certificateProvider;
|
_options.TlsEndpointOptions.CertificateProvider = certificateProvider;
|
||||||
|
|
||||||
|
|||||||
@@ -50,10 +50,7 @@ public sealed class MqttClientStatus
|
|||||||
|
|
||||||
public Task DisconnectAsync(MqttServerClientDisconnectOptions options)
|
public Task DisconnectAsync(MqttServerClientDisconnectOptions options)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return _client.StopAsync(options);
|
return _client.StopAsync(options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ public static class MqttClientStatusExtensions
|
|||||||
|
|
||||||
public static Task DisconnectAsync(this MqttClientStatus clientStatus)
|
public static Task DisconnectAsync(this MqttClientStatus clientStatus)
|
||||||
{
|
{
|
||||||
if (clientStatus == null)
|
ArgumentNullException.ThrowIfNull(clientStatus);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientStatus));
|
|
||||||
}
|
|
||||||
|
|
||||||
return clientStatus.DisconnectAsync(DefaultDisconnectOptions);
|
return clientStatus.DisconnectAsync(DefaultDisconnectOptions);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,10 +42,7 @@ public sealed class MqttSessionStatus
|
|||||||
|
|
||||||
public Task DeliverApplicationMessageAsync(MqttApplicationMessage applicationMessage)
|
public Task DeliverApplicationMessageAsync(MqttApplicationMessage applicationMessage)
|
||||||
{
|
{
|
||||||
if (applicationMessage == null)
|
ArgumentNullException.ThrowIfNull(applicationMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
var packetBusItem = new MqttPacketBusItem(MqttPublishPacketFactory.Create(applicationMessage));
|
var packetBusItem = new MqttPacketBusItem(MqttPublishPacketFactory.Create(applicationMessage));
|
||||||
_session.EnqueueDataPacket(packetBusItem);
|
_session.EnqueueDataPacket(packetBusItem);
|
||||||
@@ -55,10 +52,7 @@ public sealed class MqttSessionStatus
|
|||||||
|
|
||||||
public Task EnqueueApplicationMessageAsync(MqttApplicationMessage applicationMessage)
|
public Task EnqueueApplicationMessageAsync(MqttApplicationMessage applicationMessage)
|
||||||
{
|
{
|
||||||
if (applicationMessage == null)
|
ArgumentNullException.ThrowIfNull(applicationMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
_session.EnqueueDataPacket(new MqttPacketBusItem(MqttPublishPacketFactory.Create(applicationMessage)));
|
_session.EnqueueDataPacket(new MqttPacketBusItem(MqttPublishPacketFactory.Create(applicationMessage)));
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public MqttServerStopOptionsBuilder WithDefaultClientDisconnectOptions(Action<MqttServerClientDisconnectOptionsBuilder> builder)
|
public MqttServerStopOptionsBuilder WithDefaultClientDisconnectOptions(Action<MqttServerClientDisconnectOptionsBuilder> builder)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
ArgumentNullException.ThrowIfNull(builder);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(builder));
|
|
||||||
}
|
|
||||||
|
|
||||||
var optionsBuilder = new MqttServerClientDisconnectOptionsBuilder();
|
var optionsBuilder = new MqttServerClientDisconnectOptionsBuilder();
|
||||||
builder.Invoke(optionsBuilder);
|
builder.Invoke(optionsBuilder);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace MQTTnet.TestApp
|
|||||||
|
|
||||||
public static void ForwardToConsole(MqttNetEventLogger logger)
|
public static void ForwardToConsole(MqttNetEventLogger logger)
|
||||||
{
|
{
|
||||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
|
|
||||||
logger.LogMessagePublished -= PrintToConsole;
|
logger.LogMessagePublished -= PrintToConsole;
|
||||||
logger.LogMessagePublished += PrintToConsole;
|
logger.LogMessagePublished += PrintToConsole;
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ namespace MQTTnet.Tests.Helpers
|
|||||||
{
|
{
|
||||||
public static TestApplicationMessageReceivedHandler TrackReceivedMessages(this IMqttClient client)
|
public static TestApplicationMessageReceivedHandler TrackReceivedMessages(this IMqttClient client)
|
||||||
{
|
{
|
||||||
if (client == null)
|
ArgumentNullException.ThrowIfNull(client);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(client));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new TestApplicationMessageReceivedHandler(client);
|
return new TestApplicationMessageReceivedHandler(client);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ namespace MQTTnet.Tests.Helpers
|
|||||||
{
|
{
|
||||||
public static object GetFieldValue(this object source, string fieldName)
|
public static object GetFieldValue(this object source, string fieldName)
|
||||||
{
|
{
|
||||||
if (source == null)
|
ArgumentNullException.ThrowIfNull(source);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(source));
|
|
||||||
}
|
|
||||||
|
|
||||||
var field = source.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
|
var field = source.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
if (field == null)
|
if (field == null)
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ namespace MQTTnet.Tests.Mockups
|
|||||||
|
|
||||||
public TestApplicationMessageReceivedHandler(IMqttClient mqttClient)
|
public TestApplicationMessageReceivedHandler(IMqttClient mqttClient)
|
||||||
{
|
{
|
||||||
if (mqttClient == null)
|
ArgumentNullException.ThrowIfNull(mqttClient);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(mqttClient));
|
|
||||||
}
|
|
||||||
|
|
||||||
mqttClient.ApplicationMessageReceivedAsync += OnApplicationMessageReceivedAsync;
|
mqttClient.ApplicationMessageReceivedAsync += OnApplicationMessageReceivedAsync;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,10 +102,7 @@ namespace MQTTnet.Tests.Mockups
|
|||||||
|
|
||||||
public async Task<IMqttClient> ConnectClient(Action<MqttClientOptionsBuilder> configureOptions, TimeSpan timeout = default)
|
public async Task<IMqttClient> ConnectClient(Action<MqttClientOptionsBuilder> configureOptions, TimeSpan timeout = default)
|
||||||
{
|
{
|
||||||
if (configureOptions == null)
|
ArgumentNullException.ThrowIfNull(configureOptions);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(configureOptions));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start with initial default values.
|
// Start with initial default values.
|
||||||
var optionsBuilder = ClientFactory.CreateClientOptionsBuilder().WithProtocolVersion(_protocolVersion).WithTcpServer("127.0.0.1", ServerPort);
|
var optionsBuilder = ClientFactory.CreateClientOptionsBuilder().WithProtocolVersion(_protocolVersion).WithTcpServer("127.0.0.1", ServerPort);
|
||||||
@@ -134,10 +131,7 @@ namespace MQTTnet.Tests.Mockups
|
|||||||
|
|
||||||
public async Task<IMqttClient> ConnectClient(MqttClientOptionsBuilder options, TimeSpan timeout = default)
|
public async Task<IMqttClient> ConnectClient(MqttClientOptionsBuilder options, TimeSpan timeout = default)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
options = options.WithTcpServer("127.0.0.1", ServerPort);
|
options = options.WithTcpServer("127.0.0.1", ServerPort);
|
||||||
|
|
||||||
@@ -160,10 +154,7 @@ namespace MQTTnet.Tests.Mockups
|
|||||||
|
|
||||||
public async Task<IMqttClient> ConnectClient(MqttClientOptions options, TimeSpan timeout = default)
|
public async Task<IMqttClient> ConnectClient(MqttClientOptions options, TimeSpan timeout = default)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
var client = CreateClient();
|
var client = CreateClient();
|
||||||
|
|
||||||
|
|||||||
@@ -38,10 +38,7 @@ public sealed class MqttChannelAdapter : Disposable, IMqttChannelAdapter
|
|||||||
|
|
||||||
PacketFormatterAdapter = packetFormatterAdapter ?? throw new ArgumentNullException(nameof(packetFormatterAdapter));
|
PacketFormatterAdapter = packetFormatterAdapter ?? throw new ArgumentNullException(nameof(packetFormatterAdapter));
|
||||||
|
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger = logger.WithSource(nameof(MqttChannelAdapter));
|
_logger = logger.WithSource(nameof(MqttChannelAdapter));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,7 @@ public sealed class MqttPacketInspector
|
|||||||
{
|
{
|
||||||
_asyncEvent = asyncEvent ?? throw new ArgumentNullException(nameof(asyncEvent));
|
_asyncEvent = asyncEvent ?? throw new ArgumentNullException(nameof(asyncEvent));
|
||||||
|
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger = logger.WithSource(nameof(MqttPacketInspector));
|
_logger = logger.WithSource(nameof(MqttPacketInspector));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ public sealed class MqttClientConnectResultFactory
|
|||||||
{
|
{
|
||||||
public MqttClientConnectResult Create(MqttConnAckPacket connAckPacket, MqttProtocolVersion protocolVersion)
|
public MqttClientConnectResult Create(MqttConnAckPacket connAckPacket, MqttProtocolVersion protocolVersion)
|
||||||
{
|
{
|
||||||
if (connAckPacket == null)
|
ArgumentNullException.ThrowIfNull(connAckPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(connAckPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (protocolVersion == MqttProtocolVersion.V500)
|
if (protocolVersion == MqttProtocolVersion.V500)
|
||||||
{
|
{
|
||||||
@@ -68,10 +65,8 @@ public sealed class MqttClientConnectResultFactory
|
|||||||
|
|
||||||
static MqttClientConnectResult CreateForMqtt311(MqttConnAckPacket connAckPacket)
|
static MqttClientConnectResult CreateForMqtt311(MqttConnAckPacket connAckPacket)
|
||||||
{
|
{
|
||||||
if (connAckPacket == null)
|
ArgumentNullException.ThrowIfNull(connAckPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(connAckPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttClientConnectResult
|
return new MqttClientConnectResult
|
||||||
{
|
{
|
||||||
@@ -84,10 +79,7 @@ public sealed class MqttClientConnectResultFactory
|
|||||||
|
|
||||||
static MqttClientConnectResult CreateForMqtt500(MqttConnAckPacket connAckPacket)
|
static MqttClientConnectResult CreateForMqtt500(MqttConnAckPacket connAckPacket)
|
||||||
{
|
{
|
||||||
if (connAckPacket == null)
|
ArgumentNullException.ThrowIfNull(connAckPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(connAckPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttClientConnectResult
|
return new MqttClientConnectResult
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -209,10 +209,7 @@ namespace MQTTnet.Diagnostics.Logger
|
|||||||
|
|
||||||
public static MqttNetSourceLogger WithSource(this IMqttNetLogger logger, string source)
|
public static MqttNetSourceLogger WithSource(this IMqttNetLogger logger, string source)
|
||||||
{
|
{
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttNetSourceLogger(logger, source);
|
return new MqttNetSourceLogger(logger, source);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ public static class MqttClientDisconnectOptionsValidator
|
|||||||
{
|
{
|
||||||
public static void ThrowIfNotSupported(MqttClientDisconnectOptions options, MqttProtocolVersion protocolVersion)
|
public static void ThrowIfNotSupported(MqttClientDisconnectOptions options, MqttProtocolVersion protocolVersion)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (protocolVersion == MqttProtocolVersion.V500)
|
if (protocolVersion == MqttProtocolVersion.V500)
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-4
@@ -13,10 +13,7 @@ public class MqttExtendedAuthenticationExchangeContext
|
|||||||
{
|
{
|
||||||
public MqttExtendedAuthenticationExchangeContext(MqttAuthPacket authPacket, MqttClient client)
|
public MqttExtendedAuthenticationExchangeContext(MqttAuthPacket authPacket, MqttClient client)
|
||||||
{
|
{
|
||||||
if (authPacket == null)
|
ArgumentNullException.ThrowIfNull(authPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(authPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
ReasonCode = authPacket.ReasonCode;
|
ReasonCode = authPacket.ReasonCode;
|
||||||
ReasonString = authPacket.ReasonString;
|
ReasonString = authPacket.ReasonString;
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ namespace MQTTnet.Formatter
|
|||||||
{
|
{
|
||||||
public static MqttApplicationMessage Create(MqttPublishPacket publishPacket)
|
public static MqttApplicationMessage Create(MqttPublishPacket publishPacket)
|
||||||
{
|
{
|
||||||
if (publishPacket == null)
|
ArgumentNullException.ThrowIfNull(publishPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(publishPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttApplicationMessage
|
return new MqttApplicationMessage
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -105,10 +105,7 @@ namespace MQTTnet.Formatter
|
|||||||
|
|
||||||
public void Write(MqttBufferWriter propertyWriter)
|
public void Write(MqttBufferWriter propertyWriter)
|
||||||
{
|
{
|
||||||
if (propertyWriter == null)
|
ArgumentNullException.ThrowIfNull(propertyWriter);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(propertyWriter));
|
|
||||||
}
|
|
||||||
|
|
||||||
WriteBinary(propertyWriter._buffer, 0, propertyWriter.Length);
|
WriteBinary(propertyWriter._buffer, 0, propertyWriter.Length);
|
||||||
}
|
}
|
||||||
@@ -140,10 +137,7 @@ namespace MQTTnet.Formatter
|
|||||||
|
|
||||||
public void WriteBinary(byte[] buffer, int offset, int count)
|
public void WriteBinary(byte[] buffer, int offset, int count)
|
||||||
{
|
{
|
||||||
if (buffer == null)
|
ArgumentNullException.ThrowIfNull(buffer);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(buffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ public static class MqttConnectPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttConnectPacket Create(MqttClientOptions clientOptions)
|
public static MqttConnectPacket Create(MqttClientOptions clientOptions)
|
||||||
{
|
{
|
||||||
if (clientOptions == null)
|
ArgumentNullException.ThrowIfNull(clientOptions);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientOptions));
|
|
||||||
}
|
|
||||||
|
|
||||||
var connectPacket = new MqttConnectPacket
|
var connectPacket = new MqttConnectPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ public static class MqttPubAckPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttPubAckPacket Create(MqttApplicationMessageReceivedEventArgs applicationMessageReceivedEventArgs)
|
public static MqttPubAckPacket Create(MqttApplicationMessageReceivedEventArgs applicationMessageReceivedEventArgs)
|
||||||
{
|
{
|
||||||
if (applicationMessageReceivedEventArgs == null)
|
ArgumentNullException.ThrowIfNull(applicationMessageReceivedEventArgs);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessageReceivedEventArgs));
|
|
||||||
}
|
|
||||||
|
|
||||||
var pubAckPacket = new MqttPubAckPacket
|
var pubAckPacket = new MqttPubAckPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ public static class MqttPubCompPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttPubCompPacket Create(MqttPubRelPacket pubRelPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
public static MqttPubCompPacket Create(MqttPubRelPacket pubRelPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
||||||
{
|
{
|
||||||
if (pubRelPacket == null)
|
ArgumentNullException.ThrowIfNull(pubRelPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(pubRelPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttPubCompPacket
|
return new MqttPubCompPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ public static class MqttPubRecPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttPubRecPacket Create(MqttApplicationMessageReceivedEventArgs applicationMessageReceivedEventArgs)
|
public static MqttPubRecPacket Create(MqttApplicationMessageReceivedEventArgs applicationMessageReceivedEventArgs)
|
||||||
{
|
{
|
||||||
if (applicationMessageReceivedEventArgs == null)
|
ArgumentNullException.ThrowIfNull(applicationMessageReceivedEventArgs);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessageReceivedEventArgs));
|
|
||||||
}
|
|
||||||
|
|
||||||
var pubRecPacket = Create(applicationMessageReceivedEventArgs.PublishPacket, applicationMessageReceivedEventArgs.ReasonCode);
|
var pubRecPacket = Create(applicationMessageReceivedEventArgs.PublishPacket, applicationMessageReceivedEventArgs.ReasonCode);
|
||||||
pubRecPacket.UserProperties = applicationMessageReceivedEventArgs.ResponseUserProperties;
|
pubRecPacket.UserProperties = applicationMessageReceivedEventArgs.ResponseUserProperties;
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ public static class MqttPubRelPacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttPubRelPacket Create(MqttPubRecPacket pubRecPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
public static MqttPubRelPacket Create(MqttPubRecPacket pubRecPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
||||||
{
|
{
|
||||||
if (pubRecPacket == null)
|
ArgumentNullException.ThrowIfNull(pubRecPacket);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(pubRecPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttPubRelPacket
|
return new MqttPubRelPacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ namespace MQTTnet.Formatter
|
|||||||
{
|
{
|
||||||
public static MqttPublishPacket Create(MqttApplicationMessage applicationMessage)
|
public static MqttPublishPacket Create(MqttApplicationMessage applicationMessage)
|
||||||
{
|
{
|
||||||
if (applicationMessage == null)
|
ArgumentNullException.ThrowIfNull(applicationMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy all values to their matching counterparts.
|
// Copy all values to their matching counterparts.
|
||||||
// The not supported values in MQTT 3.1.1 are not serialized (excluded) later.
|
// The not supported values in MQTT 3.1.1 are not serialized (excluded) later.
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ public static class MqttSubscribePacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttSubscribePacket Create(MqttClientSubscribeOptions clientSubscribeOptions)
|
public static MqttSubscribePacket Create(MqttClientSubscribeOptions clientSubscribeOptions)
|
||||||
{
|
{
|
||||||
if (clientSubscribeOptions == null)
|
ArgumentNullException.ThrowIfNull(clientSubscribeOptions);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientSubscribeOptions));
|
|
||||||
}
|
|
||||||
|
|
||||||
var packet = new MqttSubscribePacket
|
var packet = new MqttSubscribePacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ public static class MqttUnsubscribePacketFactory
|
|||||||
{
|
{
|
||||||
public static MqttUnsubscribePacket Create(MqttClientUnsubscribeOptions clientUnsubscribeOptions)
|
public static MqttUnsubscribePacket Create(MqttClientUnsubscribeOptions clientUnsubscribeOptions)
|
||||||
{
|
{
|
||||||
if (clientUnsubscribeOptions == null)
|
ArgumentNullException.ThrowIfNull(clientUnsubscribeOptions);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientUnsubscribeOptions));
|
|
||||||
}
|
|
||||||
|
|
||||||
var packet = new MqttUnsubscribePacket
|
var packet = new MqttUnsubscribePacket
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -91,10 +91,7 @@ namespace MQTTnet.Formatter.V3
|
|||||||
|
|
||||||
public MqttPacketBuffer Encode(MqttPacket packet)
|
public MqttPacketBuffer Encode(MqttPacket packet)
|
||||||
{
|
{
|
||||||
if (packet == null)
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Leave enough head space for max header size (fixed + 4 variable remaining length = 5 bytes)
|
// Leave enough head space for max header size (fixed + 4 variable remaining length = 5 bytes)
|
||||||
_bufferWriter.Reset(5);
|
_bufferWriter.Reset(5);
|
||||||
@@ -797,10 +794,7 @@ namespace MQTTnet.Formatter.V3
|
|||||||
|
|
||||||
void ValidateConnectPacket(MqttConnectPacket packet)
|
void ValidateConnectPacket(MqttConnectPacket packet)
|
||||||
{
|
{
|
||||||
if (packet == null)
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(packet.ClientId) && !packet.CleanSession)
|
if (string.IsNullOrEmpty(packet.ClientId) && !packet.CleanSession)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,10 +25,7 @@ public sealed class MqttV5PacketEncoder
|
|||||||
|
|
||||||
public MqttPacketBuffer Encode(MqttPacket packet)
|
public MqttPacketBuffer Encode(MqttPacket packet)
|
||||||
{
|
{
|
||||||
if (packet == null)
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Leave enough head space for max header size (fixed + 4 variable remaining length = 5 bytes)
|
// Leave enough head space for max header size (fixed + 4 variable remaining length = 5 bytes)
|
||||||
const int ReservedHeaderSize = 5;
|
const int ReservedHeaderSize = 5;
|
||||||
|
|||||||
@@ -230,10 +230,7 @@ namespace MQTTnet.Formatter.V5
|
|||||||
|
|
||||||
public void WriteTo(MqttBufferWriter target)
|
public void WriteTo(MqttBufferWriter target)
|
||||||
{
|
{
|
||||||
if (target == null)
|
ArgumentNullException.ThrowIfNull(target);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(target));
|
|
||||||
}
|
|
||||||
|
|
||||||
target.WriteVariableByteInteger((uint)_bufferWriter.Length);
|
target.WriteVariableByteInteger((uint)_bufferWriter.Length);
|
||||||
target.Write(_bufferWriter);
|
target.Write(_bufferWriter);
|
||||||
|
|||||||
@@ -124,20 +124,14 @@ public sealed class CrossPlatformSocket : IDisposable
|
|||||||
|
|
||||||
public void Bind(EndPoint localEndPoint)
|
public void Bind(EndPoint localEndPoint)
|
||||||
{
|
{
|
||||||
if (localEndPoint is null)
|
ArgumentNullException.ThrowIfNull(localEndPoint);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(localEndPoint));
|
|
||||||
}
|
|
||||||
|
|
||||||
_socket.Bind(localEndPoint);
|
_socket.Bind(localEndPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)
|
public async Task ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (endPoint is null)
|
ArgumentNullException.ThrowIfNull(endPoint);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(endPoint));
|
|
||||||
}
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace MQTTnet.Implementations
|
|||||||
{
|
{
|
||||||
public IMqttChannelAdapter CreateClientAdapter(MqttClientOptions options, MqttPacketInspector packetInspector, IMqttNetLogger logger)
|
public IMqttChannelAdapter CreateClientAdapter(MqttClientOptions options, MqttPacketInspector packetInspector, IMqttNetLogger logger)
|
||||||
{
|
{
|
||||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
|
|
||||||
IMqttChannel channel;
|
IMqttChannel channel;
|
||||||
switch (options.ChannelOptions)
|
switch (options.ChannelOptions)
|
||||||
|
|||||||
@@ -26,10 +26,7 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public void AddHandler(Func<TEventArgs, Task> handler)
|
public void AddHandler(Func<TEventArgs, Task> handler)
|
||||||
{
|
{
|
||||||
if (handler == null)
|
ArgumentNullException.ThrowIfNull(handler);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(handler));
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_handlers)
|
lock (_handlers)
|
||||||
{
|
{
|
||||||
@@ -42,10 +39,7 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public void AddHandler(Action<TEventArgs> handler)
|
public void AddHandler(Action<TEventArgs> handler)
|
||||||
{
|
{
|
||||||
if (handler == null)
|
ArgumentNullException.ThrowIfNull(handler);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(handler));
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_handlers)
|
lock (_handlers)
|
||||||
{
|
{
|
||||||
@@ -75,10 +69,7 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public void RemoveHandler(Func<TEventArgs, Task> handler)
|
public void RemoveHandler(Func<TEventArgs, Task> handler)
|
||||||
{
|
{
|
||||||
if (handler == null)
|
ArgumentNullException.ThrowIfNull(handler);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(handler));
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_handlers)
|
lock (_handlers)
|
||||||
{
|
{
|
||||||
@@ -91,10 +82,7 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public void RemoveHandler(Action<TEventArgs> handler)
|
public void RemoveHandler(Action<TEventArgs> handler)
|
||||||
{
|
{
|
||||||
if (handler == null)
|
ArgumentNullException.ThrowIfNull(handler);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(handler));
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_handlers)
|
lock (_handlers)
|
||||||
{
|
{
|
||||||
@@ -107,15 +95,8 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public async Task TryInvokeAsync(TEventArgs eventArgs, MqttNetSourceLogger logger)
|
public async Task TryInvokeAsync(TEventArgs eventArgs, MqttNetSourceLogger logger)
|
||||||
{
|
{
|
||||||
if (eventArgs == null)
|
ArgumentNullException.ThrowIfNull(eventArgs);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
throw new ArgumentNullException(nameof(eventArgs));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -116,10 +116,7 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public bool Approve(IDisposable scope)
|
public bool Approve(IDisposable scope)
|
||||||
{
|
{
|
||||||
if (scope == null)
|
ArgumentNullException.ThrowIfNull(scope);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(scope));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_promise.Task.IsCompleted)
|
if (_promise.Task.IsCompleted)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public void Enqueue(TItem item)
|
public void Enqueue(TItem item)
|
||||||
{
|
{
|
||||||
if (item == null) throw new ArgumentNullException(nameof(item));
|
ArgumentNullException.ThrowIfNull(item);
|
||||||
|
|
||||||
lock (_syncRoot)
|
lock (_syncRoot)
|
||||||
{
|
{
|
||||||
@@ -88,7 +88,7 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public void RemoveFirst(Predicate<TItem> match)
|
public void RemoveFirst(Predicate<TItem> match)
|
||||||
{
|
{
|
||||||
if (match == null) throw new ArgumentNullException(nameof(match));
|
ArgumentNullException.ThrowIfNull(match);
|
||||||
|
|
||||||
lock (_syncRoot)
|
lock (_syncRoot)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,10 +124,7 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public void EnqueueItem(MqttPacketBusItem item, MqttPacketBusPartition partition)
|
public void EnqueueItem(MqttPacketBusItem item, MqttPacketBusPartition partition)
|
||||||
{
|
{
|
||||||
if (item == null)
|
ArgumentNullException.ThrowIfNull(item);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_syncRoot)
|
lock (_syncRoot)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ namespace MQTTnet.Internal
|
|||||||
|
|
||||||
public static async Task WaitAsync(this Task task, Task sender, MqttNetSourceLogger logger)
|
public static async Task WaitAsync(this Task task, Task sender, MqttNetSourceLogger logger)
|
||||||
{
|
{
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task == null)
|
if (task == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,10 +41,7 @@ namespace MQTTnet.LowLevelClient
|
|||||||
|
|
||||||
public async Task ConnectAsync(MqttClientOptions options, CancellationToken cancellationToken)
|
public async Task ConnectAsync(MqttClientOptions options, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (options is null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_adapter != null)
|
if (_adapter != null)
|
||||||
{
|
{
|
||||||
@@ -127,10 +124,7 @@ namespace MQTTnet.LowLevelClient
|
|||||||
|
|
||||||
public async Task SendAsync(MqttPacket packet, CancellationToken cancellationToken)
|
public async Task SendAsync(MqttPacket packet, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (packet is null)
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
var adapter = _adapter;
|
var adapter = _adapter;
|
||||||
if (adapter == null)
|
if (adapter == null)
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ public static class MqttApplicationMessageExtensions
|
|||||||
{
|
{
|
||||||
public static string ConvertPayloadToString(this MqttApplicationMessage applicationMessage)
|
public static string ConvertPayloadToString(this MqttApplicationMessage applicationMessage)
|
||||||
{
|
{
|
||||||
if (applicationMessage == null)
|
ArgumentNullException.ThrowIfNull(applicationMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (applicationMessage.Payload.Length == 0)
|
if (applicationMessage.Payload.Length == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ namespace MQTTnet
|
|||||||
{
|
{
|
||||||
public static void ThrowIfNotSupported(MqttApplicationMessage applicationMessage, MqttProtocolVersion protocolVersion)
|
public static void ThrowIfNotSupported(MqttApplicationMessage applicationMessage, MqttProtocolVersion protocolVersion)
|
||||||
{
|
{
|
||||||
if (applicationMessage == null)
|
ArgumentNullException.ThrowIfNull(applicationMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (protocolVersion == MqttProtocolVersion.V500)
|
if (protocolVersion == MqttProtocolVersion.V500)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -183,10 +183,7 @@ public sealed class MqttClient : Disposable, IMqttClient
|
|||||||
|
|
||||||
public async Task DisconnectAsync(MqttClientDisconnectOptions options, CancellationToken cancellationToken = default)
|
public async Task DisconnectAsync(MqttClientDisconnectOptions options, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (options is null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
|
|
||||||
@@ -293,10 +290,7 @@ public sealed class MqttClient : Disposable, IMqttClient
|
|||||||
|
|
||||||
public Task SendExtendedAuthenticationExchangeDataAsync(MqttExtendedAuthenticationExchangeData data, CancellationToken cancellationToken = default)
|
public Task SendExtendedAuthenticationExchangeDataAsync(MqttExtendedAuthenticationExchangeData data, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (data == null)
|
ArgumentNullException.ThrowIfNull(data);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
ThrowIfNotConnected();
|
ThrowIfNotConnected();
|
||||||
@@ -316,10 +310,7 @@ public sealed class MqttClient : Disposable, IMqttClient
|
|||||||
|
|
||||||
public async Task<MqttClientSubscribeResult> SubscribeAsync(MqttClientSubscribeOptions options, CancellationToken cancellationToken = default)
|
public async Task<MqttClientSubscribeResult> SubscribeAsync(MqttClientSubscribeOptions options, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var topicFilter in options.TopicFilters)
|
foreach (var topicFilter in options.TopicFilters)
|
||||||
{
|
{
|
||||||
@@ -355,10 +346,7 @@ public sealed class MqttClient : Disposable, IMqttClient
|
|||||||
|
|
||||||
public async Task<MqttClientUnsubscribeResult> UnsubscribeAsync(MqttClientUnsubscribeOptions options, CancellationToken cancellationToken = default)
|
public async Task<MqttClientUnsubscribeResult> UnsubscribeAsync(MqttClientUnsubscribeOptions options, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var topicFilter in options.TopicFilters)
|
foreach (var topicFilter in options.TopicFilters)
|
||||||
{
|
{
|
||||||
@@ -919,10 +907,7 @@ public sealed class MqttClient : Disposable, IMqttClient
|
|||||||
|
|
||||||
static void ThrowIfOptionsInvalid(MqttClientOptions options)
|
static void ThrowIfOptionsInvalid(MqttClientOptions options)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.ChannelOptions == null)
|
if (options.ChannelOptions == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,10 +23,7 @@ public static class MqttClientExtensions
|
|||||||
List<MqttUserProperty> userProperties = null,
|
List<MqttUserProperty> userProperties = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (client == null)
|
ArgumentNullException.ThrowIfNull(client);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(client));
|
|
||||||
}
|
|
||||||
|
|
||||||
var disconnectOptions = new MqttClientDisconnectOptions
|
var disconnectOptions = new MqttClientDisconnectOptions
|
||||||
{
|
{
|
||||||
@@ -47,15 +44,8 @@ public static class MqttClientExtensions
|
|||||||
bool retain = false,
|
bool retain = false,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (mqttClient == null)
|
ArgumentNullException.ThrowIfNull(mqttClient);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topic);
|
||||||
throw new ArgumentNullException(nameof(mqttClient));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topic == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
var applicationMessage = new MqttApplicationMessageBuilder().WithTopic(topic)
|
var applicationMessage = new MqttApplicationMessageBuilder().WithTopic(topic)
|
||||||
.WithPayload(payload)
|
.WithPayload(payload)
|
||||||
@@ -74,15 +64,8 @@ public static class MqttClientExtensions
|
|||||||
bool retain = false,
|
bool retain = false,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (mqttClient == null)
|
ArgumentNullException.ThrowIfNull(mqttClient);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topic);
|
||||||
throw new ArgumentNullException(nameof(mqttClient));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topic == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
var applicationMessage = new MqttApplicationMessageBuilder().WithTopic(topic)
|
var applicationMessage = new MqttApplicationMessageBuilder().WithTopic(topic)
|
||||||
.WithPayload(payload)
|
.WithPayload(payload)
|
||||||
@@ -118,25 +101,15 @@ public static class MqttClientExtensions
|
|||||||
|
|
||||||
public static Task SendExtendedAuthenticationExchangeDataAsync(this IMqttClient client, MqttExtendedAuthenticationExchangeData data)
|
public static Task SendExtendedAuthenticationExchangeDataAsync(this IMqttClient client, MqttExtendedAuthenticationExchangeData data)
|
||||||
{
|
{
|
||||||
if (client == null)
|
ArgumentNullException.ThrowIfNull(client);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(client));
|
|
||||||
}
|
|
||||||
|
|
||||||
return client.SendExtendedAuthenticationExchangeDataAsync(data, CancellationToken.None);
|
return client.SendExtendedAuthenticationExchangeDataAsync(data, CancellationToken.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<MqttClientSubscribeResult> SubscribeAsync(this IMqttClient mqttClient, MqttTopicFilter topicFilter, CancellationToken cancellationToken = default)
|
public static Task<MqttClientSubscribeResult> SubscribeAsync(this IMqttClient mqttClient, MqttTopicFilter topicFilter, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (mqttClient == null)
|
ArgumentNullException.ThrowIfNull(mqttClient);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topicFilter);
|
||||||
throw new ArgumentNullException(nameof(mqttClient));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topicFilter == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilter));
|
|
||||||
}
|
|
||||||
|
|
||||||
var subscribeOptions = new MqttClientSubscribeOptionsBuilder().WithTopicFilter(topicFilter).Build();
|
var subscribeOptions = new MqttClientSubscribeOptionsBuilder().WithTopicFilter(topicFilter).Build();
|
||||||
|
|
||||||
@@ -149,15 +122,8 @@ public static class MqttClientExtensions
|
|||||||
MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce,
|
MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (mqttClient == null)
|
ArgumentNullException.ThrowIfNull(mqttClient);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topic);
|
||||||
throw new ArgumentNullException(nameof(mqttClient));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topic == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
var subscribeOptions = new MqttClientSubscribeOptionsBuilder().WithTopicFilter(topic, qualityOfServiceLevel).Build();
|
var subscribeOptions = new MqttClientSubscribeOptionsBuilder().WithTopicFilter(topic, qualityOfServiceLevel).Build();
|
||||||
|
|
||||||
@@ -169,10 +135,7 @@ public static class MqttClientExtensions
|
|||||||
MqttClientDisconnectOptionsReason reason = MqttClientDisconnectOptionsReason.NormalDisconnection,
|
MqttClientDisconnectOptionsReason reason = MqttClientDisconnectOptionsReason.NormalDisconnection,
|
||||||
string reasonString = null)
|
string reasonString = null)
|
||||||
{
|
{
|
||||||
if (client == null)
|
ArgumentNullException.ThrowIfNull(client);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(client));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -189,10 +152,7 @@ public static class MqttClientExtensions
|
|||||||
|
|
||||||
public static async Task<bool> TryPingAsync(this IMqttClient client, CancellationToken cancellationToken = default)
|
public static async Task<bool> TryPingAsync(this IMqttClient client, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (client == null)
|
ArgumentNullException.ThrowIfNull(client);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(client));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -209,15 +169,8 @@ public static class MqttClientExtensions
|
|||||||
|
|
||||||
public static Task<MqttClientUnsubscribeResult> UnsubscribeAsync(this IMqttClient mqttClient, string topic, CancellationToken cancellationToken = default)
|
public static Task<MqttClientUnsubscribeResult> UnsubscribeAsync(this IMqttClient mqttClient, string topic, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (mqttClient == null)
|
ArgumentNullException.ThrowIfNull(mqttClient);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(topic);
|
||||||
throw new ArgumentNullException(nameof(mqttClient));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topic == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
var unsubscribeOptions = new MqttClientUnsubscribeOptionsBuilder().WithTopicFilter(topic).Build();
|
var unsubscribeOptions = new MqttClientUnsubscribeOptionsBuilder().WithTopicFilter(topic).Build();
|
||||||
|
|
||||||
|
|||||||
@@ -52,35 +52,22 @@ public sealed class MqttClientFactory
|
|||||||
|
|
||||||
public ILowLevelMqttClient CreateLowLevelMqttClient(IMqttNetLogger logger)
|
public ILowLevelMqttClient CreateLowLevelMqttClient(IMqttNetLogger logger)
|
||||||
{
|
{
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LowLevelMqttClient(_clientAdapterFactory, logger);
|
return new LowLevelMqttClient(_clientAdapterFactory, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILowLevelMqttClient CreateLowLevelMqttClient(IMqttClientAdapterFactory clientAdapterFactory)
|
public ILowLevelMqttClient CreateLowLevelMqttClient(IMqttClientAdapterFactory clientAdapterFactory)
|
||||||
{
|
{
|
||||||
if (clientAdapterFactory == null)
|
ArgumentNullException.ThrowIfNull(clientAdapterFactory);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientAdapterFactory));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LowLevelMqttClient(_clientAdapterFactory, DefaultLogger);
|
return new LowLevelMqttClient(_clientAdapterFactory, DefaultLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILowLevelMqttClient CreateLowLevelMqttClient(IMqttNetLogger logger, IMqttClientAdapterFactory clientAdapterFactory)
|
public ILowLevelMqttClient CreateLowLevelMqttClient(IMqttNetLogger logger, IMqttClientAdapterFactory clientAdapterFactory)
|
||||||
{
|
{
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(clientAdapterFactory);
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clientAdapterFactory == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientAdapterFactory));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LowLevelMqttClient(_clientAdapterFactory, logger);
|
return new LowLevelMqttClient(_clientAdapterFactory, logger);
|
||||||
}
|
}
|
||||||
@@ -92,35 +79,22 @@ public sealed class MqttClientFactory
|
|||||||
|
|
||||||
public IMqttClient CreateMqttClient(IMqttNetLogger logger)
|
public IMqttClient CreateMqttClient(IMqttNetLogger logger)
|
||||||
{
|
{
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttClient(_clientAdapterFactory, logger);
|
return new MqttClient(_clientAdapterFactory, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMqttClient CreateMqttClient(IMqttClientAdapterFactory clientAdapterFactory)
|
public IMqttClient CreateMqttClient(IMqttClientAdapterFactory clientAdapterFactory)
|
||||||
{
|
{
|
||||||
if (clientAdapterFactory == null)
|
ArgumentNullException.ThrowIfNull(clientAdapterFactory);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientAdapterFactory));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttClient(clientAdapterFactory, DefaultLogger);
|
return new MqttClient(clientAdapterFactory, DefaultLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMqttClient CreateMqttClient(IMqttNetLogger logger, IMqttClientAdapterFactory clientAdapterFactory)
|
public IMqttClient CreateMqttClient(IMqttNetLogger logger, IMqttClientAdapterFactory clientAdapterFactory)
|
||||||
{
|
{
|
||||||
if (logger == null)
|
ArgumentNullException.ThrowIfNull(logger);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(clientAdapterFactory);
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clientAdapterFactory == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(clientAdapterFactory));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MqttClient(clientAdapterFactory, logger);
|
return new MqttClient(clientAdapterFactory, logger);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,10 +131,7 @@ public sealed class MqttClientOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientOptionsBuilder WithConnectionUri(Uri uri)
|
public MqttClientOptionsBuilder WithConnectionUri(Uri uri)
|
||||||
{
|
{
|
||||||
if (uri == null)
|
ArgumentNullException.ThrowIfNull(uri);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
var port = uri.IsDefaultPort ? null : (int?)uri.Port;
|
var port = uri.IsDefaultPort ? null : (int?)uri.Port;
|
||||||
switch (uri.Scheme.ToLower())
|
switch (uri.Scheme.ToLower())
|
||||||
@@ -286,10 +283,7 @@ public sealed class MqttClientOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientOptionsBuilder WithTcpServer(string host, int? port = null, AddressFamily addressFamily = AddressFamily.Unspecified)
|
public MqttClientOptionsBuilder WithTcpServer(string host, int? port = null, AddressFamily addressFamily = AddressFamily.Unspecified)
|
||||||
{
|
{
|
||||||
if (host == null)
|
ArgumentNullException.ThrowIfNull(host);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(host));
|
|
||||||
}
|
|
||||||
|
|
||||||
_tcpOptions = new MqttClientTcpOptions();
|
_tcpOptions = new MqttClientTcpOptions();
|
||||||
|
|
||||||
@@ -303,10 +297,7 @@ public sealed class MqttClientOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientOptionsBuilder WithTcpServer(Action<MqttClientTcpOptions> optionsBuilder)
|
public MqttClientOptionsBuilder WithTcpServer(Action<MqttClientTcpOptions> optionsBuilder)
|
||||||
{
|
{
|
||||||
if (optionsBuilder == null)
|
ArgumentNullException.ThrowIfNull(optionsBuilder);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(optionsBuilder));
|
|
||||||
}
|
|
||||||
|
|
||||||
_tcpOptions = new MqttClientTcpOptions();
|
_tcpOptions = new MqttClientTcpOptions();
|
||||||
optionsBuilder.Invoke(_tcpOptions);
|
optionsBuilder.Invoke(_tcpOptions);
|
||||||
@@ -332,10 +323,7 @@ public sealed class MqttClientOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientOptionsBuilder WithTlsOptions(Action<MqttClientTlsOptionsBuilder> configure)
|
public MqttClientOptionsBuilder WithTlsOptions(Action<MqttClientTlsOptionsBuilder> configure)
|
||||||
{
|
{
|
||||||
if (configure == null)
|
ArgumentNullException.ThrowIfNull(configure);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(configure));
|
|
||||||
}
|
|
||||||
|
|
||||||
var builder = new MqttClientTlsOptionsBuilder();
|
var builder = new MqttClientTlsOptionsBuilder();
|
||||||
configure.Invoke(builder);
|
configure.Invoke(builder);
|
||||||
@@ -377,10 +365,7 @@ public sealed class MqttClientOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientOptionsBuilder WithWebSocketServer(Action<MqttClientWebSocketOptionsBuilder> configure)
|
public MqttClientOptionsBuilder WithWebSocketServer(Action<MqttClientWebSocketOptionsBuilder> configure)
|
||||||
{
|
{
|
||||||
if (configure == null)
|
ArgumentNullException.ThrowIfNull(configure);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(configure));
|
|
||||||
}
|
|
||||||
|
|
||||||
var webSocketOptionsBuilder = new MqttClientWebSocketOptionsBuilder();
|
var webSocketOptionsBuilder = new MqttClientWebSocketOptionsBuilder();
|
||||||
configure.Invoke(webSocketOptionsBuilder);
|
configure.Invoke(webSocketOptionsBuilder);
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ public static class MqttClientOptionsValidator
|
|||||||
{
|
{
|
||||||
public static void ThrowIfNotSupported(MqttClientOptions options)
|
public static void ThrowIfNotSupported(MqttClientOptions options)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.ProtocolVersion == MqttProtocolVersion.V500)
|
if (options.ProtocolVersion == MqttProtocolVersion.V500)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,10 +38,7 @@ public sealed class MqttClientTlsOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientTlsOptionsBuilder WithCertificateValidationHandler(Func<MqttClientCertificateValidationEventArgs, bool> certificateValidationHandler)
|
public MqttClientTlsOptionsBuilder WithCertificateValidationHandler(Func<MqttClientCertificateValidationEventArgs, bool> certificateValidationHandler)
|
||||||
{
|
{
|
||||||
if (certificateValidationHandler == null)
|
ArgumentNullException.ThrowIfNull(certificateValidationHandler);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(certificateValidationHandler));
|
|
||||||
}
|
|
||||||
|
|
||||||
_tlsOptions.CertificateValidationHandler = certificateValidationHandler;
|
_tlsOptions.CertificateValidationHandler = certificateValidationHandler;
|
||||||
return this;
|
return this;
|
||||||
@@ -49,10 +46,7 @@ public sealed class MqttClientTlsOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientTlsOptionsBuilder WithCertificateSelectionHandler(Func<MqttClientCertificateSelectionEventArgs, X509Certificate> certificateSelectionHandler)
|
public MqttClientTlsOptionsBuilder WithCertificateSelectionHandler(Func<MqttClientCertificateSelectionEventArgs, X509Certificate> certificateSelectionHandler)
|
||||||
{
|
{
|
||||||
if (certificateSelectionHandler == null)
|
ArgumentNullException.ThrowIfNull(certificateSelectionHandler);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(certificateSelectionHandler));
|
|
||||||
}
|
|
||||||
|
|
||||||
_tlsOptions.CertificateSelectionHandler = certificateSelectionHandler;
|
_tlsOptions.CertificateSelectionHandler = certificateSelectionHandler;
|
||||||
return this;
|
return this;
|
||||||
@@ -60,10 +54,7 @@ public sealed class MqttClientTlsOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientTlsOptionsBuilder WithClientCertificates(IEnumerable<X509Certificate2> certificates)
|
public MqttClientTlsOptionsBuilder WithClientCertificates(IEnumerable<X509Certificate2> certificates)
|
||||||
{
|
{
|
||||||
if (certificates == null)
|
ArgumentNullException.ThrowIfNull(certificates);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(certificates));
|
|
||||||
}
|
|
||||||
|
|
||||||
_tlsOptions.ClientCertificatesProvider = new DefaultMqttCertificatesProvider(certificates);
|
_tlsOptions.ClientCertificatesProvider = new DefaultMqttCertificatesProvider(certificates);
|
||||||
return this;
|
return this;
|
||||||
@@ -71,10 +62,7 @@ public sealed class MqttClientTlsOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientTlsOptionsBuilder WithClientCertificates(X509Certificate2Collection certificates)
|
public MqttClientTlsOptionsBuilder WithClientCertificates(X509Certificate2Collection certificates)
|
||||||
{
|
{
|
||||||
if (certificates == null)
|
ArgumentNullException.ThrowIfNull(certificates);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(certificates));
|
|
||||||
}
|
|
||||||
|
|
||||||
_tlsOptions.ClientCertificatesProvider = new DefaultMqttCertificatesProvider(certificates);
|
_tlsOptions.ClientCertificatesProvider = new DefaultMqttCertificatesProvider(certificates);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -43,10 +43,7 @@ public sealed class MqttClientWebSocketOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientWebSocketOptionsBuilder WithProxyOptions(Action<MqttClientWebSocketProxyOptionsBuilder> configure)
|
public MqttClientWebSocketOptionsBuilder WithProxyOptions(Action<MqttClientWebSocketProxyOptionsBuilder> configure)
|
||||||
{
|
{
|
||||||
if (configure == null)
|
ArgumentNullException.ThrowIfNull(configure);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(configure));
|
|
||||||
}
|
|
||||||
|
|
||||||
var proxyOptionsBuilder = new MqttClientWebSocketProxyOptionsBuilder();
|
var proxyOptionsBuilder = new MqttClientWebSocketProxyOptionsBuilder();
|
||||||
configure.Invoke(proxyOptionsBuilder);
|
configure.Invoke(proxyOptionsBuilder);
|
||||||
|
|||||||
@@ -46,10 +46,7 @@ namespace MQTTnet.PacketDispatcher
|
|||||||
|
|
||||||
public void Dispose(Exception exception)
|
public void Dispose(Exception exception)
|
||||||
{
|
{
|
||||||
if (exception == null)
|
ArgumentNullException.ThrowIfNull(exception);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(exception));
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_waiters)
|
lock (_waiters)
|
||||||
{
|
{
|
||||||
@@ -63,10 +60,7 @@ namespace MQTTnet.PacketDispatcher
|
|||||||
|
|
||||||
public void FailAll(Exception exception)
|
public void FailAll(Exception exception)
|
||||||
{
|
{
|
||||||
if (exception == null)
|
ArgumentNullException.ThrowIfNull(exception);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(exception));
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_waiters)
|
lock (_waiters)
|
||||||
{
|
{
|
||||||
@@ -81,10 +75,7 @@ namespace MQTTnet.PacketDispatcher
|
|||||||
|
|
||||||
public void RemoveAwaitable(IMqttPacketAwaitable awaitable)
|
public void RemoveAwaitable(IMqttPacketAwaitable awaitable)
|
||||||
{
|
{
|
||||||
if (awaitable == null)
|
ArgumentNullException.ThrowIfNull(awaitable);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(awaitable));
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_waiters)
|
lock (_waiters)
|
||||||
{
|
{
|
||||||
@@ -94,10 +85,7 @@ namespace MQTTnet.PacketDispatcher
|
|||||||
|
|
||||||
public bool TryDispatch(MqttPacket packet)
|
public bool TryDispatch(MqttPacket packet)
|
||||||
{
|
{
|
||||||
if (packet == null)
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
ushort identifier = 0;
|
ushort identifier = 0;
|
||||||
if (packet is MqttPacketWithIdentifier packetWithIdentifier)
|
if (packet is MqttPacketWithIdentifier packetWithIdentifier)
|
||||||
|
|||||||
@@ -10,10 +10,7 @@ public static class MqttPacketExtensions
|
|||||||
{
|
{
|
||||||
public static string GetRfcName(this MqttPacket packet)
|
public static string GetRfcName(this MqttPacket packet)
|
||||||
{
|
{
|
||||||
if (packet == null)
|
ArgumentNullException.ThrowIfNull(packet);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (packet)
|
switch (packet)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ namespace MQTTnet.Protocol
|
|||||||
{
|
{
|
||||||
public static void ThrowIfInvalid(MqttApplicationMessage applicationMessage)
|
public static void ThrowIfInvalid(MqttApplicationMessage applicationMessage)
|
||||||
{
|
{
|
||||||
if (applicationMessage == null)
|
ArgumentNullException.ThrowIfNull(applicationMessage);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(applicationMessage));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (applicationMessage.TopicAlias == 0)
|
if (applicationMessage.TopicAlias == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,10 +50,7 @@ public sealed class MqttClientSubscribeOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientSubscribeOptionsBuilder WithTopicFilter(Action<MqttTopicFilterBuilder> topicFilterBuilder)
|
public MqttClientSubscribeOptionsBuilder WithTopicFilter(Action<MqttTopicFilterBuilder> topicFilterBuilder)
|
||||||
{
|
{
|
||||||
if (topicFilterBuilder == null)
|
ArgumentNullException.ThrowIfNull(topicFilterBuilder);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilterBuilder));
|
|
||||||
}
|
|
||||||
|
|
||||||
var internalTopicFilterBuilder = new MqttTopicFilterBuilder();
|
var internalTopicFilterBuilder = new MqttTopicFilterBuilder();
|
||||||
topicFilterBuilder(internalTopicFilterBuilder);
|
topicFilterBuilder(internalTopicFilterBuilder);
|
||||||
@@ -63,20 +60,14 @@ public sealed class MqttClientSubscribeOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientSubscribeOptionsBuilder WithTopicFilter(MqttTopicFilterBuilder topicFilterBuilder)
|
public MqttClientSubscribeOptionsBuilder WithTopicFilter(MqttTopicFilterBuilder topicFilterBuilder)
|
||||||
{
|
{
|
||||||
if (topicFilterBuilder == null)
|
ArgumentNullException.ThrowIfNull(topicFilterBuilder);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilterBuilder));
|
|
||||||
}
|
|
||||||
|
|
||||||
return WithTopicFilter(topicFilterBuilder.Build());
|
return WithTopicFilter(topicFilterBuilder.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MqttClientSubscribeOptionsBuilder WithTopicFilter(MqttTopicFilter topicFilter)
|
public MqttClientSubscribeOptionsBuilder WithTopicFilter(MqttTopicFilter topicFilter)
|
||||||
{
|
{
|
||||||
if (topicFilter == null)
|
ArgumentNullException.ThrowIfNull(topicFilter);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilter));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_subscribeOptions.TopicFilters == null)
|
if (_subscribeOptions.TopicFilters == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ public static class MqttClientSubscribeOptionsValidator
|
|||||||
{
|
{
|
||||||
public static void ThrowIfNotSupported(MqttClientSubscribeOptions options, MqttProtocolVersion protocolVersion)
|
public static void ThrowIfNotSupported(MqttClientSubscribeOptions options, MqttProtocolVersion protocolVersion)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (protocolVersion == MqttProtocolVersion.V500)
|
if (protocolVersion == MqttProtocolVersion.V500)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,15 +16,8 @@ public sealed class MqttClientSubscribeResultFactory
|
|||||||
|
|
||||||
public MqttClientSubscribeResult Create(MqttSubscribePacket subscribePacket, MqttSubAckPacket subAckPacket)
|
public MqttClientSubscribeResult Create(MqttSubscribePacket subscribePacket, MqttSubAckPacket subAckPacket)
|
||||||
{
|
{
|
||||||
if (subscribePacket == null)
|
ArgumentNullException.ThrowIfNull(subscribePacket);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(subAckPacket);
|
||||||
throw new ArgumentNullException(nameof(subscribePacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subAckPacket == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(subAckPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
// MQTTv5.0.0 handling.
|
// MQTTv5.0.0 handling.
|
||||||
if (subAckPacket.ReasonCodes.Any() && subAckPacket.ReasonCodes.Count != subscribePacket.TopicFilters.Count)
|
if (subAckPacket.ReasonCodes.Any() && subAckPacket.ReasonCodes.Count != subscribePacket.TopicFilters.Count)
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ public sealed class MqttClientUnsubscribeOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(string topic)
|
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(string topic)
|
||||||
{
|
{
|
||||||
if (topic is null)
|
ArgumentNullException.ThrowIfNull(topic);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_unsubscribeOptions.TopicFilters is null)
|
if (_unsubscribeOptions.TopicFilters is null)
|
||||||
{
|
{
|
||||||
@@ -36,10 +33,7 @@ public sealed class MqttClientUnsubscribeOptionsBuilder
|
|||||||
|
|
||||||
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(MqttTopicFilter topicFilter)
|
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(MqttTopicFilter topicFilter)
|
||||||
{
|
{
|
||||||
if (topicFilter is null)
|
ArgumentNullException.ThrowIfNull(topicFilter);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(topicFilter));
|
|
||||||
}
|
|
||||||
|
|
||||||
return WithTopicFilter(topicFilter.Topic);
|
return WithTopicFilter(topicFilter.Topic);
|
||||||
}
|
}
|
||||||
@@ -59,10 +53,7 @@ public sealed class MqttClientUnsubscribeOptionsBuilder
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public MqttClientUnsubscribeOptionsBuilder WithUserProperty(MqttUserProperty userProperty)
|
public MqttClientUnsubscribeOptionsBuilder WithUserProperty(MqttUserProperty userProperty)
|
||||||
{
|
{
|
||||||
if (userProperty is null)
|
ArgumentNullException.ThrowIfNull(userProperty);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(userProperty));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_unsubscribeOptions.UserProperties is null)
|
if (_unsubscribeOptions.UserProperties is null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ public static class MqttClientUnsubscribeOptionsValidator
|
|||||||
{
|
{
|
||||||
public static void ThrowIfNotSupported(MqttClientUnsubscribeOptions options, MqttProtocolVersion protocolVersion)
|
public static void ThrowIfNotSupported(MqttClientUnsubscribeOptions options, MqttProtocolVersion protocolVersion)
|
||||||
{
|
{
|
||||||
if (options == null)
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (protocolVersion == MqttProtocolVersion.V500)
|
if (protocolVersion == MqttProtocolVersion.V500)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,15 +15,8 @@ public sealed class MqttClientUnsubscribeResultFactory
|
|||||||
|
|
||||||
public MqttClientUnsubscribeResult Create(MqttUnsubscribePacket unsubscribePacket, MqttUnsubAckPacket unsubAckPacket)
|
public MqttClientUnsubscribeResult Create(MqttUnsubscribePacket unsubscribePacket, MqttUnsubAckPacket unsubAckPacket)
|
||||||
{
|
{
|
||||||
if (unsubscribePacket == null)
|
ArgumentNullException.ThrowIfNull(unsubscribePacket);
|
||||||
{
|
ArgumentNullException.ThrowIfNull(unsubAckPacket);
|
||||||
throw new ArgumentNullException(nameof(unsubscribePacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unsubAckPacket == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(unsubAckPacket));
|
|
||||||
}
|
|
||||||
|
|
||||||
// MQTTv3.1.1 has no reason code at all!
|
// MQTTv3.1.1 has no reason code at all!
|
||||||
if (unsubAckPacket.ReasonCodes != null && unsubAckPacket.ReasonCodes.Count != unsubscribePacket.TopicFilters.Count)
|
if (unsubAckPacket.ReasonCodes != null && unsubAckPacket.ReasonCodes.Count != unsubscribePacket.TopicFilters.Count)
|
||||||
|
|||||||
Reference in New Issue
Block a user