2024-10-20 12:10:57 +08:00
|
|
|
|
using Serein.Library;
|
2024-09-12 20:32:54 +08:00
|
|
|
|
using Serein.Library.Api;
|
2024-10-20 12:10:57 +08:00
|
|
|
|
using Serein.Library.Utils.SereinExpression;
|
2024-10-22 00:13:13 +08:00
|
|
|
|
using System.ComponentModel;
|
2024-08-06 16:09:46 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Serein.NodeFlow.Model
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 条件节点(用于条件控件)
|
|
|
|
|
|
/// </summary>
|
2024-10-22 00:13:13 +08:00
|
|
|
|
[NodeProperty(ValuePath = NodeValuePath.Node)]
|
|
|
|
|
|
public partial class SingleConditionNode : NodeModelBase
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否为自定义参数
|
|
|
|
|
|
/// </summary>
|
2024-10-22 00:13:13 +08:00
|
|
|
|
[PropertyInfo(IsNotification = true)]
|
|
|
|
|
|
private bool _isCustomData;
|
|
|
|
|
|
|
2024-08-06 16:09:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 自定义参数值
|
|
|
|
|
|
/// </summary>
|
2024-10-22 00:13:13 +08:00
|
|
|
|
[PropertyInfo(IsNotification = true)]
|
|
|
|
|
|
|
|
|
|
|
|
private object? _customData;
|
2024-08-06 16:09:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 条件表达式
|
|
|
|
|
|
/// </summary>
|
2024-10-22 00:13:13 +08:00
|
|
|
|
[PropertyInfo(IsNotification = true)]
|
|
|
|
|
|
private string _expression;
|
2024-08-06 16:09:46 +08:00
|
|
|
|
|
2024-10-22 00:13:13 +08:00
|
|
|
|
}
|
2024-08-06 16:09:46 +08:00
|
|
|
|
|
2024-10-22 00:13:13 +08:00
|
|
|
|
public partial class SingleConditionNode : NodeModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public SingleConditionNode(IFlowEnvironment environment):base(environment)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.IsCustomData = false;
|
|
|
|
|
|
this.CustomData = null;
|
|
|
|
|
|
this.Expression = "PASS";
|
2024-10-28 21:52:45 +08:00
|
|
|
|
|
2024-10-22 00:13:13 +08:00
|
|
|
|
}
|
2024-08-06 16:09:46 +08:00
|
|
|
|
|
2024-10-28 21:52:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载完成后调用的方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override void OnLoading()
|
|
|
|
|
|
{
|
|
|
|
|
|
var pd = new ParameterDetails
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = 0,
|
|
|
|
|
|
Name = "Exp",
|
|
|
|
|
|
DataType = typeof(object),
|
|
|
|
|
|
ExplicitType = typeof(object),
|
|
|
|
|
|
IsExplicitData = false,
|
|
|
|
|
|
DataValue = string.Empty,
|
|
|
|
|
|
ArgDataSourceNodeGuid = string.Empty,
|
|
|
|
|
|
ArgDataSourceType = ConnectionArgSourceType.GetPreviousNodeData,
|
|
|
|
|
|
NodeModel = this,
|
|
|
|
|
|
Convertor = null,
|
|
|
|
|
|
ExplicitTypeName = "Value",
|
|
|
|
|
|
Items = Array.Empty<string>(),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.MethodDetails.ParameterDetailss = new ParameterDetails[] { pd };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-22 00:13:13 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 重写节点的方法执行
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-09-20 10:50:32 +08:00
|
|
|
|
public override Task<object?> ExecutingAsync(IDynamicContext context)
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// 接收上一节点参数or自定义参数内容
|
2024-10-14 17:29:28 +08:00
|
|
|
|
object? parameter;
|
2024-10-28 21:52:45 +08:00
|
|
|
|
object? result = context.TransmissionData(this); // 条件节点透传上一节点的数据
|
2024-10-14 17:29:28 +08:00
|
|
|
|
if (IsCustomData) // 是否使用自定义参数
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
2024-10-14 17:29:28 +08:00
|
|
|
|
// 表达式获取上一节点数据
|
|
|
|
|
|
var getObjExp = CustomData?.ToString();
|
|
|
|
|
|
if (!string.IsNullOrEmpty(getObjExp) && getObjExp.Length >= 4 && getObjExp[..4].Equals("@get", StringComparison.CurrentCultureIgnoreCase))
|
|
|
|
|
|
{
|
|
|
|
|
|
parameter = result;
|
|
|
|
|
|
if (parameter is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
parameter = SerinExpressionEvaluator.Evaluate(getObjExp, parameter, out _);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
parameter = CustomData;
|
|
|
|
|
|
}
|
2024-08-06 16:09:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-10-14 17:29:28 +08:00
|
|
|
|
parameter = result;
|
2024-08-06 16:09:46 +08:00
|
|
|
|
}
|
2024-09-09 16:42:01 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-10-14 17:29:28 +08:00
|
|
|
|
|
|
|
|
|
|
var isPass = SereinConditionParser.To(parameter, Expression);
|
2024-10-24 23:32:43 +08:00
|
|
|
|
context.NextOrientation = isPass ? ConnectionInvokeType.IsSucceed : ConnectionInvokeType.IsFail;
|
2024-09-09 16:42:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2024-10-24 23:32:43 +08:00
|
|
|
|
context.NextOrientation = ConnectionInvokeType.IsError;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
RuningException = ex;
|
2024-09-09 16:42:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-24 23:32:43 +08:00
|
|
|
|
Console.WriteLine($"{result} {Expression} -> " + context.NextOrientation);
|
2024-09-20 10:50:32 +08:00
|
|
|
|
return Task.FromResult(result);
|
2024-08-06 16:09:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-27 00:54:10 +08:00
|
|
|
|
public override ParameterData[] GetParameterdatas()
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
2024-09-17 14:20:27 +08:00
|
|
|
|
var value = CustomData switch
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
2024-09-17 14:20:27 +08:00
|
|
|
|
Type when CustomData.GetType() == typeof(int)
|
|
|
|
|
|
&& CustomData.GetType() == typeof(double)
|
|
|
|
|
|
&& CustomData.GetType() == typeof(float)
|
|
|
|
|
|
=> ((double)CustomData).ToString(),
|
|
|
|
|
|
Type when CustomData.GetType() == typeof(bool) => ((bool)CustomData).ToString(),
|
|
|
|
|
|
_ => CustomData?.ToString()!,
|
|
|
|
|
|
};
|
2024-10-27 00:54:10 +08:00
|
|
|
|
return [new ParameterData
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
2024-09-17 14:20:27 +08:00
|
|
|
|
State = IsCustomData,
|
|
|
|
|
|
Expression = Expression,
|
|
|
|
|
|
Value = value,
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-11 23:08:56 +08:00
|
|
|
|
public override NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
2024-09-17 14:20:27 +08:00
|
|
|
|
{
|
|
|
|
|
|
var node = this;
|
2024-10-22 00:13:13 +08:00
|
|
|
|
node.Guid = nodeInfo.Guid;
|
|
|
|
|
|
this.Position = nodeInfo.Position;// 加载位置信息
|
|
|
|
|
|
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
2024-09-17 14:20:27 +08:00
|
|
|
|
{
|
2024-10-27 00:54:10 +08:00
|
|
|
|
ParameterData? pd = nodeInfo.ParameterData[i];
|
2024-10-22 00:13:13 +08:00
|
|
|
|
node.IsCustomData = pd.State;
|
|
|
|
|
|
node.CustomData = pd.Value;
|
|
|
|
|
|
node.Expression = pd.Expression;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
}
|
2024-09-17 14:20:27 +08:00
|
|
|
|
return this;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-22 00:13:13 +08:00
|
|
|
|
|
2024-08-06 16:09:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|