Files
serein-flow/NodeFlow/Model/SingleExpOpNode.cs

71 lines
2.0 KiB
C#
Raw Normal View History

using Serein.Library.Api;
using Serein.Library.Entity;
using Serein.Library.Enums;
using Serein.NodeFlow.Base;
using Serein.NodeFlow.Tool.SereinExpression;
2024-09-15 22:07:10 +08:00
using System.Text;
2024-08-06 16:09:46 +08:00
namespace Serein.NodeFlow.Model
{
/// <summary>
/// Expression Operation - 表达式操作
/// </summary>
public class SingleExpOpNode : NodeModelBase
2024-08-06 16:09:46 +08:00
{
/// <summary>
/// 表达式
/// </summary>
public string Expression { get; set; }
public override object? Execute(IDynamicContext context)
2024-08-06 16:09:46 +08:00
{
var data = PreviousNode?.FlowData;
2024-09-15 22:07:10 +08:00
try
2024-08-06 16:09:46 +08:00
{
2024-09-15 22:07:10 +08:00
var newData = SerinExpressionEvaluator.Evaluate(Expression, data, out bool isChange);
Console.WriteLine(newData);
object? result = null;
if (isChange)
{
result = newData;
}
else
{
result = PreviousNode?.FlowData;
}
NextOrientation = ConnectionType.IsSucceed;
return result;
2024-08-06 16:09:46 +08:00
}
2024-09-15 22:07:10 +08:00
catch (Exception ex)
2024-08-06 16:09:46 +08:00
{
2024-09-15 22:07:10 +08:00
NextOrientation = ConnectionType.IsError;
RuningException = ex;
2024-08-06 16:09:46 +08:00
return PreviousNode?.FlowData;
}
}
public override Parameterdata[] GetParameterdatas()
{
if (base.MethodDetails.ExplicitDatas.Length > 0)
{
return MethodDetails.ExplicitDatas
.Select(it => new Parameterdata
{
state = it.IsExplicitData,
// value = it.DataValue,
expression = Expression,
})
.ToArray();
}
else
{
return [];
}
}
2024-08-06 16:09:46 +08:00
}
}