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