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