From bcbf6cb99280deb18d1236288a80d32c18013897 Mon Sep 17 00:00:00 2001
From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com>
Date: Mon, 16 Sep 2024 19:53:36 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86IOC=E7=9A=84?=
=?UTF-8?q?=E5=AE=9E=E7=8E=B0=EF=BC=8C=E5=88=A0=E9=99=A4=E4=BA=86=E9=A1=B9?=
=?UTF-8?q?=E7=9B=AE=E6=8E=92=E9=99=A4=E7=9A=84=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Library.Core/Flow/Api.cs | 13 -
Library.Core/Flow/Attribute.cs | 73 --
Library.Core/Flow/DynamicContext.cs | 168 ----
Library.Core/Flow/MethodDetails.cs | 240 ------
Library.Core/Flow/NodeFlowStarter.cs | 171 ----
.../Flow/NodeModel/CompositeActionNode.cs | 51 --
.../Flow/NodeModel/CompositeConditionNode.cs | 67 --
.../Flow/NodeModel/CompositeLoopNode.cs | 6 -
Library.Core/Flow/NodeModel/NodeBase.cs | 510 ------------
.../Flow/NodeModel/SingleActionNode.cs | 68 --
.../Flow/NodeModel/SingleConditionNode.cs | 71 --
.../Flow/NodeModel/SingleExpOpNode.cs | 35 -
.../Flow/NodeModel/SingleFlipflopNode.cs | 12 -
.../Flow/SerinExpression/ConditionResolver.cs | 337 --------
.../SerinExpression/SerinConditionParser.cs | 329 --------
.../SerinExpressionEvaluator.cs | 214 -----
Library.Core/Flow/Tool/DelegateGenerator.cs | 192 -----
Library.Core/Flow/Tool/DynamicTool.cs | 194 -----
Library.Core/Flow/Tool/ExpressionHelper.cs | 740 -----------------
Library.Core/Flow/Tool/TcsSignal.cs | 80 --
Library.Core/IOC/SereinIoc.cs | 373 ---------
.../SerinExpression/ConditionResolver.cs | 337 --------
.../SerinExpression/SerinConditionParser.cs | 338 --------
Library.Core/ServiceContainer.cs | 418 ----------
Library.Core/Tool/DataHelper.cs | 185 -----
Library.Framework/Http/Attribute.cs | 167 ----
Library.Framework/Http/ControllerBase.cs | 19 -
Library.Framework/Http/Router.cs | 761 ------------------
Library.Framework/Http/WebAPIAttribute.cs | 196 -----
Library.Framework/IOC/SereinIoc.cs | 378 ---------
Library.Framework/NodeFlow/Api.cs | 13 -
.../NodeFlow/DynamicNodeFrameworkType.cs | 38 -
Library.Framework/NodeFlow/FlowStateType.cs | 25 -
Library.Framework/NodeFlow/Tool/Attribute.cs | 8 -
.../NodeFlow/Tool/DynamicTool.cs | 194 -----
Library.Framework/NodeFlow/Tool/TcsSignal.cs | 65 --
Library.Framework/Tool/DataHelper.cs | 186 -----
Library/Api/ISereinIoc.cs | 9 +-
Library/Base/NodeBase.cs | 83 --
Library/Base/NodeModelBaseData.cs | 110 ---
Library/Base/NodeModelBaseFunc.cs | 480 -----------
Library/Serein.Library.csproj | 11 +-
Library/Utils/SereinIoc.cs | 234 ++++--
.../SerinExpression/ConditionResolver.cs | 338 --------
.../SerinExpressionEvaluator.cs | 216 -----
NodeFlow/Base/NodeModelBaseFunc.cs | 2 +-
NodeFlow/ConnectionType.cs | 30 -
NodeFlow/DynamicContext.cs | 230 ------
NodeFlow/FlowEnvironment.cs | 62 +-
NodeFlow/FlowStarter.cs | 2 +-
NodeFlow/MethodDetails.cs | 241 ------
NodeFlow/Model/SingleConditionNode.cs | 4 +-
NodeFlow/Model/SingleExpOpNode.cs | 2 +-
NodeFlow/SerinExpression/ConditionResolver.cs | 337 --------
.../SerinExpression/SerinConditionParser.cs | 329 --------
.../SerinExpressionEvaluator.cs | 214 -----
NodeFlow/Tool/Attribute.cs | 73 --
NodeFlow/Tool/DynamicTool.cs | 202 -----
NodeFlow/Tool/NodeModelBaseFunc.cs | 460 -----------
.../Resolver/BoolConditionResolver.cs | 38 +
.../Resolver/MemberConditionResolver.cs | 53 ++
.../Resolver/MemberStringConditionResolver.cs | 76 ++
.../Resolver/PassConditionResolver.cs | 38 +
.../Resolver/StringConditionResolver.cs | 80 ++
.../Resolver/ValueTypeConditionResolver.cs | 100 +++
.../SereinExpression/SereinConditionParser.cs | 92 ++-
.../SereinConditionResolver.cs | 12 +
.../SerinExpressionEvaluator.cs | 46 +-
.../Tool/SerinExpression/ConditionResolver.cs | 337 --------
.../SerinExpression/SerinConditionParser.cs | 341 --------
.../SerinExpressionEvaluator.cs | 216 -----
NodeFlow/Tool/TcsSignal.cs | 64 --
72 files changed, 702 insertions(+), 11732 deletions(-)
delete mode 100644 Library.Core/Flow/Api.cs
delete mode 100644 Library.Core/Flow/Attribute.cs
delete mode 100644 Library.Core/Flow/DynamicContext.cs
delete mode 100644 Library.Core/Flow/MethodDetails.cs
delete mode 100644 Library.Core/Flow/NodeFlowStarter.cs
delete mode 100644 Library.Core/Flow/NodeModel/CompositeActionNode.cs
delete mode 100644 Library.Core/Flow/NodeModel/CompositeConditionNode.cs
delete mode 100644 Library.Core/Flow/NodeModel/CompositeLoopNode.cs
delete mode 100644 Library.Core/Flow/NodeModel/NodeBase.cs
delete mode 100644 Library.Core/Flow/NodeModel/SingleActionNode.cs
delete mode 100644 Library.Core/Flow/NodeModel/SingleConditionNode.cs
delete mode 100644 Library.Core/Flow/NodeModel/SingleExpOpNode.cs
delete mode 100644 Library.Core/Flow/NodeModel/SingleFlipflopNode.cs
delete mode 100644 Library.Core/Flow/SerinExpression/ConditionResolver.cs
delete mode 100644 Library.Core/Flow/SerinExpression/SerinConditionParser.cs
delete mode 100644 Library.Core/Flow/SerinExpression/SerinExpressionEvaluator.cs
delete mode 100644 Library.Core/Flow/Tool/DelegateGenerator.cs
delete mode 100644 Library.Core/Flow/Tool/DynamicTool.cs
delete mode 100644 Library.Core/Flow/Tool/ExpressionHelper.cs
delete mode 100644 Library.Core/Flow/Tool/TcsSignal.cs
delete mode 100644 Library.Core/IOC/SereinIoc.cs
delete mode 100644 Library.Core/SerinExpression/ConditionResolver.cs
delete mode 100644 Library.Core/SerinExpression/SerinConditionParser.cs
delete mode 100644 Library.Core/ServiceContainer.cs
delete mode 100644 Library.Core/Tool/DataHelper.cs
delete mode 100644 Library.Framework/Http/Attribute.cs
delete mode 100644 Library.Framework/Http/ControllerBase.cs
delete mode 100644 Library.Framework/Http/Router.cs
delete mode 100644 Library.Framework/Http/WebAPIAttribute.cs
delete mode 100644 Library.Framework/IOC/SereinIoc.cs
delete mode 100644 Library.Framework/NodeFlow/Api.cs
delete mode 100644 Library.Framework/NodeFlow/DynamicNodeFrameworkType.cs
delete mode 100644 Library.Framework/NodeFlow/FlowStateType.cs
delete mode 100644 Library.Framework/NodeFlow/Tool/Attribute.cs
delete mode 100644 Library.Framework/NodeFlow/Tool/DynamicTool.cs
delete mode 100644 Library.Framework/NodeFlow/Tool/TcsSignal.cs
delete mode 100644 Library.Framework/Tool/DataHelper.cs
delete mode 100644 Library/Base/NodeBase.cs
delete mode 100644 Library/Base/NodeModelBaseData.cs
delete mode 100644 Library/Base/NodeModelBaseFunc.cs
delete mode 100644 Library/Utils/SerinExpression/ConditionResolver.cs
delete mode 100644 Library/Utils/SerinExpression/SerinExpressionEvaluator.cs
delete mode 100644 NodeFlow/ConnectionType.cs
delete mode 100644 NodeFlow/DynamicContext.cs
delete mode 100644 NodeFlow/MethodDetails.cs
delete mode 100644 NodeFlow/SerinExpression/ConditionResolver.cs
delete mode 100644 NodeFlow/SerinExpression/SerinConditionParser.cs
delete mode 100644 NodeFlow/SerinExpression/SerinExpressionEvaluator.cs
delete mode 100644 NodeFlow/Tool/Attribute.cs
delete mode 100644 NodeFlow/Tool/DynamicTool.cs
delete mode 100644 NodeFlow/Tool/NodeModelBaseFunc.cs
create mode 100644 NodeFlow/Tool/SereinExpression/Resolver/BoolConditionResolver.cs
create mode 100644 NodeFlow/Tool/SereinExpression/Resolver/MemberConditionResolver.cs
create mode 100644 NodeFlow/Tool/SereinExpression/Resolver/MemberStringConditionResolver.cs
create mode 100644 NodeFlow/Tool/SereinExpression/Resolver/PassConditionResolver.cs
create mode 100644 NodeFlow/Tool/SereinExpression/Resolver/StringConditionResolver.cs
create mode 100644 NodeFlow/Tool/SereinExpression/Resolver/ValueTypeConditionResolver.cs
rename Library/Utils/SerinExpression/SerinConditionParser.cs => NodeFlow/Tool/SereinExpression/SereinConditionParser.cs (81%)
create mode 100644 NodeFlow/Tool/SereinExpression/SereinConditionResolver.cs
rename {Library.Core/SerinExpression => NodeFlow/Tool/SereinExpression}/SerinExpressionEvaluator.cs (82%)
delete mode 100644 NodeFlow/Tool/SerinExpression/ConditionResolver.cs
delete mode 100644 NodeFlow/Tool/SerinExpression/SerinConditionParser.cs
delete mode 100644 NodeFlow/Tool/SerinExpression/SerinExpressionEvaluator.cs
delete mode 100644 NodeFlow/Tool/TcsSignal.cs
diff --git a/Library.Core/Flow/Api.cs b/Library.Core/Flow/Api.cs
deleted file mode 100644
index a62632a..0000000
--- a/Library.Core/Flow/Api.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Serein.Flow
-{
- public interface IDynamicFlowNode
- {
- }
-
-}
diff --git a/Library.Core/Flow/Attribute.cs b/Library.Core/Flow/Attribute.cs
deleted file mode 100644
index 942f11d..0000000
--- a/Library.Core/Flow/Attribute.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Serein.Flow
-{
-
- public enum DynamicNodeType
- {
- ///
- /// 初始化
- ///
- Init,
- ///
- /// 开始载入
- ///
- Loading,
- ///
- /// 结束
- ///
- Exit,
-
- ///
- /// 触发器
- ///
- Flipflop,
- ///
- /// 条件节点
- ///
- Condition,
- ///
- /// 动作节点
- ///
- Action,
- }
-
-
-
- ///
- /// 用来判断一个类是否需要注册并构建实例(单例模式场景使用)
- ///
- [AttributeUsage(AttributeTargets.Class)]
- public class DynamicFlowAttribute(bool scan = true) : Attribute
- {
- public bool Scan { get; set; } = scan;
- }
-
- ///
- /// 标记一个方法是什么类型,加载dll后用来拖拽到画布中
- ///
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
- public class MethodDetailAttribute(DynamicNodeType methodDynamicType,
- string methodTips = "",
- bool scan = true,
- string lockName = "") : Attribute
- {
- public bool Scan { get; set; } = scan;
- public string MethodTips { get; } = methodTips;
- public DynamicNodeType MethodDynamicType { get; } = methodDynamicType;
- public string LockName { get; } = lockName;
- }
-
- ///
- /// 是否为显式参数
- ///
- [AttributeUsage(AttributeTargets.Parameter)]
- public class ExplicitAttribute : Attribute // where TEnum : Enum
- {
- }
-
-}
diff --git a/Library.Core/Flow/DynamicContext.cs b/Library.Core/Flow/DynamicContext.cs
deleted file mode 100644
index a0bb924..0000000
--- a/Library.Core/Flow/DynamicContext.cs
+++ /dev/null
@@ -1,168 +0,0 @@
-using DynamicDemo.Node;
-using Serein.Library.IOC;
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Text;
-using System.Threading.Tasks;
-using static System.Collections.Specialized.BitVector32;
-using static System.Runtime.InteropServices.JavaScript.JSType;
-
-namespace Serein.Flow
-{
-
- public enum FfState
- {
- Succeed,
- Cancel,
- }
- ///
- /// 触发器上下文
- ///
- public class FlipflopContext
- {
- public FfState State { get; set; }
- public object? Data { get; set; }
- /*public FlipflopContext()
- {
- State = FfState.Cancel;
- }*/
- public FlipflopContext(FfState ffState,object? data = null)
- {
- State = ffState;
- Data = data;
- }
- }
-
-
- ///
- /// 动态流程上下文
- ///
-
- public class DynamicContext(IServiceContainer serviceContainer)
-
- {
-
- private readonly string contextGuid = "";//System.Guid.NewGuid().ToString();
-
- public IServiceContainer ServiceContainer { get; } = serviceContainer;
- private List InitServices { get; set; } = [];
-
- // private ConcurrentDictionary ContextData { get; set; } = [];
-
- //public void SetFlowData(object data)
- //{
- // var threadId = Thread.CurrentThread.ManagedThreadId.ToString();
- // var name = $"{threadId}.{contextGuid}FlowData";
- // SetData(name,data);
- //}
- //public object GetFlowData(bool IsRetain = false)
- //{
- // var threadId = Thread.CurrentThread.ManagedThreadId.ToString();
- // var name = $"{threadId}.{contextGuid}FlowData";
- // if (IsRetain)
- // {
- // return GetData(name);
- // }
- // else
- // {
- // return GetAndRemoteData(name);
-
- // }
- //}
-
-
- public void InitService()
- {
- InitService(typeof(T));
- }
- public void InitService(Type type)
- {
- if (!InitServices.Contains(type))
- {
- InitServices.Add(type);
- }
- else
- {
- //throw new Exception("初始化时试图添加已存在的类型:"+type.Name);
- Console.WriteLine("初始化时试图添加已存在的类型:" + type.Name);
- }
- }
- public void Biuld()
- {
- foreach (var item in InitServices)
- {
- ServiceContainer.Register(item);
- }
- ServiceContainer.Build();
- }
-
- //public object? RemoveData(string key)
- //{
- // if (ContextData.Remove(key, out var data))
- // {
- // return data;
- // }
- // return null;
- //}
-
- //public void SetData(string key, T value)
- //{
- // ContextData[key] = value;
- //}
-
- //public T? GetData(string key)
- //{
- // if (ContextData.TryGetValue(key, out object? value))
- // {
- // if(value == null)
- // {
- // return default;
- // }
- // if (value.GetType() == typeof(T))
- // {
- // return (T)value;
- // }
-
- // }
- // return default;
- //}
-
- //public object? GetData(string key)
- //{
- // if (ContextData.TryGetValue(key, out object? value))
- // {
- // return value;
- // }
- // return null;
- //}
-
-
- //public ConcurrentDictionary FlipFlopTasks { get; set; } = [];
-
- public NodeRunTcs NodeRunCts { get; set; }
- public Task CreateTimingTask(Action action, int time = 100, int count = -1)
- {
- NodeRunCts ??= ServiceContainer.Get();
- return Task.Factory.StartNew(async () =>
- {
- for(int i = 0; i < count; i++)
- {
- NodeRunCts.Token.ThrowIfCancellationRequested();
- await time;
- action.Invoke();
- }
- });
- }
- }
-
- public static class MyExtensions
- {
- public static TaskAwaiter GetAwaiter(this int i) => Task.Delay(i).GetAwaiter();
- }
-
-
- // if (time <= 0) throw new ArgumentException("时间不能≤0");
-}
diff --git a/Library.Core/Flow/MethodDetails.cs b/Library.Core/Flow/MethodDetails.cs
deleted file mode 100644
index dd62b99..0000000
--- a/Library.Core/Flow/MethodDetails.cs
+++ /dev/null
@@ -1,240 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using static Dm.net.buffer.ByteArrayBuffer;
-
-namespace Serein.Flow
-{
- ///
- /// 显式参数
- ///
- public class ExplicitData
- {
- ///
- /// 索引
- ///
- public int Index { get; set; }
- ///
- /// 是否为显式参数
- ///
- public bool IsExplicitData { get; set; }
- ///
- /// 显式类型
- ///
- public Type? ExplicitType { get; set; }
-
- ///
- /// 显示类型编号>
- ///
- public string ExplicitTypeName { get; set; }
-
- ///
- /// 方法需要的类型
- ///
- public Type DataType { get; set; }
-
- ///
- /// 方法入参参数名称
- ///
- public string ParameterName { get; set; }
-
- ///
- /// 入参值
- ///
-
- public string DataValue { get; set; }
-
-
-
- public string[] Items { get; set; }
-
-
-
-
- public ExplicitData Clone() => new()
- {
- Index = Index,
- IsExplicitData = IsExplicitData,
- ExplicitType = ExplicitType,
- DataType = DataType,
- ParameterName = ParameterName,
- ExplicitTypeName = ExplicitTypeName,
- DataValue = string.IsNullOrEmpty(DataValue) ? string.Empty : DataValue,
- Items = [.. Items],
- };
- }
-
-
-
- public class MethodDetails
- {
- public MethodDetails Clone()
- {
- return new MethodDetails
- {
- ActingInstance = ActingInstance,
- ActingInstanceType = ActingInstanceType,
- MethodDelegate = MethodDelegate,
- MethodDynamicType = MethodDynamicType,
- MethodGuid = Guid.NewGuid().ToString(),
- MethodTips = MethodTips ,
- ReturnType = ReturnType,
- MethodName = MethodName,
- MethodLockName = MethodLockName,
-
- ExplicitDatas = ExplicitDatas.Select(it => it.Clone()).ToArray(),
- };
- }
-
- ///
- /// 作用实例
- ///
-
- public Type ActingInstanceType { get; set; }
-
- ///
- /// 作用实例
- ///
-
- public object ActingInstance { get; set; }
-
- ///
- /// 方法GUID
- ///
-
- public string MethodGuid { get; set; }
-
- ///
- /// 方法名称
- ///
-
- public string MethodName { get; set; }
-
- ///
- /// 方法委托
- ///
-
- public Delegate MethodDelegate { get; set; }
-
- ///
- /// 节点类型
- ///
- public DynamicNodeType MethodDynamicType { get; set; }
- ///
- /// 锁名称
- ///
-
- public string MethodLockName { get; set; }
-
-
- ///
- /// 方法说明
- ///
-
- public string MethodTips { get; set; }
-
-
- ///
- /// 参数内容
- ///
-
- public ExplicitData[] ExplicitDatas { get; set; }
-
-
-
- ///
- /// 出参类型
- ///
-
- public Type ReturnType { get; set; }
-
-
-
-
-
-
- public bool IsCanConnect(Type returnType)
- {
- if (ExplicitDatas.Length == 0)
- {
- // 目标不需要传参,可以舍弃结果?
- return true;
- }
- var types = ExplicitDatas.Select(it => it.DataType).ToArray();
- // 检查返回类型是否是元组类型
- if (returnType.IsGenericType && IsValueTuple(returnType))
- {
-
- return CompareGenericArguments(returnType, types);
- }
- else
- {
- int index = 0;
- if (types[index] == typeof(DynamicContext))
- {
- index++;
- if (types.Length == 1)
- {
- return true;
- }
- }
- // 被连接节点检查自己需要的参数类型,与发起连接的节点比较返回值类型
- if (returnType == types[index])
- {
- return true;
- }
- }
- return false;
- }
-
- ///
- /// 检查元组类型
- ///
- ///
- ///
- private bool IsValueTuple(Type type)
- {
- if (!type.IsGenericType) return false;
-
- var genericTypeDef = type.GetGenericTypeDefinition();
- return genericTypeDef == typeof(ValueTuple<>) ||
- genericTypeDef == typeof(ValueTuple<,>) ||
- genericTypeDef == typeof(ValueTuple<,,>) ||
- genericTypeDef == typeof(ValueTuple<,,,>) ||
- genericTypeDef == typeof(ValueTuple<,,,,>) ||
- genericTypeDef == typeof(ValueTuple<,,,,,>) ||
- genericTypeDef == typeof(ValueTuple<,,,,,,>) ||
- genericTypeDef == typeof(ValueTuple<,,,,,,,>);
- }
-
- private bool CompareGenericArguments(Type returnType, Type[] parameterTypes)
- {
- var genericArguments = returnType.GetGenericArguments();
- var length = parameterTypes.Length;
-
- for (int i = 0; i < genericArguments.Length; i++)
- {
- if (i >= length) return false;
-
- if (IsValueTuple(genericArguments[i]))
- {
- // 如果当前参数也是 ValueTuple,递归检查嵌套的泛型参数
- if (!CompareGenericArguments(genericArguments[i], parameterTypes.Skip(i).ToArray()))
- {
- return false;
- }
- }
- else if (genericArguments[i] != parameterTypes[i])
- {
- return false;
- }
- }
-
- return true;
- }
- }
-
-
-}
diff --git a/Library.Core/Flow/NodeFlowStarter.cs b/Library.Core/Flow/NodeFlowStarter.cs
deleted file mode 100644
index 83cc335..0000000
--- a/Library.Core/Flow/NodeFlowStarter.cs
+++ /dev/null
@@ -1,171 +0,0 @@
-using Serein.Flow;
-using Serein.Flow.NodeModel;
-using Serein.Flow.Tool;
-using Serein.Library.Http;
-using Serein.Library.IOC;
-using SqlSugar;
-
-namespace DynamicDemo.Node
-{
-
- public class NodeRunTcs: CancellationTokenSource
- {
-
- }
-
-
- public class NodeFlowStarter(IServiceContainer serviceContainer,List methodDetails)
-
- {
- private readonly IServiceContainer ServiceContainer = serviceContainer;
- private readonly List methodDetails = methodDetails;
-
- private Action ExitAction = null;
-
-
- private DynamicContext context = null;
-
-
- public NodeRunTcs MainCts;
-
- ///
- /// 运行测试
- ///
- ///
- ///
- //public async Task RunAsync1(List nodes)
- //{
- // await Task.Run(async ()=> await StartRunAsync(nodes));
- //}
-
- public async Task RunAsync(List nodes)
- {
- var startNode = nodes.FirstOrDefault(p => p.IsStart);
- if (startNode == null) { return; }
- context = new(ServiceContainer);
-
- MainCts = ServiceContainer.CreateServiceInstance();
-
- var initMethods = methodDetails.Where(it => it.MethodDynamicType == DynamicNodeType.Init).ToList();
- var loadingMethods = methodDetails.Where(it => it.MethodDynamicType == DynamicNodeType.Loading).ToList();
- var exitMethods = methodDetails.Where(it => it.MethodDynamicType == DynamicNodeType.Exit).ToList();
- ExitAction = () =>
- {
- ServiceContainer.Run((web) =>
- {
- web?.Stop();
- });
- foreach (MethodDetails? md in exitMethods)
- {
- object?[]? args = [context];
- object?[]? data = [md.ActingInstance, args];
- md.MethodDelegate.DynamicInvoke(data);
- }
- if(context != null && context.NodeRunCts != null && !context.NodeRunCts.IsCancellationRequested)
- {
- context.NodeRunCts.Cancel();
- }
- if (MainCts!=null && !MainCts.IsCancellationRequested) MainCts.Cancel();
- ServiceContainer.Reset();
- };
-
-
- foreach (var md in initMethods) // 初始化 - 调用方法
- {
- //md.ActingInstance = context.ServiceContainer.Get(md.ActingInstanceType);
- object?[]? args = [context];
- object?[]? data = [md.ActingInstance, args];
- md.MethodDelegate.DynamicInvoke(data);
- }
- context.Biuld();
-
- foreach (var md in loadingMethods) // 加载
- {
- //md.ActingInstance = context.ServiceContainer.Get(md.ActingInstanceType);
- object?[]? args = [context];
- object?[]? data = [md.ActingInstance, args];
- md.MethodDelegate.DynamicInvoke(data);
- }
-
- var flipflopNodes = nodes.Where(it => it.MethodDetails?.MethodDynamicType == DynamicNodeType.Flipflop
- && it.PreviousNodes.Count == 0
- && it.IsStart != true).ToArray();
-
- var singleFlipflopNodes = flipflopNodes.Select(it => (SingleFlipflopNode)it).ToArray();
-
- // 使用 TaskCompletionSource 创建未启动的任务
- var tasks = singleFlipflopNodes.Select(async node =>
- {
- await FlipflopExecute(node);
- }).ToArray();
-
-
- try
- {
- await Task.WhenAll([startNode.ExecuteStack(context),.. tasks]);
- }
- catch (Exception ex)
- {
- await Console.Out.WriteLineAsync(ex.ToString());
- }
-
- }
-
- private async Task FlipflopExecute(SingleFlipflopNode singleFlipFlopNode)
- {
- DynamicContext context = new DynamicContext(ServiceContainer);
- MethodDetails md = singleFlipFlopNode.MethodDetails;
-
- try
- {
-
- if (!DelegateCache.GlobalDicDelegates.TryGetValue(md.MethodName, out Delegate del))
- {
- return;
- }
-
- var func = md.ExplicitDatas.Length == 0 ? ((Func