mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-17 06:56:34 +08:00
优化了流程的进行
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Entity;
|
||||
using Serein.Library.Enums;
|
||||
using Serein.NodeFlow.Model;
|
||||
using Serein.NodeFlow.Tool.SerinExpression;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Serein.NodeFlow.Base
|
||||
{
|
||||
@@ -65,12 +61,14 @@ namespace Serein.NodeFlow.Base
|
||||
/// <summary>
|
||||
/// 不同分支的子节点
|
||||
/// </summary>
|
||||
public Dictionary<ConnectionType,List<NodeModelBase>> SuccessorNodes { get; }
|
||||
public Dictionary<ConnectionType,List<NodeModelBase>> SuccessorNodes { get; }
|
||||
|
||||
public ConnectionType NextOrientation { get; set; } = ConnectionType.None;
|
||||
|
||||
/// <summary>
|
||||
/// 当前执行状态(进入真分支还是假分支,异常分支在异常中确定)
|
||||
/// </summary>
|
||||
public FlowStateType FlowState { get; set; } = FlowStateType.None;
|
||||
// public FlowStateType FlowState { get; set; } = FlowStateType.Cancel;
|
||||
|
||||
/// <summary>
|
||||
/// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Entity;
|
||||
using Serein.Library.Enums;
|
||||
using Serein.Library.Ex;
|
||||
using Serein.NodeFlow.Tool.SerinExpression;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -92,14 +93,13 @@ namespace Serein.NodeFlow.Base
|
||||
currentNode.FlowData = currentNode.Execute(context);
|
||||
}
|
||||
|
||||
ConnectionType connection = currentNode.FlowState switch
|
||||
if(currentNode.NextOrientation == ConnectionType.None)
|
||||
{
|
||||
FlowStateType.Succeed => ConnectionType.IsSucceed,
|
||||
FlowStateType.Fail => ConnectionType.IsFail,
|
||||
FlowStateType.Error => ConnectionType.IsError,
|
||||
_ => throw new Exception("非预期的枚举值")
|
||||
};
|
||||
var nextNodes = currentNode.SuccessorNodes[connection];
|
||||
// 不再执行
|
||||
break;
|
||||
}
|
||||
|
||||
var nextNodes = currentNode.SuccessorNodes[currentNode.NextOrientation];
|
||||
|
||||
// 将下一个节点集合中的所有节点逆序推入栈中
|
||||
for (int i = nextNodes.Count - 1; i >= 0; i--)
|
||||
@@ -148,12 +148,12 @@ namespace Serein.NodeFlow.Base
|
||||
result = func?.Invoke(md.ActingInstance, parameters);
|
||||
}
|
||||
}
|
||||
FlowState = FlowStateType.Succeed;
|
||||
NextOrientation = ConnectionType.IsSucceed;
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FlowState = FlowStateType.Error;
|
||||
NextOrientation = ConnectionType.IsError;
|
||||
RuningException = ex;
|
||||
}
|
||||
|
||||
@@ -184,23 +184,16 @@ namespace Serein.NodeFlow.Base
|
||||
object?[]? parameters = GetParameters(context, MethodDetails);
|
||||
flipflopContext = await ((Func<object, object[], Task<IFlipflopContext>>)md.MethodDelegate).Invoke(MethodDetails.ActingInstance, parameters);
|
||||
}
|
||||
|
||||
if (flipflopContext != null)
|
||||
if (flipflopContext == null)
|
||||
{
|
||||
FlowState = flipflopContext.State;
|
||||
if (flipflopContext.State == FlowStateType.Succeed)
|
||||
{
|
||||
result = flipflopContext.Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
throw new FlipflopException("没有返回上下文");
|
||||
}
|
||||
NextOrientation = flipflopContext.State.ToContentType();
|
||||
result = flipflopContext.Data;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FlowState = FlowStateType.Error;
|
||||
NextOrientation = ConnectionType.IsError;
|
||||
RuningException = ex;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user