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

82 lines
2.3 KiB
C#
Raw Normal View History

using Serein.Library;
using Serein.Library.Api;
using Serein.Library.Utils.SereinExpression;
using System.Reactive;
2024-08-06 16:09:46 +08:00
namespace Serein.NodeFlow.Model
{
/// <summary>
/// Expression Operation - 表达式操作
/// </summary>
[NodeProperty(ValuePath = NodeValuePath.Node)]
public partial class SingleExpOpNode : NodeModelBase
2024-08-06 16:09:46 +08:00
{
/// <summary>
/// 表达式
/// </summary>
[PropertyInfo(IsNotification = true)]
private string _expression;
}
2024-08-06 16:09:46 +08:00
public partial class SingleExpOpNode : NodeModelBase
{
public SingleExpOpNode(IFlowEnvironment environment) : base(environment)
{
}
2024-08-06 16:09:46 +08:00
//public override async Task<object?> Executing(IDynamicContext context)
public override Task<object?> ExecutingAsync(IDynamicContext context)
2024-08-06 16:09:46 +08:00
{
2024-10-27 00:54:10 +08:00
var data = context.GetFlowData(PreviousNode.Guid); // 表达式节点使用上一节点数据
2024-08-06 16:09:46 +08:00
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;
2024-09-15 22:07:10 +08:00
}
else
{
result = data;
2024-09-15 22:07:10 +08:00
}
context.NextOrientation = ConnectionInvokeType.IsSucceed;
return Task.FromResult(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
{
context.NextOrientation = ConnectionInvokeType.IsError;
2024-09-15 22:07:10 +08:00
RuningException = ex;
return Task.FromResult(data);
2024-08-06 16:09:46 +08:00
}
}
2024-10-27 00:54:10 +08:00
public override ParameterData[] GetParameterdatas()
{
2024-10-27 00:54:10 +08:00
return [new ParameterData { Expression = Expression }];
}
2024-10-11 23:08:56 +08:00
public override NodeModelBase LoadInfo(NodeInfo nodeInfo)
{
var node = this;
this.Position = nodeInfo.Position;// 加载位置信息
node.Guid = nodeInfo.Guid;
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
{
node.Expression = nodeInfo.ParameterData[i].Expression;
}
return this;
}
2024-08-06 16:09:46 +08:00
}
}