流程返回值改为FlowResult,记录节点信息、上下文信息,为以后的流程调用回溯做准备

This commit is contained in:
fengjiayi
2025-03-21 18:26:01 +08:00
parent 9941f24c5d
commit f99aff3c2c
30 changed files with 916 additions and 752 deletions

View File

@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
namespace Serein.Library
@@ -237,6 +238,7 @@ namespace Serein.Library
// 需要获取预入参数据
object inputParameter;
#region
if (ArgDataSourceType == ConnectionArgSourceType.GetPreviousNodeData)
{
var previousNode = context.GetPreviousNode(nodeModel);
@@ -246,40 +248,32 @@ namespace Serein.Library
}
else
{
inputParameter = context.GetFlowData(previousNode.Guid); // 当前传递的数据
inputParameter = context.GetFlowData(previousNode).Value; // 当前传递的数据
}
}
#endregion
#region
else if (ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData)
{
// 获取指定节点的数据
// 如果指定节点没有被执行会返回null
// 如果执行过,会获取上一次执行结果作为预入参数据
inputParameter = context.GetFlowData(ArgDataSourceNodeGuid);
}
#endregion
#region
else if (ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeDataOfInvoke)
{
// 立刻调用对应节点获取数据。
try
{
var result = await env.InvokeNodeAsync(context, ArgDataSourceNodeGuid);
inputParameter = result;
}
catch (Exception ex)
{
context.NextOrientation = ConnectionInvokeType.IsError;
context.ExceptionOfRuning = ex;
throw;
}
}
#endregion
#region
else
{
throw new Exception("节点执行方法获取入参参数时ConnectionArgSourceType枚举是意外的枚举值");
if(!env.TryGetNodeModel(ArgDataSourceNodeGuid, out var argSourceNodeModel))
{
throw new Exception($"[arg{Index}][{Name}][{DataType}]需要节点[{ArgDataSourceNodeGuid}]的参数,但节点不存在");
}
if (ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData)
{
inputParameter = context.GetFlowData(argSourceNodeModel).Value;
}
else if (ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeDataOfInvoke)
{
// 立刻调用对应节点获取数据。
var cts = new CancellationTokenSource();
var result = await argSourceNodeModel.ExecutingAsync(context, cts.Token);
cts?.Cancel();
cts?.Dispose();
inputParameter = result.Value;
}
else
{
throw new Exception("节点执行方法获取入参参数时ConnectionArgSourceType枚举是意外的枚举值");
}
}
#endregion
#region