mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-11 10:26:34 +08:00
修改了无法保存项目文件的bug
This commit is contained in:
@@ -70,12 +70,12 @@ namespace Serein.NodeFlow
|
||||
/// </summary>
|
||||
/// <param name="startNode">起始节点</param>
|
||||
/// <param name="env">运行环境</param>
|
||||
/// <param name="runMd">环境中已加载的所有节点方法</param>
|
||||
/// <param name="runNodeMd">环境中已加载的所有节点方法</param>
|
||||
/// <param name="flipflopNodes">触发器节点</param>
|
||||
/// <returns></returns>
|
||||
public async Task RunAsync(NodeModelBase startNode,
|
||||
IFlowEnvironment env,
|
||||
List<MethodDetails> runMd,
|
||||
List<MethodDetails> runNodeMd,
|
||||
List<MethodDetails> initMethods,
|
||||
List<MethodDetails> loadingMethods,
|
||||
List<MethodDetails> exitMethods,
|
||||
@@ -89,6 +89,8 @@ namespace Serein.NodeFlow
|
||||
return;
|
||||
}
|
||||
|
||||
#region 选择运行环境的上下文
|
||||
|
||||
// 判断使用哪一种流程上下文
|
||||
var isNetFramework = true;
|
||||
if (isNetFramework)
|
||||
@@ -99,23 +101,38 @@ namespace Serein.NodeFlow
|
||||
{
|
||||
Context = new Serein.Library.Core.NodeFlow.DynamicContext(SereinIOC, env);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 初始化运行环境的Ioc容器
|
||||
// 清除节点使用的对象
|
||||
foreach (var nodeMd in runMd)
|
||||
var thisRuningMds = new List<MethodDetails>();
|
||||
thisRuningMds.AddRange(runNodeMd);
|
||||
thisRuningMds.AddRange(initMethods);
|
||||
thisRuningMds.AddRange(loadingMethods);
|
||||
thisRuningMds.AddRange(exitMethods);
|
||||
|
||||
// .AddRange(initMethods).AddRange(loadingMethods).a
|
||||
foreach (var nodeMd in thisRuningMds)
|
||||
{
|
||||
nodeMd.ActingInstance = null;
|
||||
}
|
||||
|
||||
SereinIOC.Reset(); // 开始运行时清空ioc中注册的实例
|
||||
// 初始化ioc容器中的类型对象
|
||||
foreach (var md in runMd)
|
||||
foreach (var md in thisRuningMds)
|
||||
{
|
||||
SereinIOC.Register(md.ActingInstanceType);
|
||||
if(md.ActingInstanceType != null)
|
||||
{
|
||||
SereinIOC.Register(md.ActingInstanceType);
|
||||
}
|
||||
}
|
||||
SereinIOC.Build();
|
||||
foreach (var md in runMd)
|
||||
SereinIOC.Build(); // 流程启动前的初始化
|
||||
foreach (var md in thisRuningMds)
|
||||
{
|
||||
md.ActingInstance = SereinIOC.GetOrInstantiate(md.ActingInstanceType);
|
||||
if (md.ActingInstanceType != null)
|
||||
{
|
||||
md.ActingInstance = SereinIOC.GetOrRegisterInstantiate(md.ActingInstanceType);
|
||||
}
|
||||
}
|
||||
|
||||
//foreach (var md in flipflopNodes.Select(it => it.MethodDetails).ToArray())
|
||||
@@ -124,23 +141,36 @@ namespace Serein.NodeFlow
|
||||
//}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 创建Node中初始化、加载时、退出时调用的方法
|
||||
|
||||
#region 检查并修正初始化、加载时、退出时方法作用的对象,保证后续不会报错
|
||||
foreach (var md in initMethods) // 初始化
|
||||
{
|
||||
md.ActingInstance ??= Context.SereinIoc.GetOrInstantiate(md.ActingInstanceType);
|
||||
md.ActingInstance ??= Context.SereinIoc.GetOrRegisterInstantiate(md.ActingInstanceType);
|
||||
}
|
||||
foreach (var md in loadingMethods) // 加载
|
||||
{
|
||||
md.ActingInstance ??= Context.SereinIoc.GetOrInstantiate(md.ActingInstanceType);
|
||||
md.ActingInstance ??= Context.SereinIoc.GetOrRegisterInstantiate(md.ActingInstanceType);
|
||||
}
|
||||
foreach (var md in exitMethods) // 初始化
|
||||
{
|
||||
md.ActingInstance ??= Context.SereinIoc.GetOrInstantiate(md.ActingInstanceType);
|
||||
md.ActingInstance ??= Context.SereinIoc.GetOrRegisterInstantiate(md.ActingInstanceType);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 执行初始化,绑定IOC容器,再执行加载时,设置流程退出时的回调函数
|
||||
|
||||
object?[]? args = [Context];
|
||||
foreach (var md in initMethods) // 初始化
|
||||
{
|
||||
object?[]? data = [md.ActingInstance, args];
|
||||
md.MethodDelegate.DynamicInvoke(data);
|
||||
}
|
||||
Context.SereinIoc.Build(); // 绑定初始化时注册的类型
|
||||
foreach (var md in loadingMethods) // 加载
|
||||
{
|
||||
object?[]? data = [md.ActingInstance, args];
|
||||
md.MethodDelegate.DynamicInvoke(data);
|
||||
}
|
||||
Context.SereinIoc.Build(); // 预防有人在加载时才注册类型,再绑定一次
|
||||
ExitAction = () =>
|
||||
{
|
||||
foreach (MethodDetails? md in exitMethods)
|
||||
@@ -159,34 +189,18 @@ namespace Serein.NodeFlow
|
||||
FlowState = RunState.Completion;
|
||||
FlipFlopState = RunState.Completion;
|
||||
};
|
||||
Context.SereinIoc.Build();
|
||||
#endregion
|
||||
|
||||
#region 执行初始化,然后绑定IOC容器,再执行加载时
|
||||
|
||||
foreach (var md in initMethods) // 初始化 - 调用方法
|
||||
{
|
||||
object?[]? data = [md.ActingInstance, args];
|
||||
md.MethodDelegate.DynamicInvoke(data);
|
||||
}
|
||||
Context.SereinIoc.Build();
|
||||
foreach (var md in loadingMethods) // 加载
|
||||
{
|
||||
object?[]? data = [md.ActingInstance, args];
|
||||
md.MethodDelegate.DynamicInvoke(data);
|
||||
}
|
||||
#endregion
|
||||
#region 开始启动流程
|
||||
|
||||
|
||||
// 节点任务的启动
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
if (flipflopNodes.Count > 0)
|
||||
{
|
||||
FlipFlopState = RunState.Running;
|
||||
// 如果存在需要启动的触发器,则开始启动
|
||||
FlipFlopCts = SereinIOC.GetOrInstantiate<NodeRunCts>();
|
||||
FlipFlopCts = SereinIOC.GetOrRegisterInstantiate<NodeRunCts>();
|
||||
// 使用 TaskCompletionSource 创建未启动的触发器任务
|
||||
var tasks = flipflopNodes.Select(async node =>
|
||||
{
|
||||
@@ -196,7 +210,7 @@ namespace Serein.NodeFlow
|
||||
}
|
||||
await startNode.StartExecution(Context);
|
||||
// 等待结束
|
||||
if(FlipFlopCts != null)
|
||||
if (FlipFlopCts != null)
|
||||
{
|
||||
while (!FlipFlopCts.IsCancellationRequested)
|
||||
{
|
||||
@@ -207,7 +221,8 @@ namespace Serein.NodeFlow
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Out.WriteLineAsync(ex.ToString());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -228,7 +243,7 @@ namespace Serein.NodeFlow
|
||||
object?[]? parameters = singleFlipFlopNode.GetParameters(context, md);
|
||||
// 调用委托并获取结果
|
||||
|
||||
md.ActingInstance = context.SereinIoc.GetOrInstantiate(md.ActingInstanceType);
|
||||
md.ActingInstance = context.SereinIoc.GetOrRegisterInstantiate(md.ActingInstanceType);
|
||||
|
||||
IFlipflopContext flipflopContext = await func.Invoke(md.ActingInstance, parameters);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user