Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
MQTTnet
提交
09385b1b
MQTTnet
项目概览
dotNET Platform
/
MQTTnet
12 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MQTTnet
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
09385b1b
编写于
7月 23, 2022
作者:
C
Christian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass session item to several more event handers.
上级
e3349501
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
206 addition
and
155 deletion
+206
-155
Source/MQTTnet/Server/Events/ApplicationMessageNotConsumedEventArgs.cs
...t/Server/Events/ApplicationMessageNotConsumedEventArgs.cs
+8
-2
Source/MQTTnet/Server/Events/ClientConnectedEventArgs.cs
Source/MQTTnet/Server/Events/ClientConnectedEventArgs.cs
+25
-10
Source/MQTTnet/Server/Events/ClientDisconnectedEventArgs.cs
Source/MQTTnet/Server/Events/ClientDisconnectedEventArgs.cs
+20
-6
Source/MQTTnet/Server/Events/ClientSubscribedTopicEventArgs.cs
...e/MQTTnet/Server/Events/ClientSubscribedTopicEventArgs.cs
+20
-7
Source/MQTTnet/Server/Events/ClientUnsubscribedTopicEventArgs.cs
...MQTTnet/Server/Events/ClientUnsubscribedTopicEventArgs.cs
+20
-7
Source/MQTTnet/Server/Events/InterceptingPacketEventArgs.cs
Source/MQTTnet/Server/Events/InterceptingPacketEventArgs.cs
+27
-12
Source/MQTTnet/Server/Events/InterceptingPublishEventArgs.cs
Source/MQTTnet/Server/Events/InterceptingPublishEventArgs.cs
+11
-3
Source/MQTTnet/Server/Events/InterceptingSubscriptionEventArgs.cs
...QTTnet/Server/Events/InterceptingSubscriptionEventArgs.cs
+16
-4
Source/MQTTnet/Server/Events/InterceptingUnsubscriptionEventArgs.cs
...Tnet/Server/Events/InterceptingUnsubscriptionEventArgs.cs
+12
-4
Source/MQTTnet/Server/Events/RetainedMessageChangedEventArgs.cs
.../MQTTnet/Server/Events/RetainedMessageChangedEventArgs.cs
+12
-5
Source/MQTTnet/Server/Events/SessionDeletedEventArgs.cs
Source/MQTTnet/Server/Events/SessionDeletedEventArgs.cs
+14
-2
Source/MQTTnet/Server/Internal/MqttClient.cs
Source/MQTTnet/Server/Internal/MqttClient.cs
+4
-27
Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
+12
-32
Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs
...MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs
+4
-27
Source/MQTTnet/Server/Internal/MqttRetainedMessagesManager.cs
...ce/MQTTnet/Server/Internal/MqttRetainedMessagesManager.cs
+1
-7
未找到文件。
Source/MQTTnet/Server/Events/ApplicationMessageNotConsumedEventArgs.cs
浏览文件 @
09385b1b
...
@@ -8,14 +8,20 @@ namespace MQTTnet.Server
...
@@ -8,14 +8,20 @@ namespace MQTTnet.Server
{
{
public
sealed
class
ApplicationMessageNotConsumedEventArgs
:
EventArgs
public
sealed
class
ApplicationMessageNotConsumedEventArgs
:
EventArgs
{
{
public
ApplicationMessageNotConsumedEventArgs
(
MqttApplicationMessage
applicationMessage
,
string
senderId
)
{
ApplicationMessage
=
applicationMessage
??
throw
new
ArgumentNullException
(
nameof
(
applicationMessage
));
SenderId
=
senderId
;
}
/// <summary>
/// <summary>
/// Gets the application message which was not consumed by any client.
/// Gets the application message which was not consumed by any client.
/// </summary>
/// </summary>
public
MqttApplicationMessage
ApplicationMessage
{
get
;
internal
set
;
}
public
MqttApplicationMessage
ApplicationMessage
{
get
;
}
/// <summary>
/// <summary>
/// Gets the ID of the client which has sent the affected application message.
/// Gets the ID of the client which has sent the affected application message.
/// </summary>
/// </summary>
public
string
SenderId
{
get
;
internal
set
;
}
public
string
SenderId
{
get
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Events/ClientConnectedEventArgs.cs
浏览文件 @
09385b1b
...
@@ -3,31 +3,46 @@
...
@@ -3,31 +3,46 @@
// See the LICENSE file in the project root for more information.
// See the LICENSE file in the project root for more information.
using
System
;
using
System
;
using
System.Collections
;
using
MQTTnet.Formatter
;
using
MQTTnet.Formatter
;
namespace
MQTTnet.Server
namespace
MQTTnet.Server
{
{
public
sealed
class
ClientConnectedEventArgs
:
EventArgs
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
));
}
/// <summary>
/// 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.
/// </summary>
public
string
ClientId
{
get
;
}
/// <summary>
/// <summary>
/// Gets the client identifier of the connected client.
/// Gets the endpoint of the connected client.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
/// </summary>
public
string
ClientId
{
get
;
internal
s
et
;
}
public
string
Endpoint
{
g
et
;
}
/// <summary>
/// <summary>
///
Gets the user name of
the connected client.
///
Gets the protocol version which is used by
the connected client.
/// </summary>
/// </summary>
public
string
UserName
{
get
;
internal
s
et
;
}
public
MqttProtocolVersion
ProtocolVersion
{
g
et
;
}
/// <summary>
/// <summary>
///
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
.
/// </summary>
/// </summary>
public
MqttProtocolVersion
ProtocolVersion
{
get
;
internal
s
et
;
}
public
IDictionary
SessionItems
{
g
et
;
}
/// <summary>
/// <summary>
///
Gets the endpoint
of the connected client.
///
Gets the user name
of the connected client.
/// </summary>
/// </summary>
public
string
Endpoint
{
get
;
internal
s
et
;
}
public
string
UserName
{
g
et
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Events/ClientDisconnectedEventArgs.cs
浏览文件 @
09385b1b
...
@@ -3,19 +3,33 @@
...
@@ -3,19 +3,33 @@
// See the LICENSE file in the project root for more information.
// See the LICENSE file in the project root for more information.
using
System
;
using
System
;
using
System.Collections
;
namespace
MQTTnet.Server
namespace
MQTTnet.Server
{
{
public
sealed
class
ClientDisconnectedEventArgs
:
EventArgs
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
));
}
/// <summary>
/// <summary>
/// Gets the client identifier.
///
Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
///
Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
/// </summary>
public
string
ClientId
{
get
;
internal
set
;
}
public
string
ClientId
{
get
;
}
public
MqttClientDisconnectType
DisconnectType
{
get
;
}
public
MqttClientDisconnectType
DisconnectType
{
get
;
internal
s
et
;
}
public
string
Endpoint
{
g
et
;
}
public
string
Endpoint
{
get
;
internal
set
;
}
/// <summary>
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// </summary>
public
IDictionary
SessionItems
{
get
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Events/ClientSubscribedTopicEventArgs.cs
浏览文件 @
09385b1b
...
@@ -3,22 +3,35 @@
...
@@ -3,22 +3,35 @@
// See the LICENSE file in the project root for more information.
// See the LICENSE file in the project root for more information.
using
System
;
using
System
;
using
System.Collections
;
using
MQTTnet.Packets
;
using
MQTTnet.Packets
;
namespace
MQTTnet.Server
namespace
MQTTnet.Server
{
{
public
sealed
class
ClientSubscribedTopicEventArgs
:
EventArgs
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
));
}
/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public
string
ClientId
{
get
;
}
/// <summary>
/// <summary>
/// Gets the client identifier.
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
/// </summary>
public
string
ClientId
{
get
;
internal
s
et
;
}
public
IDictionary
SessionItems
{
g
et
;
}
/// <summary>
/// <summary>
/// Gets the topic filter.
///
Gets the topic filter.
/// The topic filter can contain topics and wildcards.
///
The topic filter can contain topics and wildcards.
/// </summary>
/// </summary>
public
MqttTopicFilter
TopicFilter
{
get
;
internal
set
;
}
public
MqttTopicFilter
TopicFilter
{
get
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Events/ClientUnsubscribedTopicEventArgs.cs
浏览文件 @
09385b1b
...
@@ -3,21 +3,34 @@
...
@@ -3,21 +3,34 @@
// See the LICENSE file in the project root for more information.
// See the LICENSE file in the project root for more information.
using
System
;
using
System
;
using
System.Collections
;
namespace
MQTTnet.Server
namespace
MQTTnet.Server
{
{
public
sealed
class
ClientUnsubscribedTopicEventArgs
:
EventArgs
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
));
}
/// <summary>
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
public
string
ClientId
{
get
;
}
/// <summary>
/// <summary>
/// Gets the client identifier.
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
/// </summary>
public
string
ClientId
{
get
;
internal
s
et
;
}
public
IDictionary
SessionItems
{
g
et
;
}
/// <summary>
/// <summary>
/// Gets or sets the topic filter.
///
Gets or sets the topic filter.
/// The topic filter can contain topics and wildcards.
///
The topic filter can contain topics and wildcards.
/// </summary>
/// </summary>
public
string
TopicFilter
{
get
;
internal
set
;
}
public
string
TopicFilter
{
get
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Events/InterceptingPacketEventArgs.cs
浏览文件 @
09385b1b
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
// See the LICENSE file in the project root for more information.
using
System
;
using
System
;
using
System.Collections
;
using
System.Threading
;
using
System.Threading
;
using
MQTTnet.Packets
;
using
MQTTnet.Packets
;
...
@@ -10,30 +11,44 @@ namespace MQTTnet.Server
...
@@ -10,30 +11,44 @@ namespace MQTTnet.Server
{
{
public
sealed
class
InterceptingPacketEventArgs
:
EventArgs
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
;
}
/// <summary>
/// <summary>
/// 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.
/// </summary>
/// </summary>
public
string
ClientId
{
get
;
internal
s
et
;
}
public
CancellationToken
CancellationToken
{
g
et
;
}
/// <summary>
/// <summary>
///
Gets the endpoint of the sending or receiving clien
t.
///
Gets the client ID which has sent the packet or will receive the packe
t.
/// </summary>
/// </summary>
public
string
Endpoint
{
get
;
internal
s
et
;
}
public
string
ClientId
{
g
et
;
}
/// <summary>
/// <summary>
/// Gets or sets the MQTT packet which was received or will be sent.
/// Gets the endpoint of the sending or receiving client.
/// </summary>
public
string
Endpoint
{
get
;
}
/// <summary>
/// Gets or sets the MQTT packet which was received or will be sent.
/// </summary>
/// </summary>
public
MqttPacket
Packet
{
get
;
set
;
}
public
MqttPacket
Packet
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Gets or sets whether the packet should be processed or not.
///
Gets or sets whether the packet should be processed or not.
/// </summary>
/// </summary>
public
bool
ProcessPacket
{
get
;
set
;
}
=
true
;
public
bool
ProcessPacket
{
get
;
set
;
}
=
true
;
/// <summary>
/// <summary>
/// Gets the cancellation token from the connection managing thread.
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// Use this in further event processing.
/// </summary>
/// </summary>
public
CancellationToken
CancellationToken
{
get
;
internal
s
et
;
}
public
IDictionary
SessionItems
{
g
et
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Events/InterceptingPublishEventArgs.cs
浏览文件 @
09385b1b
...
@@ -10,18 +10,26 @@ namespace MQTTnet.Server
...
@@ -10,18 +10,26 @@ namespace MQTTnet.Server
{
{
public
sealed
class
InterceptingPublishEventArgs
:
EventArgs
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
;
}
public
MqttApplicationMessage
ApplicationMessage
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Gets the cancellation token which can indicate that the client connection gets down.
/// Gets the cancellation token which can indicate that the client connection gets down.
/// </summary>
/// </summary>
public
CancellationToken
CancellationToken
{
get
;
internal
set
;
}
public
CancellationToken
CancellationToken
{
get
;
}
/// <summary>
/// <summary>
/// Gets the client identifier.
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
/// </summary>
public
string
ClientId
{
get
;
internal
set
;
}
public
string
ClientId
{
get
;
}
public
bool
CloseConnection
{
get
;
set
;
}
public
bool
CloseConnection
{
get
;
set
;
}
...
@@ -38,6 +46,6 @@ namespace MQTTnet.Server
...
@@ -38,6 +46,6 @@ namespace MQTTnet.Server
/// <summary>
/// <summary>
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// </summary>
/// </summary>
public
IDictionary
SessionItems
{
get
;
internal
set
;
}
public
IDictionary
SessionItems
{
get
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Events/InterceptingSubscriptionEventArgs.cs
浏览文件 @
09385b1b
...
@@ -12,16 +12,28 @@ namespace MQTTnet.Server
...
@@ -12,16 +12,28 @@ namespace MQTTnet.Server
{
{
public
sealed
class
InterceptingSubscriptionEventArgs
:
EventArgs
public
sealed
class
InterceptingSubscriptionEventArgs
:
EventArgs
{
{
public
InterceptingSubscriptionEventArgs
(
CancellationToken
cancellationToken
,
string
clientId
,
MqttSessionStatus
session
,
MqttTopicFilter
topicFilter
)
{
CancellationToken
=
cancellationToken
;
ClientId
=
clientId
;
Session
=
session
;
TopicFilter
=
topicFilter
;
}
/// <summary>
/// <summary>
/// Gets the cancellation token which can indicate that the client connection gets down.
/// Gets the cancellation token which can indicate that the client connection gets down.
/// </summary>
/// </summary>
public
CancellationToken
CancellationToken
{
get
;
internal
set
;
}
public
CancellationToken
CancellationToken
{
get
;
}
/// <summary>
/// <summary>
/// Gets the client identifier.
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
/// </summary>
public
string
ClientId
{
get
;
internal
set
;
}
public
string
ClientId
{
get
;
}
/// <summary>
/// <summary>
/// Gets or sets whether the broker should close the client connection.
/// Gets or sets whether the broker should close the client connection.
...
@@ -48,12 +60,12 @@ namespace MQTTnet.Server
...
@@ -48,12 +60,12 @@ namespace MQTTnet.Server
/// <summary>
/// <summary>
/// Gets the current client session.
/// Gets the current client session.
/// </summary>
/// </summary>
public
MqttSessionStatus
Session
{
get
;
internal
set
;
}
public
MqttSessionStatus
Session
{
get
;
}
/// <summary>
/// <summary>
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// </summary>
/// </summary>
public
IDictionary
SessionItems
{
get
;
internal
set
;
}
public
IDictionary
SessionItems
=>
Session
.
Items
;
/// <summary>
/// <summary>
/// Gets or sets the topic filter.
/// Gets or sets the topic filter.
...
...
Source/MQTTnet/Server/Events/InterceptingUnsubscriptionEventArgs.cs
浏览文件 @
09385b1b
...
@@ -10,16 +10,24 @@ namespace MQTTnet.Server
...
@@ -10,16 +10,24 @@ namespace MQTTnet.Server
{
{
public
sealed
class
InterceptingUnsubscriptionEventArgs
:
EventArgs
public
sealed
class
InterceptingUnsubscriptionEventArgs
:
EventArgs
{
{
public
InterceptingUnsubscriptionEventArgs
(
CancellationToken
cancellationToken
,
string
clientId
,
IDictionary
sessionItems
,
string
topic
)
{
CancellationToken
=
cancellationToken
;
ClientId
=
clientId
;
SessionItems
=
sessionItems
;
Topic
=
topic
;
}
/// <summary>
/// <summary>
/// Gets the cancellation token which can indicate that the client connection gets down.
/// Gets the cancellation token which can indicate that the client connection gets down.
/// </summary>
/// </summary>
public
CancellationToken
CancellationToken
{
get
;
internal
set
;
}
public
CancellationToken
CancellationToken
{
get
;
}
/// <summary>
/// <summary>
/// Gets the client identifier.
/// Gets the client identifier.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues.
/// </summary>
/// </summary>
public
string
ClientId
{
get
;
internal
set
;
}
public
string
ClientId
{
get
;
}
/// <summary>
/// <summary>
/// Gets or sets whether the broker should close the client connection.
/// Gets or sets whether the broker should close the client connection.
...
@@ -41,7 +49,7 @@ namespace MQTTnet.Server
...
@@ -41,7 +49,7 @@ namespace MQTTnet.Server
/// <summary>
/// <summary>
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// Gets or sets a key/value collection that can be used to share data within the scope of this session.
/// </summary>
/// </summary>
public
IDictionary
SessionItems
{
get
;
internal
set
;
}
public
IDictionary
SessionItems
{
get
;
}
/// <summary>
/// <summary>
/// Gets or sets the MQTT topic.
/// Gets or sets the MQTT topic.
...
@@ -50,6 +58,6 @@ namespace MQTTnet.Server
...
@@ -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
/// The topic consists of one or more topic levels. Each topic level is separated by a forward slash (topic level
/// separator).
/// separator).
/// </summary>
/// </summary>
public
string
Topic
{
get
;
internal
set
;
}
public
string
Topic
{
get
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Events/RetainedMessageChangedEventArgs.cs
浏览文件 @
09385b1b
...
@@ -9,10 +9,17 @@ namespace MQTTnet.Server
...
@@ -9,10 +9,17 @@ namespace MQTTnet.Server
{
{
public
sealed
class
RetainedMessageChangedEventArgs
:
EventArgs
public
sealed
class
RetainedMessageChangedEventArgs
:
EventArgs
{
{
public
string
ClientId
{
get
;
internal
set
;
}
public
RetainedMessageChangedEventArgs
(
string
clientId
,
MqttApplicationMessage
changedRetainedMessage
,
List
<
MqttApplicationMessage
>
storedRetainedMessages
)
{
public
MqttApplicationMessage
ChangedRetainedMessage
{
get
;
internal
set
;
}
ClientId
=
clientId
??
throw
new
ArgumentNullException
(
nameof
(
clientId
));
ChangedRetainedMessage
=
changedRetainedMessage
??
throw
new
ArgumentNullException
(
nameof
(
changedRetainedMessage
));
public
List
<
MqttApplicationMessage
>
StoredRetainedMessages
{
get
;
internal
set
;
}
StoredRetainedMessages
=
storedRetainedMessages
??
throw
new
ArgumentNullException
(
nameof
(
storedRetainedMessages
));
}
public
MqttApplicationMessage
ChangedRetainedMessage
{
get
;
}
public
string
ClientId
{
get
;
}
public
List
<
MqttApplicationMessage
>
StoredRetainedMessages
{
get
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Events/SessionDeletedEventArgs.cs
浏览文件 @
09385b1b
...
@@ -3,14 +3,26 @@
...
@@ -3,14 +3,26 @@
// See the LICENSE file in the project root for more information.
// See the LICENSE file in the project root for more information.
using
System
;
using
System
;
using
System.Collections
;
namespace
MQTTnet.Server
namespace
MQTTnet.Server
{
{
public
sealed
class
SessionDeletedEventArgs
:
EventArgs
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
));
}
/// <summary>
/// Gets the ID of the session.
/// </summary>
public
string
Id
{
get
;
}
/// <summary>
/// <summary>
///
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.
/// </summary>
/// </summary>
public
string
Id
{
get
;
internal
s
et
;
}
public
IDictionary
SessionItems
{
g
et
;
}
}
}
}
}
\ No newline at end of file
Source/MQTTnet/Server/Internal/MqttClient.cs
浏览文件 @
09385b1b
...
@@ -160,15 +160,8 @@ namespace MQTTnet.Server
...
@@ -160,15 +160,8 @@ namespace MQTTnet.Server
{
{
return
packet
;
return
packet
;
}
}
var
interceptingPacketEventArgs
=
new
InterceptingPacketEventArgs
var
interceptingPacketEventArgs
=
new
InterceptingPacketEventArgs
(
cancellationToken
,
Id
,
Endpoint
,
packet
,
Session
.
Items
);
{
ClientId
=
Id
,
Endpoint
=
Endpoint
,
Packet
=
packet
,
CancellationToken
=
cancellationToken
};
await
_eventContainer
.
InterceptingOutboundPacketEvent
.
InvokeAsync
(
interceptingPacketEventArgs
).
ConfigureAwait
(
false
);
await
_eventContainer
.
InterceptingOutboundPacketEvent
.
InvokeAsync
(
interceptingPacketEventArgs
).
ConfigureAwait
(
false
);
if
(!
interceptingPacketEventArgs
.
ProcessPacket
||
packet
==
null
)
if
(!
interceptingPacketEventArgs
.
ProcessPacket
||
packet
==
null
)
...
@@ -200,14 +193,7 @@ namespace MQTTnet.Server
...
@@ -200,14 +193,7 @@ namespace MQTTnet.Server
if
(
_eventContainer
.
InterceptingInboundPacketEvent
.
HasHandlers
)
if
(
_eventContainer
.
InterceptingInboundPacketEvent
.
HasHandlers
)
{
{
var
interceptingPacketEventArgs
=
new
InterceptingPacketEventArgs
var
interceptingPacketEventArgs
=
new
InterceptingPacketEventArgs
(
cancellationToken
,
Id
,
Endpoint
,
packet
,
Session
.
Items
);
{
ClientId
=
Id
,
Endpoint
=
Endpoint
,
Packet
=
packet
,
CancellationToken
=
cancellationToken
};
await
_eventContainer
.
InterceptingInboundPacketEvent
.
InvokeAsync
(
interceptingPacketEventArgs
).
ConfigureAwait
(
false
);
await
_eventContainer
.
InterceptingInboundPacketEvent
.
InvokeAsync
(
interceptingPacketEventArgs
).
ConfigureAwait
(
false
);
packet
=
interceptingPacketEventArgs
.
Packet
;
packet
=
interceptingPacketEventArgs
.
Packet
;
processPacket
=
interceptingPacketEventArgs
.
ProcessPacket
;
processPacket
=
interceptingPacketEventArgs
.
ProcessPacket
;
...
@@ -428,16 +414,7 @@ namespace MQTTnet.Server
...
@@ -428,16 +414,7 @@ namespace MQTTnet.Server
if
(
_eventContainer
.
InterceptingPublishEvent
.
HasHandlers
)
if
(
_eventContainer
.
InterceptingPublishEvent
.
HasHandlers
)
{
{
interceptingPublishEventArgs
=
new
InterceptingPublishEventArgs
interceptingPublishEventArgs
=
new
InterceptingPublishEventArgs
(
applicationMessage
,
cancellationToken
,
Id
,
Session
.
Items
);
{
ClientId
=
Id
,
ApplicationMessage
=
applicationMessage
,
SessionItems
=
Session
.
Items
,
ProcessPublish
=
true
,
CloseConnection
=
false
,
CancellationToken
=
cancellationToken
};
if
(
string
.
IsNullOrEmpty
(
interceptingPublishEventArgs
.
ApplicationMessage
.
Topic
))
if
(
string
.
IsNullOrEmpty
(
interceptingPublishEventArgs
.
ApplicationMessage
.
Topic
))
{
{
// This can happen if a topic alias us used but the topic is
// This can happen if a topic alias us used but the topic is
...
...
Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
浏览文件 @
09385b1b
...
@@ -109,13 +109,9 @@ namespace MQTTnet.Server
...
@@ -109,13 +109,9 @@ namespace MQTTnet.Server
try
try
{
{
if
(
_eventContainer
.
SessionDeletedEvent
.
HasHandlers
)
if
(
_eventContainer
.
SessionDeletedEvent
.
HasHandlers
&&
session
!=
null
)
{
{
var
eventArgs
=
new
SessionDeletedEventArgs
var
eventArgs
=
new
SessionDeletedEventArgs
(
clientId
,
session
.
Items
);
{
Id
=
session
?.
Id
};
await
_eventContainer
.
SessionDeletedEvent
.
TryInvokeAsync
(
eventArgs
,
_logger
).
ConfigureAwait
(
false
);
await
_eventContainer
.
SessionDeletedEvent
.
TryInvokeAsync
(
eventArgs
,
_logger
).
ConfigureAwait
(
false
);
}
}
}
}
...
@@ -295,13 +291,12 @@ namespace MQTTnet.Server
...
@@ -295,13 +291,12 @@ namespace MQTTnet.Server
if
(
_eventContainer
.
ClientConnectedEvent
.
HasHandlers
)
if
(
_eventContainer
.
ClientConnectedEvent
.
HasHandlers
)
{
{
var
eventArgs
=
new
ClientConnectedEventArgs
var
eventArgs
=
new
ClientConnectedEventArgs
(
{
connectPacket
.
ClientId
,
ClientId
=
connectPacket
.
ClientId
,
connectPacket
.
Username
,
UserName
=
connectPacket
.
Username
,
channelAdapter
.
PacketFormatterAdapter
.
ProtocolVersion
,
ProtocolVersion
=
channelAdapter
.
PacketFormatterAdapter
.
ProtocolVersion
,
channelAdapter
.
Endpoint
,
Endpoint
=
channelAdapter
.
Endpoint
client
.
Session
.
Items
);
};
await
_eventContainer
.
ClientConnectedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
await
_eventContainer
.
ClientConnectedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
}
}
...
@@ -340,12 +335,8 @@ namespace MQTTnet.Server
...
@@ -340,12 +335,8 @@ namespace MQTTnet.Server
if
(
client
.
Id
!=
null
&&
!
client
.
IsTakenOver
&&
_eventContainer
.
ClientDisconnectedEvent
.
HasHandlers
)
if
(
client
.
Id
!=
null
&&
!
client
.
IsTakenOver
&&
_eventContainer
.
ClientDisconnectedEvent
.
HasHandlers
)
{
{
var
eventArgs
=
new
ClientDisconnectedEventArgs
var
disconnectType
=
client
.
IsCleanDisconnect
?
MqttClientDisconnectType
.
Clean
:
MqttClientDisconnectType
.
NotClean
;
{
var
eventArgs
=
new
ClientDisconnectedEventArgs
(
client
.
Id
,
disconnectType
,
endpoint
,
client
.
Session
.
Items
);
ClientId
=
client
.
Id
,
DisconnectType
=
client
.
IsCleanDisconnect
?
MqttClientDisconnectType
.
Clean
:
MqttClientDisconnectType
.
NotClean
,
Endpoint
=
endpoint
};
await
_eventContainer
.
ClientDisconnectedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
await
_eventContainer
.
ClientDisconnectedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
}
}
...
@@ -533,13 +524,7 @@ namespace MQTTnet.Server
...
@@ -533,13 +524,7 @@ namespace MQTTnet.Server
if
(
_eventContainer
.
ClientConnectedEvent
.
HasHandlers
)
if
(
_eventContainer
.
ClientConnectedEvent
.
HasHandlers
)
{
{
var
eventArgs
=
new
ClientDisconnectedEventArgs
var
eventArgs
=
new
ClientDisconnectedEventArgs
(
existing
.
Id
,
MqttClientDisconnectType
.
Takeover
,
existing
.
Endpoint
,
existing
.
Session
.
Items
);
{
ClientId
=
existing
.
Id
,
DisconnectType
=
MqttClientDisconnectType
.
Takeover
,
Endpoint
=
existing
.
Endpoint
};
await
_eventContainer
.
ClientDisconnectedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
await
_eventContainer
.
ClientDisconnectedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
}
}
}
}
...
@@ -572,12 +557,7 @@ namespace MQTTnet.Server
...
@@ -572,12 +557,7 @@ namespace MQTTnet.Server
return
;
return
;
}
}
var
eventArgs
=
new
ApplicationMessageNotConsumedEventArgs
var
eventArgs
=
new
ApplicationMessageNotConsumedEventArgs
(
applicationMessage
,
senderId
);
{
ApplicationMessage
=
applicationMessage
,
SenderId
=
senderId
};
await
_eventContainer
.
ApplicationMessageNotConsumedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
await
_eventContainer
.
ApplicationMessageNotConsumedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
}
}
...
...
Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs
浏览文件 @
09385b1b
...
@@ -217,12 +217,7 @@ namespace MQTTnet.Server
...
@@ -217,12 +217,7 @@ namespace MQTTnet.Server
{
{
foreach
(
var
finalTopicFilter
in
finalTopicFilters
)
foreach
(
var
finalTopicFilter
in
finalTopicFilters
)
{
{
var
eventArgs
=
new
ClientSubscribedTopicEventArgs
var
eventArgs
=
new
ClientSubscribedTopicEventArgs
(
_session
.
Id
,
finalTopicFilter
,
_session
.
Items
);
{
ClientId
=
_session
.
Id
,
TopicFilter
=
finalTopicFilter
};
await
_eventContainer
.
ClientSubscribedTopicEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
await
_eventContainer
.
ClientSubscribedTopicEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
}
}
}
}
...
@@ -312,12 +307,7 @@ namespace MQTTnet.Server
...
@@ -312,12 +307,7 @@ namespace MQTTnet.Server
{
{
foreach
(
var
topicFilter
in
unsubscribePacket
.
TopicFilters
)
foreach
(
var
topicFilter
in
unsubscribePacket
.
TopicFilters
)
{
{
var
eventArgs
=
new
ClientUnsubscribedTopicEventArgs
var
eventArgs
=
new
ClientUnsubscribedTopicEventArgs
(
_session
.
Id
,
topicFilter
,
_session
.
Items
);
{
ClientId
=
_session
.
Id
,
TopicFilter
=
topicFilter
};
await
_eventContainer
.
ClientUnsubscribedTopicEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
await
_eventContainer
.
ClientUnsubscribedTopicEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
}
}
}
}
...
@@ -472,14 +462,7 @@ namespace MQTTnet.Server
...
@@ -472,14 +462,7 @@ namespace MQTTnet.Server
async
Task
<
InterceptingSubscriptionEventArgs
>
InterceptSubscribe
(
MqttTopicFilter
topicFilter
,
CancellationToken
cancellationToken
)
async
Task
<
InterceptingSubscriptionEventArgs
>
InterceptSubscribe
(
MqttTopicFilter
topicFilter
,
CancellationToken
cancellationToken
)
{
{
var
eventArgs
=
new
InterceptingSubscriptionEventArgs
var
eventArgs
=
new
InterceptingSubscriptionEventArgs
(
cancellationToken
,
_session
.
Id
,
new
MqttSessionStatus
(
_session
),
topicFilter
);
{
ClientId
=
_session
.
Id
,
TopicFilter
=
topicFilter
,
SessionItems
=
_session
.
Items
,
Session
=
new
MqttSessionStatus
(
_session
),
CancellationToken
=
cancellationToken
};
if
(
topicFilter
.
QualityOfServiceLevel
==
MqttQualityOfServiceLevel
.
AtMostOnce
)
if
(
topicFilter
.
QualityOfServiceLevel
==
MqttQualityOfServiceLevel
.
AtMostOnce
)
{
{
...
@@ -508,13 +491,7 @@ namespace MQTTnet.Server
...
@@ -508,13 +491,7 @@ namespace MQTTnet.Server
async
Task
<
InterceptingUnsubscriptionEventArgs
>
InterceptUnsubscribe
(
string
topicFilter
,
MqttSubscription
mqttSubscription
,
CancellationToken
cancellationToken
)
async
Task
<
InterceptingUnsubscriptionEventArgs
>
InterceptUnsubscribe
(
string
topicFilter
,
MqttSubscription
mqttSubscription
,
CancellationToken
cancellationToken
)
{
{
var
clientUnsubscribingTopicEventArgs
=
new
InterceptingUnsubscriptionEventArgs
var
clientUnsubscribingTopicEventArgs
=
new
InterceptingUnsubscriptionEventArgs
(
cancellationToken
,
topicFilter
,
_session
.
Items
,
topicFilter
);
{
ClientId
=
_session
.
Id
,
Topic
=
topicFilter
,
SessionItems
=
_session
.
Items
,
CancellationToken
=
cancellationToken
};
if
(
mqttSubscription
==
null
)
if
(
mqttSubscription
==
null
)
{
{
...
...
Source/MQTTnet/Server/Internal/MqttRetainedMessagesManager.cs
浏览文件 @
09385b1b
...
@@ -105,13 +105,7 @@ namespace MQTTnet.Server
...
@@ -105,13 +105,7 @@ namespace MQTTnet.Server
{
{
using
(
await
_storageAccessLock
.
WaitAsync
(
CancellationToken
.
None
).
ConfigureAwait
(
false
))
using
(
await
_storageAccessLock
.
WaitAsync
(
CancellationToken
.
None
).
ConfigureAwait
(
false
))
{
{
var
eventArgs
=
new
RetainedMessageChangedEventArgs
var
eventArgs
=
new
RetainedMessageChangedEventArgs
(
clientId
,
applicationMessage
,
messagesForSave
);
{
ClientId
=
clientId
,
ChangedRetainedMessage
=
applicationMessage
,
StoredRetainedMessages
=
messagesForSave
};
await
_eventContainer
.
RetainedMessageChangedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
await
_eventContainer
.
RetainedMessageChangedEvent
.
InvokeAsync
(
eventArgs
).
ConfigureAwait
(
false
);
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录