mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-20 00:06:45 +08:00
重新优化了NodeModel类;从硬编码类型改为“注册/获取”的方式,为下一步解耦Workbench与节点UI做准备。
新增了“全局数据节点”;保存项目文件时,不同节点可以使用自定义数据保存自身独特的数据,不再借用“方法参数”。 重新设计了运行时的环境输出;增量式生成器现在可以选择在属性变更的前后时间点插入自定义代码;重写了加载项目、保存项目的方法。
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.Library.Utils.SereinExpression;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Dynamic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
{
|
||||
@@ -12,38 +15,90 @@ namespace Serein.NodeFlow.Model
|
||||
[NodeProperty(ValuePath = NodeValuePath.Node)]
|
||||
public partial class SingleConditionNode : NodeModelBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 是否为自定义参数
|
||||
/// </summary>
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
private bool _isCustomData;
|
||||
private bool _isExplicitData;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数值
|
||||
/// </summary>
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
private string? _customData;
|
||||
private string? _explicitData;
|
||||
|
||||
/// <summary>
|
||||
/// 条件表达式
|
||||
/// </summary>
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
private string _expression;
|
||||
|
||||
}
|
||||
|
||||
public partial class SingleConditionNode : NodeModelBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 表达式参数索引
|
||||
/// </summary>
|
||||
private const int INDEX_EXPRESSION = 0;
|
||||
|
||||
|
||||
public SingleConditionNode(IFlowEnvironment environment):base(environment)
|
||||
{
|
||||
this.IsCustomData = false;
|
||||
this.CustomData = null;
|
||||
this.IsExplicitData = false;
|
||||
this.ExplicitData = string.Empty;
|
||||
this.Expression = "PASS";
|
||||
}
|
||||
|
||||
|
||||
public override void OnCreating()
|
||||
{
|
||||
// 这里的这个参数是为了方便使用入参控制点,参数无意义
|
||||
var pd = new ParameterDetails[1];
|
||||
pd[INDEX_EXPRESSION] = new ParameterDetails
|
||||
{
|
||||
Index = INDEX_EXPRESSION,
|
||||
Name = nameof(Expression),
|
||||
IsExplicitData = false,
|
||||
DataValue = string.Empty,
|
||||
DataType = typeof(string),
|
||||
ExplicitType = typeof(string),
|
||||
ArgDataSourceNodeGuid = string.Empty,
|
||||
ArgDataSourceType = ConnectionArgSourceType.GetPreviousNodeData,
|
||||
NodeModel = this,
|
||||
Convertor = null,
|
||||
ExplicitTypeName = "Value",
|
||||
Items = null,
|
||||
};
|
||||
this.MethodDetails.ParameterDetailss = [..pd];
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导出方法信息
|
||||
/// </summary>
|
||||
/// <param name="nodeInfo"></param>
|
||||
/// <returns></returns>
|
||||
public override NodeInfo SaveCustomData(NodeInfo nodeInfo)
|
||||
{
|
||||
dynamic data = new ExpandoObject();
|
||||
data.Expression = Expression ?? "";
|
||||
data.ExplicitData = ExplicitData ?? "";
|
||||
data.IsExplicitData = IsExplicitData;
|
||||
nodeInfo.CustomData = data;
|
||||
return nodeInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载自定义数据
|
||||
/// </summary>
|
||||
/// <param name="nodeInfo"></param>
|
||||
public override void LoadCustomData(NodeInfo nodeInfo)
|
||||
{
|
||||
this.Expression = nodeInfo.CustomData?.Expression ?? "";
|
||||
this.ExplicitData = nodeInfo.CustomData?.ExplicitData ?? "";
|
||||
this.IsExplicitData = nodeInfo.CustomData?.IsExplicitData ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写节点的方法执行
|
||||
/// </summary>
|
||||
@@ -54,54 +109,45 @@ namespace Serein.NodeFlow.Model
|
||||
// 接收上一节点参数or自定义参数内容
|
||||
object? parameter;
|
||||
object? result = null;
|
||||
if (!IsCustomData) // 是否使用自定义参数
|
||||
|
||||
if (!IsExplicitData)
|
||||
{
|
||||
|
||||
var pd = MethodDetails.ParameterDetailss[0];
|
||||
|
||||
if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData)
|
||||
// 使用自动取参
|
||||
var pd = MethodDetails.ParameterDetailss[INDEX_EXPRESSION];
|
||||
if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData)
|
||||
{
|
||||
// 使用自定义节点的参数
|
||||
result = context.GetFlowData(pd.ArgDataSourceNodeGuid);
|
||||
result = context.GetFlowData(pd.ArgDataSourceNodeGuid); // 使用自定义节点的参数
|
||||
}
|
||||
else if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeDataOfInvoke)
|
||||
{
|
||||
// 立刻调用目标节点,然后使用其返回值
|
||||
result = await Env.InvokeNodeAsync(context, pd.ArgDataSourceNodeGuid);
|
||||
result = await Env.InvokeNodeAsync(context, pd.ArgDataSourceNodeGuid); // 立刻调用目标节点,然后使用其返回值
|
||||
}
|
||||
else
|
||||
{
|
||||
// 条件节点透传上一节点的数据
|
||||
result = context.TransmissionData(this);
|
||||
result = context.TransmissionData(this); // 条件节点透传上一节点的数据
|
||||
}
|
||||
|
||||
// 使用上一节点的参数
|
||||
parameter = result;
|
||||
parameter = result; // 使用上一节点的参数
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var getObjExp = CustomData?.ToString();
|
||||
if (string.IsNullOrEmpty(getObjExp) || getObjExp.Length < 4 || !getObjExp[..4].Equals("@get", StringComparison.CurrentCultureIgnoreCase))
|
||||
var exp = ExplicitData?.ToString();
|
||||
if (!string.IsNullOrEmpty(exp) && exp.StartsWith('@'))
|
||||
{
|
||||
// 使用自定义的参数
|
||||
parameter = CustomData;
|
||||
parameter = result; // 表达式获取上一节点数据
|
||||
if (parameter is not null)
|
||||
{
|
||||
parameter = SerinExpressionEvaluator.Evaluate(exp, parameter, out _);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 表达式获取上一节点数据
|
||||
parameter = result;
|
||||
if (parameter is not null)
|
||||
{
|
||||
parameter = SerinExpressionEvaluator.Evaluate(getObjExp, parameter, out _);
|
||||
}
|
||||
parameter = ExplicitData; // 使用自定义的参数
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var isPass = SereinConditionParser.To(parameter, Expression);
|
||||
context.NextOrientation = isPass ? ConnectionInvokeType.IsSucceed : ConnectionInvokeType.IsFail;
|
||||
}
|
||||
@@ -117,105 +163,6 @@ namespace Serein.NodeFlow.Model
|
||||
|
||||
|
||||
|
||||
public override ParameterData[] GetParameterdatas()
|
||||
{
|
||||
var pd1 = MethodDetails.ParameterDetailss[0];
|
||||
var pd2 = MethodDetails.ParameterDetailss[1];
|
||||
var pd3 = MethodDetails.ParameterDetailss[2];
|
||||
return [
|
||||
new ParameterData // 保存表达式
|
||||
{
|
||||
Value = Expression ,
|
||||
SourceNodeGuid = pd1.ArgDataSourceNodeGuid,
|
||||
SourceType = pd1.ArgDataSourceType.ToString(),
|
||||
},
|
||||
new ParameterData // 保存自定义参数
|
||||
{
|
||||
Value = CustomData?.ToString() ,
|
||||
SourceNodeGuid = pd2.ArgDataSourceNodeGuid,
|
||||
SourceType = pd2.ArgDataSourceType.ToString(),
|
||||
},
|
||||
new ParameterData // 参数来源状态
|
||||
{
|
||||
Value = IsCustomData.ToString() ,
|
||||
SourceNodeGuid = pd3.ArgDataSourceNodeGuid,
|
||||
SourceType = pd3.ArgDataSourceType.ToString(),
|
||||
}];
|
||||
}
|
||||
|
||||
public override void OnCreating()
|
||||
{
|
||||
// 自定义节点初始化默认的参数实体
|
||||
var tmpParameterDetails = new ParameterDetails[3];
|
||||
for (int index = 0; index <= 2; index++)
|
||||
{
|
||||
tmpParameterDetails[index] = new ParameterDetails
|
||||
{
|
||||
Index = index,
|
||||
IsExplicitData = false,
|
||||
DataValue = string.Empty,
|
||||
ArgDataSourceNodeGuid = string.Empty,
|
||||
ArgDataSourceType = ConnectionArgSourceType.GetPreviousNodeData,
|
||||
NodeModel = this,
|
||||
Convertor = null,
|
||||
ExplicitTypeName = "Value",
|
||||
Items = Array.Empty<string>(),
|
||||
};
|
||||
}
|
||||
|
||||
var pd1 = tmpParameterDetails[0]; // 表达式
|
||||
var pd2 = tmpParameterDetails[1]; // 自定义参数
|
||||
var pd3 = tmpParameterDetails[2]; // 参数来源
|
||||
|
||||
// 表达式
|
||||
pd1.Name = nameof(Expression);
|
||||
pd1.DataType = typeof(string);
|
||||
pd1.ExplicitType = typeof(string);
|
||||
|
||||
// 自定义参数
|
||||
pd2.Name = nameof(CustomData);
|
||||
pd2.DataType = typeof(string);
|
||||
pd2.ExplicitType = typeof(string);
|
||||
|
||||
// 参数来源
|
||||
pd3.Name = nameof(IsCustomData);
|
||||
pd3.DataType = typeof(bool);
|
||||
pd3.ExplicitType = typeof(bool);
|
||||
|
||||
//this.MethodDetails.ParameterDetailss = new ParameterDetails[2] { pd1, pd2 };
|
||||
this.MethodDetails.ParameterDetailss = [..tmpParameterDetails];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public override NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
{
|
||||
this.Guid = nodeInfo.Guid;
|
||||
this.Position = nodeInfo.Position;// 加载位置信息
|
||||
|
||||
var pdInfo1 = nodeInfo.ParameterData[0];
|
||||
this.Expression = pdInfo1.Value; // 加载表达式
|
||||
|
||||
var pdInfo2 = nodeInfo.ParameterData[1];
|
||||
this.CustomData = pdInfo2.Value; // 加载自定义参数信息
|
||||
|
||||
var pdInfo3 = nodeInfo.ParameterData[2];
|
||||
bool.TryParse(pdInfo3.Value,out var @bool); // 参数来源状态
|
||||
this.IsCustomData = @bool;
|
||||
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
{
|
||||
var pd = this.MethodDetails.ParameterDetailss[i]; // 本节点的参数信息
|
||||
ParameterData? pdInfo = nodeInfo.ParameterData[i]; // 项目文件的保存信息
|
||||
|
||||
pd.ArgDataSourceNodeGuid = pdInfo.SourceNodeGuid;
|
||||
pd.ArgDataSourceType = EnumHelper.ConvertEnum<ConnectionArgSourceType>(pdInfo.SourceType);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user