2024-09-12 20:32:54 +08:00
|
|
|
|
using Serein.Library.Api;
|
|
|
|
|
|
using Serein.Library.Enums;
|
|
|
|
|
|
using Serein.Library.Core.NodeFlow;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Serein.NodeFlow.Model
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 组合条件节点(用于条件区域)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class CompositeConditionNode : NodeBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public List<SingleConditionNode> ConditionNodes { get; } = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void AddNode(SingleConditionNode node)
|
|
|
|
|
|
{
|
|
|
|
|
|
ConditionNodes.Add(node);
|
|
|
|
|
|
MethodDetails ??= node.MethodDetails;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-09 16:42:01 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 条件节点重写执行方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-09-12 20:32:54 +08:00
|
|
|
|
public override object? Execute(IDynamicContext context)
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// bool allTrue = ConditionNodes.All(condition => Judge(context,condition.MethodDetails));
|
|
|
|
|
|
// bool IsAllTrue = true; // 初始化为 true
|
2024-09-09 16:42:01 +08:00
|
|
|
|
FlowState = FlowStateType.Succeed;
|
2024-08-06 16:09:46 +08:00
|
|
|
|
foreach (SingleConditionNode? node in ConditionNodes)
|
|
|
|
|
|
{
|
2024-09-09 16:42:01 +08:00
|
|
|
|
var state = Judge(context, node);
|
|
|
|
|
|
if (state == FlowStateType.Fail || FlowStateType.Fail == FlowStateType.Error)
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
2024-09-09 16:42:01 +08:00
|
|
|
|
FlowState = state;
|
2024-08-06 16:09:46 +08:00
|
|
|
|
break;// 一旦发现条件为假,立即退出循环
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return PreviousNode?.FlowData;
|
|
|
|
|
|
//if (IsAllTrue)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// foreach (var nextNode in TrueBranchNextNodes)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// nextNode.ExecuteStack(context);
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
// foreach (var nextNode in FalseBranchNextNodes)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// nextNode.ExecuteStack(context);
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
2024-09-12 20:32:54 +08:00
|
|
|
|
private FlowStateType Judge(IDynamicContext context, SingleConditionNode node)
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
node.Execute(context);
|
|
|
|
|
|
return node.FlowState;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(ex.Message);
|
2024-09-09 16:42:01 +08:00
|
|
|
|
return FlowStateType.Error;
|
2024-08-06 16:09:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|