From 5656619a3bc9feb9ea89465db34b1d42d9254062 Mon Sep 17 00:00:00 2001
From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com>
Date: Sat, 23 Aug 2025 14:48:19 +0800
Subject: [PATCH] =?UTF-8?q?1.=20Serein.Proto.WebSocket=E9=A1=B9=E7=9B=AE?=
=?UTF-8?q?=E4=B8=AD=EF=BC=8Cws=E6=96=B9=E6=B3=95=E5=85=A5=E5=8F=82?=
=?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E5=AF=B9=E4=BA=8E=E4=BD=BF=E7=94=A8?=
=?UTF-8?q?=E6=B5=81=E7=A8=8B=E4=B8=8A=E4=B8=8B=E6=96=87=E4=BD=9C=E4=B8=BA?=
=?UTF-8?q?=E5=8F=82=E6=95=B0=E7=9A=84=E8=AF=86=E5=88=AB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Library/Utils/FlowTrigger/ChannelFlowTrigger.cs | 11 +----------
.../{MessageIdGenerator.cs => IdGeneratorHelper.cs} | 2 +-
.../Handle/MethodInvokeConfiguration.cs | 5 +++++
.../Handle/WebSocketHandleModule.cs | 7 +++++++
Serein.Proto.WebSocket/Serein.Proto.WebSocket.csproj | 4 ----
Serein.Proto.WebSocket/SereinWebSocketService.cs | 1 +
Workbench/Serein.WorkBench.csproj | 1 +
7 files changed, 16 insertions(+), 15 deletions(-)
rename Library/Utils/{MessageIdGenerator.cs => IdGeneratorHelper.cs} (97%)
diff --git a/Library/Utils/FlowTrigger/ChannelFlowTrigger.cs b/Library/Utils/FlowTrigger/ChannelFlowTrigger.cs
index a3a3ba9..9e31180 100644
--- a/Library/Utils/FlowTrigger/ChannelFlowTrigger.cs
+++ b/Library/Utils/FlowTrigger/ChannelFlowTrigger.cs
@@ -25,16 +25,7 @@ namespace Serein.Library.Utils
/// 对应的 Channel
private Channel> GetOrCreateChannel(TSignal signal)
{
- if(_channels.TryGetValue(signal, out var channel))
- {
- return channel;
- }
- else
- {
- channel = Channel.CreateUnbounded>();
- _channels.AddOrUpdate(signal, _ => channel, (s, r) => channel = r);
- return channel;
- }
+ return _channels.GetOrAdd(signal, _ => Channel.CreateUnbounded>());
}
///
diff --git a/Library/Utils/MessageIdGenerator.cs b/Library/Utils/IdGeneratorHelper.cs
similarity index 97%
rename from Library/Utils/MessageIdGenerator.cs
rename to Library/Utils/IdGeneratorHelper.cs
index f1f11b2..5470388 100644
--- a/Library/Utils/MessageIdGenerator.cs
+++ b/Library/Utils/IdGeneratorHelper.cs
@@ -11,7 +11,7 @@ namespace Serein.Library.Utils
///
/// 消息ID生成工具
///
- public class MessageIdGenerator
+ public class IdGeneratorHelper
{
private static readonly object _lock = new object();
private static int _counter = 0;
diff --git a/Serein.Proto.WebSocket/Handle/MethodInvokeConfiguration.cs b/Serein.Proto.WebSocket/Handle/MethodInvokeConfiguration.cs
index a1105a3..cc612f5 100644
--- a/Serein.Proto.WebSocket/Handle/MethodInvokeConfiguration.cs
+++ b/Serein.Proto.WebSocket/Handle/MethodInvokeConfiguration.cs
@@ -56,6 +56,11 @@ namespace Serein.Proto.WebSocket.Handle
///
public bool[] UseMsgId { get; set; } = [];
+ ///
+ /// 是否使用上下文作为参数
+ ///
+ public bool[] UseContent { get; set; } = [];
+
///
/// 参数名称
///
diff --git a/Serein.Proto.WebSocket/Handle/WebSocketHandleModule.cs b/Serein.Proto.WebSocket/Handle/WebSocketHandleModule.cs
index cd5cbb4..9d6c92a 100644
--- a/Serein.Proto.WebSocket/Handle/WebSocketHandleModule.cs
+++ b/Serein.Proto.WebSocket/Handle/WebSocketHandleModule.cs
@@ -254,6 +254,12 @@ namespace Serein.Proto.WebSocket.Handle
args[i] = data;
}
#endregion
+ #region 传递上下文
+ else if (config.UseContent[i])
+ {
+ args[i] = context;
+ }
+ #endregion
#region 传递消息委托
else if (config.IsNeedSendDelegate[i]) // 传递SendAsync委托
{
@@ -308,6 +314,7 @@ namespace Serein.Proto.WebSocket.Handle
}
}
#endregion
+
}
if (!isCanInvoke)
{
diff --git a/Serein.Proto.WebSocket/Serein.Proto.WebSocket.csproj b/Serein.Proto.WebSocket/Serein.Proto.WebSocket.csproj
index 18dee7d..7c67d79 100644
--- a/Serein.Proto.WebSocket/Serein.Proto.WebSocket.csproj
+++ b/Serein.Proto.WebSocket/Serein.Proto.WebSocket.csproj
@@ -25,9 +25,5 @@
-
-
-
-
diff --git a/Serein.Proto.WebSocket/SereinWebSocketService.cs b/Serein.Proto.WebSocket/SereinWebSocketService.cs
index bb0cb95..e433627 100644
--- a/Serein.Proto.WebSocket/SereinWebSocketService.cs
+++ b/Serein.Proto.WebSocket/SereinWebSocketService.cs
@@ -210,6 +210,7 @@ namespace Serein.Proto.WebSocket
UseRequest = parameterInfos.Select(p => p.GetCustomAttribute() is not null).ToArray(),// 是否使用整体data数据
UseData = parameterInfos.Select(p => p.GetCustomAttribute() is not null).ToArray(), // 是否使用整体data数据
UseMsgId = parameterInfos.Select(p => p.GetCustomAttribute() is not null).ToArray(), // 是否使用消息ID
+ UseContent = parameterInfos.Select(p => p.ParameterType.IsAssignableFrom(typeof(WebSocketHandleContext))).ToArray(), // 是否使用上下文
IsNeedSendDelegate = temp_array.Select(p => p.IsNeedSend).ToArray(), // 是否需要发送消息的委托
SendDelegateType = temp_array.Select(p => p.Type).ToArray(), // 发送消息的委托类型
CachedSendDelegates = new Delegate[temp_array.Length], // 提前缓存发送委托数组
diff --git a/Workbench/Serein.WorkBench.csproj b/Workbench/Serein.WorkBench.csproj
index 21e22fc..0887490 100644
--- a/Workbench/Serein.WorkBench.csproj
+++ b/Workbench/Serein.WorkBench.csproj
@@ -69,6 +69,7 @@
+