mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-20 08:16:34 +08:00
优化了运行。在运行状态下,在画布上添加触发器、移除触发器、或者涉及到触发器的操作都会及时/延时生效(已经在等待信号的触发器,将会在触发信号后才会拿取新的信号类型创建触发任务)
This commit is contained in:
@@ -157,7 +157,7 @@ namespace Serein.NodeFlow
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 执行初始化,绑定IOC容器,再执行加载时,设置流程退出时的回调函数
|
||||
#region 执行初始化,绑定IOC容器,再执行加载时
|
||||
|
||||
object?[]? args = [Context];
|
||||
foreach (var md in initMethods) // 初始化
|
||||
@@ -172,6 +172,9 @@ namespace Serein.NodeFlow
|
||||
md.MethodDelegate.DynamicInvoke(data);
|
||||
}
|
||||
Context.SereinIoc.Build(); // 预防有人在加载时才注册类型,再绑定一次
|
||||
#endregion
|
||||
|
||||
#region 设置流程退出时的回调函数
|
||||
ExitAction = () =>
|
||||
{
|
||||
SereinIOC.Run<WebServer>(web => {
|
||||
@@ -193,9 +196,6 @@ namespace Serein.NodeFlow
|
||||
}
|
||||
FlowState = RunState.Completion;
|
||||
FlipFlopState = RunState.Completion;
|
||||
|
||||
|
||||
|
||||
};
|
||||
#endregion
|
||||
|
||||
@@ -233,6 +233,17 @@ namespace Serein.NodeFlow
|
||||
#endregion
|
||||
}
|
||||
|
||||
public void AddFlipflopInRuning(SingleFlipflopNode singleFlipFlopNode, IFlowEnvironment flowEnvironment)
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
// 设置对象
|
||||
singleFlipFlopNode.MethodDetails.ActingInstance = SereinIOC.GetOrRegisterInstantiate(singleFlipFlopNode.MethodDetails.ActingInstanceType);
|
||||
await FlipflopExecute(singleFlipFlopNode, flowEnvironment); // 启动触发器
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 启动触发器
|
||||
/// </summary>
|
||||
@@ -248,26 +259,39 @@ namespace Serein.NodeFlow
|
||||
|
||||
while (!FlipFlopCts.IsCancellationRequested) // 循环中直到栈为空才会退出
|
||||
{
|
||||
if(singleFlipFlopNode.NotExitPreviousNode() == false)
|
||||
{
|
||||
// 存在上级节点时,退出触发器
|
||||
break;
|
||||
}
|
||||
object?[]? parameters = singleFlipFlopNode.GetParameters(context, md);
|
||||
// 调用委托并获取结果
|
||||
|
||||
md.ActingInstance = context.SereinIoc.GetOrRegisterInstantiate(md.ActingInstanceType);
|
||||
|
||||
IFlipflopContext flipflopContext = await func.Invoke(md.ActingInstance, parameters);
|
||||
|
||||
ConnectionType connection = flipflopContext.State.ToContentType();
|
||||
|
||||
|
||||
if (connection != ConnectionType.None)
|
||||
{
|
||||
singleFlipFlopNode.NextOrientation = connection;
|
||||
singleFlipFlopNode.FlowData = flipflopContext.Data;
|
||||
|
||||
var tasks = singleFlipFlopNode.SuccessorNodes[connection].Select(nextNode =>
|
||||
var upstreamNodeTasks = singleFlipFlopNode.SuccessorNodes[ConnectionType.Upstream].Select(nextNode =>
|
||||
{
|
||||
var context = new DynamicContext(SereinIOC, flowEnvironment);
|
||||
nextNode.PreviousNode = singleFlipFlopNode;
|
||||
return nextNode.StartExecution(context);
|
||||
}).ToArray();
|
||||
|
||||
var tmpTasks = singleFlipFlopNode.SuccessorNodes[connection].Select(nextNode =>
|
||||
{
|
||||
var context = new DynamicContext(SereinIOC,flowEnvironment);
|
||||
nextNode.PreviousNode = singleFlipFlopNode;
|
||||
return nextNode.StartExecution(context);
|
||||
}).ToArray();
|
||||
Task[] tasks = [..upstreamNodeTasks, .. tmpTasks];
|
||||
Task.WaitAll(tasks);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user