From 5941f753136fad86a18f81c65dc06affda224f75 Mon Sep 17 00:00:00 2001
From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com>
Date: Mon, 23 Dec 2024 23:19:10 +0800
Subject: [PATCH] =?UTF-8?q?=E5=B0=86FlowTrigger=E8=A7=A6=E5=8F=91=E5=99=A8?=
=?UTF-8?q?=E6=95=B4=E5=90=88=E6=88=90=E6=8E=A5=E5=8F=A3=E7=9A=84=E5=BD=A2?=
=?UTF-8?q?=E5=BC=8F=E6=96=B9=E4=BE=BF=E6=9B=BF=E6=8D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Library.Core/FlipflopContext.cs | 2 +-
Library.Framework/FlipflopContext.cs | 2 +-
Library/Api/IFlipflopContext.cs | 2 +-
Library/Api/IFlowTrigger.cs | 44 ++++++
Library/Enums/NodeType.cs | 10 ++
Library/FlowNode/NodeModelBaseFunc.cs | 3 +-
Library/Utils/ChannelFlowTrigger.cs | 83 ++++++-----
Library/Utils/EnumHelper.cs | 18 ++-
Library/Utils/SingleSyncFlowTrigger.cs | 136 ++++++++++++++++++
.../{FlowTrigger.cs => TaskFlowTrigger.cs} | 129 ++++++++++-------
.../LogicControl/ParkingLogicControl.cs | 10 +-
Net462DllTest/LogicControl/PlcLogicControl.cs | 4 +-
.../LogicControl/ViewLogicControl.cs | 9 +-
Net462DllTest/Trigger/PrakingDevice.cs | 2 +-
Net462DllTest/Trigger/SiemensPlcDevice.cs | 6 +-
Net462DllTest/Trigger/ViewManagement.cs | 2 +-
.../ViewModel/FromWorkBenchViewModel.cs | 2 +-
Net462DllTest/Web/FlowController.cs | 4 +-
Net462DllTest/Web/PlcSocketService.cs | 2 +-
NodeFlow/Env/MsgControllerOfClient.cs | 22 +--
NodeFlow/Env/RemoteFlowEnvironment.cs | 2 +-
NodeFlow/{Env => }/FlowFunc.cs | 48 ++++---
NodeFlow/FlowStarter.cs | 2 +-
NodeFlow/Model/SingleActionNode.cs | 11 +-
NodeFlow/Model/SingleFlipflopNode.cs | 5 +-
NodeFlow/Model/SingleScriptNode.cs | 2 +-
WorkBench/App.xaml.cs | 1 +
WorkBench/MainWindow.xaml.cs | 2 -
.../GlobalDataNodeControlViewModel.cs | 2 +-
29 files changed, 403 insertions(+), 164 deletions(-)
create mode 100644 Library/Api/IFlowTrigger.cs
create mode 100644 Library/Utils/SingleSyncFlowTrigger.cs
rename Library/Utils/{FlowTrigger.cs => TaskFlowTrigger.cs} (54%)
rename NodeFlow/{Env => }/FlowFunc.cs (79%)
diff --git a/Library.Core/FlipflopContext.cs b/Library.Core/FlipflopContext.cs
index a9e6862..cabf969 100644
--- a/Library.Core/FlipflopContext.cs
+++ b/Library.Core/FlipflopContext.cs
@@ -71,7 +71,7 @@ namespace Serein.Library.Core
{
public FlipflopStateType State { get; set; }
- public TriggerType Type { get; set; }
+ public TriggerDescription Type { get; set; }
public TResult Value { get; set; }
public FlipflopContext(FlipflopStateType ffState)
diff --git a/Library.Framework/FlipflopContext.cs b/Library.Framework/FlipflopContext.cs
index b1be1a5..c3fa51a 100644
--- a/Library.Framework/FlipflopContext.cs
+++ b/Library.Framework/FlipflopContext.cs
@@ -63,7 +63,7 @@ namespace Serein.Library.Framework.NodeFlow
{
public FlipflopStateType State { get; set; }
- public TriggerType Type { get; set; }
+ public TriggerDescription Type { get; set; }
public TResult Value { get; set; }
public FlipflopContext(FlipflopStateType ffState)
diff --git a/Library/Api/IFlipflopContext.cs b/Library/Api/IFlipflopContext.cs
index 288d2f5..10be21e 100644
--- a/Library/Api/IFlipflopContext.cs
+++ b/Library/Api/IFlipflopContext.cs
@@ -17,7 +17,7 @@ namespace Serein.Library.Api
///
/// 触发类型
///
- TriggerType Type { get; set; }
+ TriggerDescription Type { get; set; }
///
/// 触发时传递的数据
///
diff --git a/Library/Api/IFlowTrigger.cs b/Library/Api/IFlowTrigger.cs
new file mode 100644
index 0000000..33b07bb
--- /dev/null
+++ b/Library/Api/IFlowTrigger.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Serein.Library.Api
+{
+ ///
+ /// 触发器接口
+ ///
+ ///
+ public interface IFlowTrigger
+ {
+ ///
+ /// 等待信号触发并指定超时时间
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> WaitTriggerWithTimeoutAsync(TSignal signal, TimeSpan outTime);
+ ///
+ /// 等待信号触发
+ ///
+ /// 预期的返回值类型
+ ///
+ ///
+ Task> WaitTriggerAsync(TSignal signal);
+ ///
+ /// 调用触发器
+ ///
+ /// 预期的返回值类型
+ /// 信号
+ /// 返回值
+ ///
+ Task InvokeTriggerAsync(TSignal signal, TResult value);
+ ///
+ /// 取消所有触发器
+ ///
+ void CancelAllTrigger();
+ }
+
+}
diff --git a/Library/Enums/NodeType.cs b/Library/Enums/NodeType.cs
index 44b472b..90f211e 100644
--- a/Library/Enums/NodeType.cs
+++ b/Library/Enums/NodeType.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -72,6 +73,9 @@ namespace Serein.Library
///
public enum NodeControlType
{
+ ///
+ /// 预料之外的情况
+ ///
None,
///
/// 动作节点
@@ -81,25 +85,31 @@ namespace Serein.Library
/// 触发器节点
///
Flipflop,
+
///
/// 表达式操作节点
///
+ [Description("base")]
ExpOp,
///
/// 表达式操作节点
///
+ [Description("base")]
ExpCondition,
///
/// 条件节点区域
///
+ [Description("base")]
ConditionRegion,
///
/// 全局数据
///
+ [Description("base")]
GlobalData,
///
/// 脚本节点
///
+ [Description("base")]
Script,
}
diff --git a/Library/FlowNode/NodeModelBaseFunc.cs b/Library/FlowNode/NodeModelBaseFunc.cs
index ee5a643..ef01b3a 100644
--- a/Library/FlowNode/NodeModelBaseFunc.cs
+++ b/Library/FlowNode/NodeModelBaseFunc.cs
@@ -38,7 +38,6 @@ namespace Serein.Library
}
-
///
/// 保存自定义信息
///
@@ -155,7 +154,7 @@ namespace Serein.Library
AssemblyName = MethodDetails.AssemblyName,
MethodName = MethodDetails?.MethodName,
Label = MethodDetails?.MethodAnotherName,
- Type = this.GetType().ToString(),
+ Type = ControlType.ToString() , //this.GetType().ToString(),
TrueNodes = trueNodes.ToArray(),
FalseNodes = falseNodes.ToArray(),
UpstreamNodes = upstreamNodes.ToArray(),
diff --git a/Library/Utils/ChannelFlowTrigger.cs b/Library/Utils/ChannelFlowTrigger.cs
index 34a5d5e..d65e1d6 100644
--- a/Library/Utils/ChannelFlowTrigger.cs
+++ b/Library/Utils/ChannelFlowTrigger.cs
@@ -1,5 +1,6 @@
+using Serein.Library.Api;
using System;
using System.Collections.Concurrent;
using System.Threading;
@@ -12,18 +13,22 @@ namespace Serein.Library.Utils
- public class ChannelFlowTrigger
+ public class ChannelFlowTrigger : IFlowTrigger
{
// 使用并发字典管理每个枚举信号对应的 Channel
- private readonly ConcurrentDictionary> _channels = new ConcurrentDictionary>();
+ private readonly ConcurrentDictionary>> _channels = new ConcurrentDictionary>>();
///
- /// 创建信号并指定超时时间,到期后自动触发(异步方法)
+ /// 获取或创建指定信号的 Channel
///
/// 枚举信号标识符
- /// 超时时间
- /// 等待任务
- public async Task<(TriggerType, TResult)> WaitDataWithTimeoutAsync(TSignal signal, TimeSpan outTime)
+ /// 对应的 Channel
+ private Channel> GetOrCreateChannel(TSignal signal)
+ {
+ return _channels.GetOrAdd(signal, _ => Channel.CreateUnbounded>());
+ }
+
+ public async Task> WaitTriggerWithTimeoutAsync(TSignal signal, TimeSpan outTime)
{
var channel = GetOrCreateChannel(signal);
var cts = new CancellationTokenSource();
@@ -34,7 +39,11 @@ namespace Serein.Library.Utils
try
{
await Task.Delay(outTime, cts.Token);
- await channel.Writer.WriteAsync((TriggerType.Overtime, null));
+ var outResult = new TriggerResult