优化了流程的进行

This commit is contained in:
fengjiayi
2024-09-15 22:07:10 +08:00
parent fe2ccaf74c
commit 61d40977ff
21 changed files with 153 additions and 117 deletions

View File

@@ -26,50 +26,38 @@ namespace Serein.NodeFlow.Model
/// <returns></returns>
public override object? Execute(IDynamicContext context)
{
// bool allTrue = ConditionNodes.All(condition => Judge(context,condition.MethodDetails));
// bool IsAllTrue = true; // 初始化为 true
FlowState = FlowStateType.Succeed;
// NextOrientation = ConnectionType.IsSucceed;
// 条件区域中遍历每个条件节点
foreach (SingleConditionNode? node in ConditionNodes)
{
var state = Judge(context, node);
if (state == FlowStateType.Fail || FlowStateType.Fail == FlowStateType.Error)
NextOrientation = state; // 每次判读完成后,设置区域后继方向为判断结果
if (state != ConnectionType.IsSucceed)
{
FlowState = state;
break;// 一旦发现条件为假,立即退出循环
// 如果条件不通过,立刻推出循环
break;
}
}
return PreviousNode?.FlowData;
//if (IsAllTrue)
//{
// foreach (var nextNode in TrueBranchNextNodes)
// {
// nextNode.ExecuteStack(context);
// }
//}
//else
//{
// foreach (var nextNode in FalseBranchNextNodes)
// {
// nextNode.ExecuteStack(context);
// }
//}
}
private FlowStateType Judge(IDynamicContext context, SingleConditionNode node)
private ConnectionType Judge(IDynamicContext context, SingleConditionNode node)
{
try
{
node.Execute(context);
return node.FlowState;
return node.NextOrientation;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return FlowStateType.Error;
NextOrientation = ConnectionType.IsError;
RuningException = ex;
return ConnectionType.IsError;
}
}

View File

@@ -43,15 +43,15 @@ namespace Serein.NodeFlow.Model
try
{
var isPass = SerinConditionParser.To(result, Expression);
FlowState = isPass ? FlowStateType.Succeed : FlowStateType.Fail;
NextOrientation = isPass ? ConnectionType.IsSucceed : ConnectionType.IsFail;
}
catch (Exception ex)
{
FlowState = FlowStateType.Error;
NextOrientation = ConnectionType.IsError;
RuningException = ex;
}
Console.WriteLine($"{result} {Expression} -> " + FlowState);
Console.WriteLine($"{result} {Expression} -> " + NextOrientation);
return result;
}

View File

@@ -3,6 +3,7 @@ using Serein.Library.Entity;
using Serein.Library.Enums;
using Serein.NodeFlow.Base;
using Serein.NodeFlow.Tool.SerinExpression;
using System.Text;
namespace Serein.NodeFlow.Model
{
@@ -21,16 +22,27 @@ namespace Serein.NodeFlow.Model
{
var data = PreviousNode?.FlowData;
var newData = SerinExpressionEvaluator.Evaluate(Expression, data, out bool isChange);
try
{
var newData = SerinExpressionEvaluator.Evaluate(Expression, data, out bool isChange);
Console.WriteLine(newData);
object? result = null;
if (isChange)
{
result = newData;
}
else
{
result = PreviousNode?.FlowData;
}
FlowState = FlowStateType.Succeed;
Console.WriteLine(newData);
if (isChange)
{
return newData;
NextOrientation = ConnectionType.IsSucceed;
return result;
}
else
catch (Exception ex)
{
NextOrientation = ConnectionType.IsError;
RuningException = ex;
return PreviousNode?.FlowData;
}

View File

@@ -1,5 +1,6 @@
using Serein.Library.Api;
using Serein.Library.Entity;
using Serein.Library.Ex;
using Serein.NodeFlow.Base;
namespace Serein.NodeFlow.Model
@@ -7,9 +8,11 @@ namespace Serein.NodeFlow.Model
public class SingleFlipflopNode : NodeModelBase
{
public override object Execute(IDynamicContext context)
public override object? Execute(IDynamicContext context)
{
throw new NotImplementedException("无法以非await/async的形式调用触发器");
NextOrientation = Library.Enums.ConnectionType.IsError;
RuningException = new FlipflopException ("无法以非await/async的形式调用触发器");
return null;
}
public override Parameterdata[] GetParameterdatas()