diff --git a/Source/MQTTnet/Server/Events/ApplicationMessageNotConsumedEventArgs.cs b/Source/MQTTnet/Server/Events/ApplicationMessageNotConsumedEventArgs.cs
index 28b0e72d7f58963b27736ed4af05f338b91f7092..d81e6bb740beb6d5bc948adf04fbc267768e6df9 100644
--- a/Source/MQTTnet/Server/Events/ApplicationMessageNotConsumedEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/ApplicationMessageNotConsumedEventArgs.cs
@@ -8,14 +8,20 @@ namespace MQTTnet.Server
{
public sealed class ApplicationMessageNotConsumedEventArgs : EventArgs
{
+ public ApplicationMessageNotConsumedEventArgs(MqttApplicationMessage applicationMessage, string senderId)
+ {
+ ApplicationMessage = applicationMessage ?? throw new ArgumentNullException(nameof(applicationMessage));
+ SenderId = senderId;
+ }
+
///
/// Gets the application message which was not consumed by any client.
///
- public MqttApplicationMessage ApplicationMessage { get; internal set; }
+ public MqttApplicationMessage ApplicationMessage { get; }
///
/// Gets the ID of the client which has sent the affected application message.
///
- public string SenderId { get; internal set; }
+ public string SenderId { get; }
}
}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Events/ClientConnectedEventArgs.cs b/Source/MQTTnet/Server/Events/ClientConnectedEventArgs.cs
index 2a8845ee0b4fcbb147c5fea724c824343175e447..390427389cad618418684465c99a98638b262cc6 100644
--- a/Source/MQTTnet/Server/Events/ClientConnectedEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/ClientConnectedEventArgs.cs
@@ -3,31 +3,46 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections;
using MQTTnet.Formatter;
namespace MQTTnet.Server
{
public sealed class ClientConnectedEventArgs : EventArgs
{
+ public ClientConnectedEventArgs(string clientId, string userName, MqttProtocolVersion protocolVersion, string endpoint, IDictionary sessionItems)
+ {
+ ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
+ UserName = userName;
+ ProtocolVersion = protocolVersion;
+ Endpoint = endpoint;
+ SessionItems = sessionItems ?? throw new ArgumentNullException(nameof(sessionItems));
+ }
+
+ ///
+ /// Gets the client identifier of the connected client.
+ /// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
+ ///
+ public string ClientId { get; }
+
///
- /// Gets the client identifier of the connected client.
- /// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
+ /// Gets the endpoint of the connected client.
///
- public string ClientId { get; internal set; }
+ public string Endpoint { get; }
///
- /// Gets the user name of the connected client.
+ /// Gets the protocol version which is used by the connected client.
///
- public string UserName { get; internal set; }
+ public MqttProtocolVersion ProtocolVersion { get; }
///
- /// Gets the protocol version which is used by the connected client.
+ /// Gets or sets a key/value collection that can be used to share data within the scope of this session.
///
- public MqttProtocolVersion ProtocolVersion { get; internal set; }
+ public IDictionary SessionItems { get; }
///
- /// Gets the endpoint of the connected client.
+ /// Gets the user name of the connected client.
///
- public string Endpoint { get; internal set; }
+ public string UserName { get; }
}
-}
+}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Events/ClientDisconnectedEventArgs.cs b/Source/MQTTnet/Server/Events/ClientDisconnectedEventArgs.cs
index aeac413825675d0e932c0205936bf0a5962cab2c..20e2b2dccfd631fe8cdb67b8bb4bd7a93096028b 100644
--- a/Source/MQTTnet/Server/Events/ClientDisconnectedEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/ClientDisconnectedEventArgs.cs
@@ -3,19 +3,33 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections;
namespace MQTTnet.Server
{
public sealed class ClientDisconnectedEventArgs : EventArgs
{
+ public ClientDisconnectedEventArgs(string clientId, MqttClientDisconnectType disconnectType, string endpoint, IDictionary sessionItems)
+ {
+ ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
+ DisconnectType = disconnectType;
+ Endpoint = endpoint;
+ SessionItems = sessionItems ?? throw new ArgumentNullException(nameof(sessionItems));
+ }
+
///
- /// Gets the client identifier.
- /// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
+ /// Gets the client identifier.
+ /// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
///
- public string ClientId { get; internal set; }
+ public string ClientId { get; }
+
+ public MqttClientDisconnectType DisconnectType { get; }
- public MqttClientDisconnectType DisconnectType { get; internal set; }
+ public string Endpoint { get; }
- public string Endpoint { get; internal set; }
+ ///
+ /// Gets or sets a key/value collection that can be used to share data within the scope of this session.
+ ///
+ public IDictionary SessionItems { get; }
}
-}
+}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Events/ClientSubscribedTopicEventArgs.cs b/Source/MQTTnet/Server/Events/ClientSubscribedTopicEventArgs.cs
index 341056738900626b50c17e9a364debcf75a2aeaf..639ad98e368213fd40639df3dce69e60b6e468d0 100644
--- a/Source/MQTTnet/Server/Events/ClientSubscribedTopicEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/ClientSubscribedTopicEventArgs.cs
@@ -3,22 +3,35 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections;
using MQTTnet.Packets;
namespace MQTTnet.Server
{
public sealed class ClientSubscribedTopicEventArgs : EventArgs
{
+ public ClientSubscribedTopicEventArgs(string clientId, MqttTopicFilter topicFilter, IDictionary sessionItems)
+ {
+ ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
+ TopicFilter = topicFilter ?? throw new ArgumentNullException(nameof(topicFilter));
+ SessionItems = sessionItems ?? throw new ArgumentNullException(nameof(sessionItems));
+ }
+
+ ///
+ /// Gets the client identifier.
+ /// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
+ ///
+ public string ClientId { get; }
+
///
- /// Gets the client identifier.
- /// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
+ /// Gets or sets a key/value collection that can be used to share data within the scope of this session.
///
- public string ClientId { get; internal set; }
+ public IDictionary SessionItems { get; }
///
- /// Gets the topic filter.
- /// The topic filter can contain topics and wildcards.
+ /// Gets the topic filter.
+ /// The topic filter can contain topics and wildcards.
///
- public MqttTopicFilter TopicFilter { get; internal set; }
+ public MqttTopicFilter TopicFilter { get; }
}
-}
+}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Events/ClientUnsubscribedTopicEventArgs.cs b/Source/MQTTnet/Server/Events/ClientUnsubscribedTopicEventArgs.cs
index 9a9f73bc1fc402a0443de1e310339a3c3545f418..d521b857e54fb8d3aa0665afaca92dd47a35bafe 100644
--- a/Source/MQTTnet/Server/Events/ClientUnsubscribedTopicEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/ClientUnsubscribedTopicEventArgs.cs
@@ -3,21 +3,34 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections;
namespace MQTTnet.Server
{
public sealed class ClientUnsubscribedTopicEventArgs : EventArgs
{
+ public ClientUnsubscribedTopicEventArgs(string clientId, string topicFilter, IDictionary sessionItems)
+ {
+ ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
+ TopicFilter = topicFilter ?? throw new ArgumentNullException(nameof(topicFilter));
+ SessionItems = sessionItems ?? throw new ArgumentNullException(nameof(sessionItems));
+ }
+
+ ///
+ /// Gets the client identifier.
+ /// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
+ ///
+ public string ClientId { get; }
+
///
- /// Gets the client identifier.
- /// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
+ /// Gets or sets a key/value collection that can be used to share data within the scope of this session.
///
- public string ClientId { get; internal set; }
+ public IDictionary SessionItems { get; }
///
- /// Gets or sets the topic filter.
- /// The topic filter can contain topics and wildcards.
+ /// Gets or sets the topic filter.
+ /// The topic filter can contain topics and wildcards.
///
- public string TopicFilter { get; internal set; }
+ public string TopicFilter { get; }
}
-}
+}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Events/InterceptingPacketEventArgs.cs b/Source/MQTTnet/Server/Events/InterceptingPacketEventArgs.cs
index 3f2661cb321c30c15c1bbc1bc4a00b692bd17022..df62b54a4961eedbbaad8655245f6fd311fd3b71 100644
--- a/Source/MQTTnet/Server/Events/InterceptingPacketEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/InterceptingPacketEventArgs.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections;
using System.Threading;
using MQTTnet.Packets;
@@ -10,30 +11,44 @@ namespace MQTTnet.Server
{
public sealed class InterceptingPacketEventArgs : EventArgs
{
+ public InterceptingPacketEventArgs(CancellationToken cancellationToken, string clientId, string endpoint, MqttPacket packet, IDictionary sessionItems)
+ {
+ CancellationToken = cancellationToken;
+ ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
+ Endpoint = endpoint;
+ Packet = packet ?? throw new ArgumentNullException(nameof(packet));
+ SessionItems = sessionItems;
+ }
+
///
- /// Gets the client ID which has sent the packet or will receive the packet.
+ /// Gets the cancellation token from the connection managing thread.
+ /// Use this in further event processing.
///
- public string ClientId { get; internal set; }
-
+ public CancellationToken CancellationToken { get; }
+
///
- /// Gets the endpoint of the sending or receiving client.
+ /// Gets the client ID which has sent the packet or will receive the packet.
///
- public string Endpoint { get; internal set; }
-
+ public string ClientId { get; }
+
///
- /// Gets or sets the MQTT packet which was received or will be sent.
+ /// Gets the endpoint of the sending or receiving client.
+ ///
+ public string Endpoint { get; }
+
+ ///
+ /// Gets or sets the MQTT packet which was received or will be sent.
///
public MqttPacket Packet { get; set; }
///
- /// Gets or sets whether the packet should be processed or not.
+ /// Gets or sets whether the packet should be processed or not.
///
public bool ProcessPacket { get; set; } = true;
-
+
///
- /// Gets the cancellation token from the connection managing thread.
- /// Use this in further event processing.
+ /// Gets or sets a key/value collection that can be used to share data within the scope of this session.
///
- public CancellationToken CancellationToken { get; internal set; }
+ public IDictionary SessionItems { get; }
}
}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Events/InterceptingPublishEventArgs.cs b/Source/MQTTnet/Server/Events/InterceptingPublishEventArgs.cs
index 09a4d76e5f1534599a6d12b108720de7c750024f..34b12b565c5b51dada94a61cc756a035ab231211 100644
--- a/Source/MQTTnet/Server/Events/InterceptingPublishEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/InterceptingPublishEventArgs.cs
@@ -10,18 +10,26 @@ namespace MQTTnet.Server
{
public sealed class InterceptingPublishEventArgs : EventArgs
{
+ public InterceptingPublishEventArgs(MqttApplicationMessage applicationMessage, CancellationToken cancellationToken, string clientId, IDictionary sessionItems)
+ {
+ ApplicationMessage = applicationMessage ?? throw new ArgumentNullException(nameof(applicationMessage));
+ CancellationToken = cancellationToken;
+ ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
+ SessionItems = sessionItems ?? throw new ArgumentNullException(nameof(sessionItems));
+ }
+
public MqttApplicationMessage ApplicationMessage { get; set; }
///
/// Gets the cancellation token which can indicate that the client connection gets down.
///
- public CancellationToken CancellationToken { get; internal set; }
+ public CancellationToken CancellationToken { get; }
///
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
///
- public string ClientId { get; internal set; }
+ public string ClientId { get; }
public bool CloseConnection { get; set; }
@@ -38,6 +46,6 @@ namespace MQTTnet.Server
///
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
///
- public IDictionary SessionItems { get; internal set; }
+ public IDictionary SessionItems { get; }
}
}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Events/InterceptingSubscriptionEventArgs.cs b/Source/MQTTnet/Server/Events/InterceptingSubscriptionEventArgs.cs
index 8b173f1d11bf794b0d520d3120d96c2268916eaf..d7f787e124f8a79f5608731bbc1d49ab6bc7a9a1 100644
--- a/Source/MQTTnet/Server/Events/InterceptingSubscriptionEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/InterceptingSubscriptionEventArgs.cs
@@ -12,16 +12,28 @@ namespace MQTTnet.Server
{
public sealed class InterceptingSubscriptionEventArgs : EventArgs
{
+ public InterceptingSubscriptionEventArgs(
+ CancellationToken cancellationToken,
+ string clientId,
+ MqttSessionStatus session,
+ MqttTopicFilter topicFilter)
+ {
+ CancellationToken = cancellationToken;
+ ClientId = clientId;
+ Session = session;
+ TopicFilter = topicFilter;
+ }
+
///
/// Gets the cancellation token which can indicate that the client connection gets down.
///
- public CancellationToken CancellationToken { get; internal set; }
+ public CancellationToken CancellationToken { get; }
///
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
///
- public string ClientId { get; internal set; }
+ public string ClientId { get; }
///
/// Gets or sets whether the broker should close the client connection.
@@ -48,12 +60,12 @@ namespace MQTTnet.Server
///
/// Gets the current client session.
///
- public MqttSessionStatus Session { get; internal set; }
+ public MqttSessionStatus Session { get; }
///
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
///
- public IDictionary SessionItems { get; internal set; }
+ public IDictionary SessionItems => Session.Items;
///
/// Gets or sets the topic filter.
diff --git a/Source/MQTTnet/Server/Events/InterceptingUnsubscriptionEventArgs.cs b/Source/MQTTnet/Server/Events/InterceptingUnsubscriptionEventArgs.cs
index 648ccd6fc21b8dbd9612757944c7236684698577..63e8cad5377bb9ffa9e5df766aecd89a13c799c2 100644
--- a/Source/MQTTnet/Server/Events/InterceptingUnsubscriptionEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/InterceptingUnsubscriptionEventArgs.cs
@@ -10,16 +10,24 @@ namespace MQTTnet.Server
{
public sealed class InterceptingUnsubscriptionEventArgs : EventArgs
{
+ public InterceptingUnsubscriptionEventArgs(CancellationToken cancellationToken, string clientId, IDictionary sessionItems, string topic)
+ {
+ CancellationToken = cancellationToken;
+ ClientId = clientId;
+ SessionItems = sessionItems;
+ Topic = topic;
+ }
+
///
/// Gets the cancellation token which can indicate that the client connection gets down.
///
- public CancellationToken CancellationToken { get; internal set; }
+ public CancellationToken CancellationToken { get; }
///
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
///
- public string ClientId { get; internal set; }
+ public string ClientId { get; }
///
/// Gets or sets whether the broker should close the client connection.
@@ -41,7 +49,7 @@ namespace MQTTnet.Server
///
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
///
- public IDictionary SessionItems { get; internal set; }
+ public IDictionary SessionItems { get; }
///
/// Gets or sets the MQTT topic.
@@ -50,6 +58,6 @@ namespace MQTTnet.Server
/// The topic consists of one or more topic levels. Each topic level is separated by a forward slash (topic level
/// separator).
///
- public string Topic { get; internal set; }
+ public string Topic { get; }
}
}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Events/RetainedMessageChangedEventArgs.cs b/Source/MQTTnet/Server/Events/RetainedMessageChangedEventArgs.cs
index 1d436fc3d18f17901c54e57dae5f1305c0ef5bd1..c7beb807696e7a43e56370efcb7c4b3e21410d71 100644
--- a/Source/MQTTnet/Server/Events/RetainedMessageChangedEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/RetainedMessageChangedEventArgs.cs
@@ -9,10 +9,17 @@ namespace MQTTnet.Server
{
public sealed class RetainedMessageChangedEventArgs : EventArgs
{
- public string ClientId { get; internal set; }
-
- public MqttApplicationMessage ChangedRetainedMessage { get; internal set; }
-
- public List StoredRetainedMessages { get; internal set; }
+ public RetainedMessageChangedEventArgs(string clientId, MqttApplicationMessage changedRetainedMessage, List storedRetainedMessages)
+ {
+ ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
+ ChangedRetainedMessage = changedRetainedMessage ?? throw new ArgumentNullException(nameof(changedRetainedMessage));
+ StoredRetainedMessages = storedRetainedMessages ?? throw new ArgumentNullException(nameof(storedRetainedMessages));
+ }
+
+ public MqttApplicationMessage ChangedRetainedMessage { get; }
+
+ public string ClientId { get; }
+
+ public List StoredRetainedMessages { get; }
}
}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Events/SessionDeletedEventArgs.cs b/Source/MQTTnet/Server/Events/SessionDeletedEventArgs.cs
index 844f7c15300f7521c37ab34b737a4a5c23f305b8..3d27036c7d95a181669c2d45e80732c1745d02c6 100644
--- a/Source/MQTTnet/Server/Events/SessionDeletedEventArgs.cs
+++ b/Source/MQTTnet/Server/Events/SessionDeletedEventArgs.cs
@@ -3,14 +3,26 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections;
namespace MQTTnet.Server
{
public sealed class SessionDeletedEventArgs : EventArgs
{
+ public SessionDeletedEventArgs(string id, IDictionary sessionItems)
+ {
+ Id = id ?? throw new ArgumentNullException(nameof(id));
+ SessionItems = sessionItems ?? throw new ArgumentNullException(nameof(sessionItems));
+ }
+
+ ///
+ /// Gets the ID of the session.
+ ///
+ public string Id { get; }
+
///
- /// Gets the ID of the session.
+ /// Gets or sets a key/value collection that can be used to share data within the scope of this session.
///
- public string Id { get; internal set; }
+ public IDictionary SessionItems { get; }
}
}
\ No newline at end of file
diff --git a/Source/MQTTnet/Server/Internal/MqttClient.cs b/Source/MQTTnet/Server/Internal/MqttClient.cs
index 6d2f59e1633358aea077376c7e096bf42e476455..9e97b671a6f4b6340640d2570bf894cac147deea 100644
--- a/Source/MQTTnet/Server/Internal/MqttClient.cs
+++ b/Source/MQTTnet/Server/Internal/MqttClient.cs
@@ -160,15 +160,8 @@ namespace MQTTnet.Server
{
return packet;
}
-
- var interceptingPacketEventArgs = new InterceptingPacketEventArgs
- {
- ClientId = Id,
- Endpoint = Endpoint,
- Packet = packet,
- CancellationToken = cancellationToken
- };
-
+
+ var interceptingPacketEventArgs = new InterceptingPacketEventArgs(cancellationToken, Id, Endpoint, packet, Session.Items);
await _eventContainer.InterceptingOutboundPacketEvent.InvokeAsync(interceptingPacketEventArgs).ConfigureAwait(false);
if (!interceptingPacketEventArgs.ProcessPacket || packet == null)
@@ -200,14 +193,7 @@ namespace MQTTnet.Server
if (_eventContainer.InterceptingInboundPacketEvent.HasHandlers)
{
- var interceptingPacketEventArgs = new InterceptingPacketEventArgs
- {
- ClientId = Id,
- Endpoint = Endpoint,
- Packet = packet,
- CancellationToken = cancellationToken
- };
-
+ var interceptingPacketEventArgs = new InterceptingPacketEventArgs(cancellationToken, Id, Endpoint, packet, Session.Items);
await _eventContainer.InterceptingInboundPacketEvent.InvokeAsync(interceptingPacketEventArgs).ConfigureAwait(false);
packet = interceptingPacketEventArgs.Packet;
processPacket = interceptingPacketEventArgs.ProcessPacket;
@@ -428,16 +414,7 @@ namespace MQTTnet.Server
if (_eventContainer.InterceptingPublishEvent.HasHandlers)
{
- interceptingPublishEventArgs = new InterceptingPublishEventArgs
- {
- ClientId = Id,
- ApplicationMessage = applicationMessage,
- SessionItems = Session.Items,
- ProcessPublish = true,
- CloseConnection = false,
- CancellationToken = cancellationToken
- };
-
+ interceptingPublishEventArgs = new InterceptingPublishEventArgs(applicationMessage, cancellationToken, Id, Session.Items);
if (string.IsNullOrEmpty(interceptingPublishEventArgs.ApplicationMessage.Topic))
{
// This can happen if a topic alias us used but the topic is
diff --git a/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs b/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
index 7d2e47ecadb8b4db36ccb6dafc27e30785bdd727..4787e28c7b1c9cc98b2b8b2dce198ff84ba4e0df 100644
--- a/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
+++ b/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
@@ -109,13 +109,9 @@ namespace MQTTnet.Server
try
{
- if (_eventContainer.SessionDeletedEvent.HasHandlers)
+ if (_eventContainer.SessionDeletedEvent.HasHandlers && session != null)
{
- var eventArgs = new SessionDeletedEventArgs
- {
- Id = session?.Id
- };
-
+ var eventArgs = new SessionDeletedEventArgs(clientId, session.Items);
await _eventContainer.SessionDeletedEvent.TryInvokeAsync(eventArgs, _logger).ConfigureAwait(false);
}
}
@@ -295,13 +291,12 @@ namespace MQTTnet.Server
if (_eventContainer.ClientConnectedEvent.HasHandlers)
{
- var eventArgs = new ClientConnectedEventArgs
- {
- ClientId = connectPacket.ClientId,
- UserName = connectPacket.Username,
- ProtocolVersion = channelAdapter.PacketFormatterAdapter.ProtocolVersion,
- Endpoint = channelAdapter.Endpoint
- };
+ var eventArgs = new ClientConnectedEventArgs(
+ connectPacket.ClientId,
+ connectPacket.Username,
+ channelAdapter.PacketFormatterAdapter.ProtocolVersion,
+ channelAdapter.Endpoint,
+ client.Session.Items);
await _eventContainer.ClientConnectedEvent.InvokeAsync(eventArgs).ConfigureAwait(false);
}
@@ -340,12 +335,8 @@ namespace MQTTnet.Server
if (client.Id != null && !client.IsTakenOver && _eventContainer.ClientDisconnectedEvent.HasHandlers)
{
- var eventArgs = new ClientDisconnectedEventArgs
- {
- ClientId = client.Id,
- DisconnectType = client.IsCleanDisconnect ? MqttClientDisconnectType.Clean : MqttClientDisconnectType.NotClean,
- Endpoint = endpoint
- };
+ var disconnectType = client.IsCleanDisconnect ? MqttClientDisconnectType.Clean : MqttClientDisconnectType.NotClean;
+ var eventArgs = new ClientDisconnectedEventArgs(client.Id, disconnectType, endpoint, client.Session.Items);
await _eventContainer.ClientDisconnectedEvent.InvokeAsync(eventArgs).ConfigureAwait(false);
}
@@ -533,13 +524,7 @@ namespace MQTTnet.Server
if (_eventContainer.ClientConnectedEvent.HasHandlers)
{
- var eventArgs = new ClientDisconnectedEventArgs
- {
- ClientId = existing.Id,
- DisconnectType = MqttClientDisconnectType.Takeover,
- Endpoint = existing.Endpoint
- };
-
+ var eventArgs = new ClientDisconnectedEventArgs(existing.Id, MqttClientDisconnectType.Takeover, existing.Endpoint, existing.Session.Items);
await _eventContainer.ClientDisconnectedEvent.InvokeAsync(eventArgs).ConfigureAwait(false);
}
}
@@ -572,12 +557,7 @@ namespace MQTTnet.Server
return;
}
- var eventArgs = new ApplicationMessageNotConsumedEventArgs
- {
- ApplicationMessage = applicationMessage,
- SenderId = senderId
- };
-
+ var eventArgs = new ApplicationMessageNotConsumedEventArgs(applicationMessage, senderId);
await _eventContainer.ApplicationMessageNotConsumedEvent.InvokeAsync(eventArgs).ConfigureAwait(false);
}
diff --git a/Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs b/Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs
index 9f2f4c7145a3dad988b28501abb8523bc5210891..3a505a40480699e486d250d87b5d94da18ee8bd0 100644
--- a/Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs
+++ b/Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs
@@ -217,12 +217,7 @@ namespace MQTTnet.Server
{
foreach (var finalTopicFilter in finalTopicFilters)
{
- var eventArgs = new ClientSubscribedTopicEventArgs
- {
- ClientId = _session.Id,
- TopicFilter = finalTopicFilter
- };
-
+ var eventArgs = new ClientSubscribedTopicEventArgs(_session.Id, finalTopicFilter, _session.Items);
await _eventContainer.ClientSubscribedTopicEvent.InvokeAsync(eventArgs).ConfigureAwait(false);
}
}
@@ -312,12 +307,7 @@ namespace MQTTnet.Server
{
foreach (var topicFilter in unsubscribePacket.TopicFilters)
{
- var eventArgs = new ClientUnsubscribedTopicEventArgs
- {
- ClientId = _session.Id,
- TopicFilter = topicFilter
- };
-
+ var eventArgs = new ClientUnsubscribedTopicEventArgs(_session.Id, topicFilter, _session.Items);
await _eventContainer.ClientUnsubscribedTopicEvent.InvokeAsync(eventArgs).ConfigureAwait(false);
}
}
@@ -472,14 +462,7 @@ namespace MQTTnet.Server
async Task InterceptSubscribe(MqttTopicFilter topicFilter, CancellationToken cancellationToken)
{
- var eventArgs = new InterceptingSubscriptionEventArgs
- {
- ClientId = _session.Id,
- TopicFilter = topicFilter,
- SessionItems = _session.Items,
- Session = new MqttSessionStatus(_session),
- CancellationToken = cancellationToken
- };
+ var eventArgs = new InterceptingSubscriptionEventArgs(cancellationToken, _session.Id, new MqttSessionStatus(_session), topicFilter);
if (topicFilter.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtMostOnce)
{
@@ -508,13 +491,7 @@ namespace MQTTnet.Server
async Task InterceptUnsubscribe(string topicFilter, MqttSubscription mqttSubscription, CancellationToken cancellationToken)
{
- var clientUnsubscribingTopicEventArgs = new InterceptingUnsubscriptionEventArgs
- {
- ClientId = _session.Id,
- Topic = topicFilter,
- SessionItems = _session.Items,
- CancellationToken = cancellationToken
- };
+ var clientUnsubscribingTopicEventArgs = new InterceptingUnsubscriptionEventArgs(cancellationToken, topicFilter, _session.Items, topicFilter);
if (mqttSubscription == null)
{
diff --git a/Source/MQTTnet/Server/Internal/MqttRetainedMessagesManager.cs b/Source/MQTTnet/Server/Internal/MqttRetainedMessagesManager.cs
index 367373494ef7cc0cbdbc8c81e1ee7f24eba3ce45..acc4672d34177628c6d7c3da7aad9b1075152dcf 100644
--- a/Source/MQTTnet/Server/Internal/MqttRetainedMessagesManager.cs
+++ b/Source/MQTTnet/Server/Internal/MqttRetainedMessagesManager.cs
@@ -105,13 +105,7 @@ namespace MQTTnet.Server
{
using (await _storageAccessLock.WaitAsync(CancellationToken.None).ConfigureAwait(false))
{
- var eventArgs = new RetainedMessageChangedEventArgs
- {
- ClientId = clientId,
- ChangedRetainedMessage = applicationMessage,
- StoredRetainedMessages = messagesForSave
- };
-
+ var eventArgs = new RetainedMessageChangedEventArgs(clientId, applicationMessage, messagesForSave);
await _eventContainer.RetainedMessageChangedEvent.InvokeAsync(eventArgs).ConfigureAwait(false);
}
}