From 61d40977ffd2ac6298555b63206f67ed44e60d8d Mon Sep 17 00:00:00 2001
From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com>
Date: Sun, 15 Sep 2024 22:07:10 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E6=B5=81=E7=A8=8B?=
=?UTF-8?q?=E7=9A=84=E8=BF=9B=E8=A1=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Library.Core/NodeFlow/FlipflopContext.cs | 6 +--
Library.Framework/NodeFlow/DynamicContext.cs | 1 -
Library.Framework/NodeFlow/FlipflopContext.cs | 27 ++-----------
.../Serein.Library.Framework.csproj | 2 +-
Library/Api/IFlipflopContext.cs | 2 +-
Library/Enums/ConnectionType.cs | 4 ++
...{FlowStateType.cs => FlipflopStateType.cs} | 12 +++---
Library/Ex/FlipflopException.cs | 16 ++++++++
Library/NodeAttribute.cs | 5 +--
.../{TcsSignal.cs => TcsSignalFlipflop.cs} | 10 ++---
NodeFlow/Base/NodeModelBaseData.cs | 12 +++---
NodeFlow/Base/NodeModelBaseFunc.cs | 35 +++++++---------
NodeFlow/FlowEnvironment.cs | 13 ++++++
NodeFlow/FlowStarter.cs | 9 +++--
NodeFlow/Model/CompositeConditionNode.cs | 40 +++++++------------
NodeFlow/Model/SingleConditionNode.cs | 6 +--
NodeFlow/Model/SingleExpOpNode.cs | 26 ++++++++----
NodeFlow/Model/SingleFlipflopNode.cs | 7 +++-
NodeFlow/Tool/MethodDetailsHelper.cs | 16 +++++++-
README.md | 9 +++--
WorkBench/Node/View/FlipflopNodeControl.xaml | 12 ++++++
21 files changed, 153 insertions(+), 117 deletions(-)
rename Library/Enums/{FlowStateType.cs => FlipflopStateType.cs} (89%)
create mode 100644 Library/Ex/FlipflopException.cs
rename Library/Utils/{TcsSignal.cs => TcsSignalFlipflop.cs} (87%)
diff --git a/Library.Core/NodeFlow/FlipflopContext.cs b/Library.Core/NodeFlow/FlipflopContext.cs
index 3819260..8dd9884 100644
--- a/Library.Core/NodeFlow/FlipflopContext.cs
+++ b/Library.Core/NodeFlow/FlipflopContext.cs
@@ -65,15 +65,15 @@ namespace Serein.Library.Core.NodeFlow
///
public class FlipflopContext : IFlipflopContext
{
- public FlowStateType State { get; set; }
+ public FlipflopStateType State { get; set; }
public object Data { get; set; }
- public FlipflopContext(FlowStateType ffState)
+ public FlipflopContext(FlipflopStateType ffState)
{
State = ffState;
}
- public FlipflopContext(FlowStateType ffState, object data)
+ public FlipflopContext(FlipflopStateType ffState, object data)
{
State = ffState;
Data = data;
diff --git a/Library.Framework/NodeFlow/DynamicContext.cs b/Library.Framework/NodeFlow/DynamicContext.cs
index 1335ee5..6107d70 100644
--- a/Library.Framework/NodeFlow/DynamicContext.cs
+++ b/Library.Framework/NodeFlow/DynamicContext.cs
@@ -17,7 +17,6 @@ namespace Serein.Library.Framework.NodeFlow
SereinIoc = sereinIoc;
FlowEnvironment = flowEnvironment;
}
-
public NodeRunCts NodeRunCts { get; set; }
public ISereinIoc SereinIoc { get; }
public IFlowEnvironment FlowEnvironment { get; }
diff --git a/Library.Framework/NodeFlow/FlipflopContext.cs b/Library.Framework/NodeFlow/FlipflopContext.cs
index f97056b..5557d63 100644
--- a/Library.Framework/NodeFlow/FlipflopContext.cs
+++ b/Library.Framework/NodeFlow/FlipflopContext.cs
@@ -5,24 +5,6 @@ using System.Threading.Tasks;
namespace Serein.Library.Framework.NodeFlow
{
- //public enum FfState
- //{
- // Succeed,
- // Cancel,
- // Error,
- //}
-
- //public class FlipflopContext
- //{
- // public FlowStateType State { get; set; }
- // public object? Data { get; set; }
- // public FlipflopContext(FlowStateType ffState, object? data = null)
- // {
- // State = ffState;
- // Data = data;
- // }
- //}
-
public static class FlipflopFunc
{
///
@@ -75,20 +57,19 @@ namespace Serein.Library.Framework.NodeFlow
///
public class FlipflopContext : IFlipflopContext
{
- public FlowStateType State { get; set; }
+ public FlipflopStateType State { get; set; }
//public TResult? Data { get; set; }
public object Data { get; set; }
- public FlipflopContext(FlowStateType ffState)
+ public FlipflopContext(FlipflopStateType ffState)
{
State = ffState;
}
- public FlipflopContext(FlowStateType ffState, object data)
+ public FlipflopContext(FlipflopStateType ffState, object data)
{
State = ffState;
Data = data;
}
-
-
}
+
}
diff --git a/Library.Framework/Serein.Library.Framework.csproj b/Library.Framework/Serein.Library.Framework.csproj
index f0f00c1..3a690f9 100644
--- a/Library.Framework/Serein.Library.Framework.csproj
+++ b/Library.Framework/Serein.Library.Framework.csproj
@@ -55,7 +55,7 @@
- {5e19d0f2-913a-4d1c-a6f8-1e1227baa0e3}
+ {55C77D23-2FD3-43D1-918C-DC3DE9614F0F}
Serein.Library
diff --git a/Library/Api/IFlipflopContext.cs b/Library/Api/IFlipflopContext.cs
index 8722869..5f6b8a8 100644
--- a/Library/Api/IFlipflopContext.cs
+++ b/Library/Api/IFlipflopContext.cs
@@ -4,7 +4,7 @@ namespace Serein.Library.Api
{
public interface IFlipflopContext
{
- FlowStateType State { get; set; }
+ FlipflopStateType State { get; set; }
object Data { get; set; }
}
}
diff --git a/Library/Enums/ConnectionType.cs b/Library/Enums/ConnectionType.cs
index 8c40635..7a90ea3 100644
--- a/Library/Enums/ConnectionType.cs
+++ b/Library/Enums/ConnectionType.cs
@@ -6,6 +6,10 @@ namespace Serein.Library.Enums
{
public enum ConnectionType
{
+ ///
+ /// 不执行分支
+ ///
+ None,
///
/// 真分支
///
diff --git a/Library/Enums/FlowStateType.cs b/Library/Enums/FlipflopStateType.cs
similarity index 89%
rename from Library/Enums/FlowStateType.cs
rename to Library/Enums/FlipflopStateType.cs
index f142e27..087c830 100644
--- a/Library/Enums/FlowStateType.cs
+++ b/Library/Enums/FlipflopStateType.cs
@@ -7,12 +7,8 @@ using System.Threading.Tasks;
namespace Serein.Library.Enums
{
- public enum FlowStateType
+ public enum FlipflopStateType
{
- ///
- /// 待执行
- ///
- None,
///
/// 成功(方法成功执行)
///
@@ -25,5 +21,11 @@ namespace Serein.Library.Enums
/// 异常(节点没有成功执行,执行时发生非预期的错误)
///
Error,
+ ///
+ /// 取消
+ ///
+ Cancel,
}
+
+
}
diff --git a/Library/Ex/FlipflopException.cs b/Library/Ex/FlipflopException.cs
new file mode 100644
index 0000000..d562da4
--- /dev/null
+++ b/Library/Ex/FlipflopException.cs
@@ -0,0 +1,16 @@
+using System;
+
+namespace Serein.Library.Ex
+{
+ ///
+ /// 触发器
+ ///
+ public class FlipflopException: Exception
+ {
+ public bool IsCancel { get; }
+ public FlipflopException(string message, bool isCancel = true) :base(message)
+ {
+ IsCancel = isCancel;
+ }
+ }
+}
diff --git a/Library/NodeAttribute.cs b/Library/NodeAttribute.cs
index a0aab98..0036922 100644
--- a/Library/NodeAttribute.cs
+++ b/Library/NodeAttribute.cs
@@ -27,7 +27,7 @@ namespace Serein.Library.Attributes
///
- /// 标记一个方法是什么类型,加载dll后用来拖拽到画布中
+ /// 建议触发器手动设置返回类型
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class NodeActionAttribute : Attribute
@@ -45,9 +45,6 @@ namespace Serein.Library.Attributes
public bool Scan;
public string MethodTips;
public NodeType MethodDynamicType;
- ///
- /// 推荐触发器手动设置返回类型
- ///
public Type ReturnType;
public string LockName;
}
diff --git a/Library/Utils/TcsSignal.cs b/Library/Utils/TcsSignalFlipflop.cs
similarity index 87%
rename from Library/Utils/TcsSignal.cs
rename to Library/Utils/TcsSignalFlipflop.cs
index 6355acc..fa98d9d 100644
--- a/Library/Utils/TcsSignal.cs
+++ b/Library/Utils/TcsSignalFlipflop.cs
@@ -1,6 +1,7 @@
-using System;
-using System.Threading.Tasks;
+using Serein.Library.Ex;
+using System;
using System.Collections.Concurrent;
+using System.Threading.Tasks;
namespace Serein.Library.Core.NodeFlow.Tool
{
@@ -13,9 +14,8 @@ namespace Serein.Library.Core.NodeFlow.Tool
// }
//}
- public class TcsSignal where TSignal : struct, Enum
+ public class TcsSignalFlipflop where TSignal : struct, Enum
{
- //public ConcurrentDictionary>> TcsEvent { get; } = new();
public ConcurrentDictionary> TcsEvent { get; } = new ConcurrentDictionary>();
public ConcurrentDictionary TcsLock { get; } = new ConcurrentDictionary();
@@ -56,7 +56,7 @@ namespace Serein.Library.Core.NodeFlow.Tool
{
foreach (var tcs in TcsEvent.Values)
{
- tcs.SetException(new Exception("任务取消"));
+ tcs.SetException(new FlipflopException("任务取消"));
}
TcsEvent.Clear();
}
diff --git a/NodeFlow/Base/NodeModelBaseData.cs b/NodeFlow/Base/NodeModelBaseData.cs
index 6b3aab1..c4e9db5 100644
--- a/NodeFlow/Base/NodeModelBaseData.cs
+++ b/NodeFlow/Base/NodeModelBaseData.cs
@@ -1,10 +1,6 @@
-using Newtonsoft.Json;
-using Serein.Library.Api;
+using Serein.Library.Api;
using Serein.Library.Entity;
using Serein.Library.Enums;
-using Serein.NodeFlow.Model;
-using Serein.NodeFlow.Tool.SerinExpression;
-using System.Xml.Linq;
namespace Serein.NodeFlow.Base
{
@@ -65,12 +61,14 @@ namespace Serein.NodeFlow.Base
///
/// 不同分支的子节点
///
- public Dictionary> SuccessorNodes { get; }
+ public Dictionary> SuccessorNodes { get; }
+
+ public ConnectionType NextOrientation { get; set; } = ConnectionType.None;
///
/// 当前执行状态(进入真分支还是假分支,异常分支在异常中确定)
///
- public FlowStateType FlowState { get; set; } = FlowStateType.None;
+ // public FlowStateType FlowState { get; set; } = FlowStateType.Cancel;
///
/// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值)
diff --git a/NodeFlow/Base/NodeModelBaseFunc.cs b/NodeFlow/Base/NodeModelBaseFunc.cs
index 0a3bb54..c678ad0 100644
--- a/NodeFlow/Base/NodeModelBaseFunc.cs
+++ b/NodeFlow/Base/NodeModelBaseFunc.cs
@@ -2,6 +2,7 @@
using Serein.Library.Api;
using Serein.Library.Entity;
using Serein.Library.Enums;
+using Serein.Library.Ex;
using Serein.NodeFlow.Tool.SerinExpression;
using System;
using System.Collections.Generic;
@@ -92,14 +93,13 @@ namespace Serein.NodeFlow.Base
currentNode.FlowData = currentNode.Execute(context);
}
- ConnectionType connection = currentNode.FlowState switch
+ if(currentNode.NextOrientation == ConnectionType.None)
{
- FlowStateType.Succeed => ConnectionType.IsSucceed,
- FlowStateType.Fail => ConnectionType.IsFail,
- FlowStateType.Error => ConnectionType.IsError,
- _ => throw new Exception("非预期的枚举值")
- };
- var nextNodes = currentNode.SuccessorNodes[connection];
+ // 不再执行
+ break;
+ }
+
+ var nextNodes = currentNode.SuccessorNodes[currentNode.NextOrientation];
// 将下一个节点集合中的所有节点逆序推入栈中
for (int i = nextNodes.Count - 1; i >= 0; i--)
@@ -148,12 +148,12 @@ namespace Serein.NodeFlow.Base
result = func?.Invoke(md.ActingInstance, parameters);
}
}
- FlowState = FlowStateType.Succeed;
+ NextOrientation = ConnectionType.IsSucceed;
return result;
}
catch (Exception ex)
{
- FlowState = FlowStateType.Error;
+ NextOrientation = ConnectionType.IsError;
RuningException = ex;
}
@@ -184,23 +184,16 @@ namespace Serein.NodeFlow.Base
object?[]? parameters = GetParameters(context, MethodDetails);
flipflopContext = await ((Func