mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
修复了全局节点连接异常异常。
This commit is contained in:
@@ -58,3 +58,5 @@ namespace Serein.Library
|
||||
public double ScaleY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -173,34 +173,6 @@ namespace Serein.Library
|
||||
dictPreviousNodes.AddOrUpdate(currentNodeModel, (_) => PreviousNode, (o, n) => PreviousNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 忽略处理该节点流程
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public void IgnoreFlowHandle(string node)
|
||||
{
|
||||
dictIgnoreNodeFlow.AddOrUpdate(node, (o) => true, (o, n) => true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取此次流程处理状态
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
/// <returns></returns>
|
||||
public bool GetIgnodeFlowStateUpload(string node)
|
||||
{
|
||||
return dictIgnoreNodeFlow.TryGetValue(node, out var state) ? state : false;
|
||||
}
|
||||
/// <summary>
|
||||
/// 恢复流程处理状态
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
/// <returns></returns>
|
||||
public void RecoverIgnodeFlowStateUpload(string node)
|
||||
{
|
||||
dictIgnoreNodeFlow.AddOrUpdate(node, (o) => false, (o, n) => false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前节点的运行时上一节点
|
||||
/// </summary>
|
||||
@@ -242,7 +214,6 @@ namespace Serein.Library
|
||||
/// <param name="flowData">新的数据</param>
|
||||
public void AddOrUpdateFlowData(string nodeModel, FlowResult flowData)
|
||||
{
|
||||
// this.dictNodeFlowData.TryGetValue(nodeGuid, out var oldFlowData);
|
||||
dictNodeFlowData.AddOrUpdate(nodeModel, _ => flowData, (o,n ) => flowData);
|
||||
}
|
||||
|
||||
@@ -274,10 +245,6 @@ namespace Serein.Library
|
||||
throw new InvalidOperationException($"透传{nodeModel}节点数据时发生异常:上一节点不存在数据");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始
|
||||
/// </summary>
|
||||
|
||||
/// <summary>
|
||||
/// 重置
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -23,7 +24,7 @@ namespace Serein.Library
|
||||
/// <summary>
|
||||
/// 流程返回值的包装
|
||||
/// </summary>
|
||||
public class FlowResult
|
||||
public sealed class FlowResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化返回值
|
||||
|
||||
@@ -151,14 +151,21 @@ namespace Serein.Library
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private enum ActionType
|
||||
{
|
||||
Action,
|
||||
Task,
|
||||
}
|
||||
private ActionType actionType = ActionType.Action;
|
||||
public void SetAction(Action<IFlowContext> action)
|
||||
{
|
||||
this.action = action;
|
||||
actionType = ActionType.Action;
|
||||
}
|
||||
public void SetAction(Func<IFlowContext, Task> taskFunc)
|
||||
{
|
||||
this.taskFunc = taskFunc;
|
||||
actionType = ActionType.Task;
|
||||
}
|
||||
|
||||
|
||||
@@ -177,12 +184,14 @@ namespace Serein.Library
|
||||
public Dictionary<ConnectionInvokeType, List<CallNode>> SuccessorNodes { get; private set; }
|
||||
public CallNode[][] ChildNodes { get; private set; } = new CallNode[][]
|
||||
{
|
||||
new CallNode[32],
|
||||
new CallNode[32],
|
||||
new CallNode[32],
|
||||
new CallNode[32]
|
||||
new CallNode[MaxChildNodeCount],
|
||||
new CallNode[MaxChildNodeCount],
|
||||
new CallNode[MaxChildNodeCount],
|
||||
new CallNode[MaxChildNodeCount]
|
||||
};
|
||||
private const int MaxChildNodeCount = 16; // 每个分支最多支持16个子节点
|
||||
|
||||
|
||||
public int GetCount(ConnectionInvokeType type)
|
||||
{
|
||||
if (type == ConnectionInvokeType.Upstream) return UpstreamNodeCount;
|
||||
@@ -245,13 +254,13 @@ namespace Serein.Library
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (action is not null)
|
||||
if (actionType == ActionType.Action)
|
||||
{
|
||||
action(context);
|
||||
action.Invoke(context);
|
||||
}
|
||||
else if (taskFunc is not null)
|
||||
else if (actionType == ActionType.Task)
|
||||
{
|
||||
await taskFunc(context);
|
||||
await taskFunc.Invoke(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -286,11 +295,8 @@ namespace Serein.Library
|
||||
FlowResult flowResult = null;
|
||||
try
|
||||
{
|
||||
context.NextOrientation = ConnectionInvokeType.IsSucceed; // 默认执行成功
|
||||
await currentNode.InvokeAsync(context, token);
|
||||
if (context.NextOrientation == ConnectionInvokeType.None) // 没有手动设置时,进行自动设置
|
||||
{
|
||||
context.NextOrientation = ConnectionInvokeType.IsSucceed;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -306,17 +312,18 @@ namespace Serein.Library
|
||||
var nextNodes = currentNode.SuccessorNodes[context.NextOrientation];
|
||||
for (int index = nextNodes.Count - 1; index >= 0; index--)
|
||||
{
|
||||
//if (!ignodeState)
|
||||
context.SetPreviousNode(nextNodes[index].Guid, currentNode.Guid);
|
||||
stack.Push(nextNodes[index]);
|
||||
var node = nextNodes[index];
|
||||
context.SetPreviousNode(node.Guid, currentNode.Guid);
|
||||
stack.Push(node);
|
||||
}
|
||||
|
||||
// 然后将指上游分支的所有节点逆序推入栈中
|
||||
var upstreamNodes = currentNode.SuccessorNodes[ConnectionInvokeType.Upstream];
|
||||
for (int index = upstreamNodes.Count - 1; index >= 0; index--)
|
||||
{
|
||||
context.SetPreviousNode(upstreamNodes[index].Guid, currentNode.Guid);
|
||||
stack.Push(upstreamNodes[index]);
|
||||
var node = upstreamNodes[index];
|
||||
context.SetPreviousNode(node.Guid, currentNode.Guid);
|
||||
stack.Push(node);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -334,7 +341,7 @@ namespace Serein.Library
|
||||
|
||||
_stackPool.Return(stack);
|
||||
context.Env.WriteLine(InfoType.INFO, $"流程执行到节点[{currentNode.Guid}]时提前结束,将返回当前执行结果。");
|
||||
flowResult = context.GetFlowData(currentNode.Guid); _stackPool.Return(stack);
|
||||
flowResult = context.GetFlowData(currentNode.Guid);
|
||||
return flowResult; // 流程执行完成,返回结果
|
||||
}
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ namespace Serein.Library
|
||||
MethodName = this.MethodName, // 拷贝
|
||||
MethodLockName = this.MethodLockName, // 拷贝
|
||||
ParamsArgIndex = this.ParamsArgIndex, // 拷贝
|
||||
ParameterDetailss = this.ParameterDetailss?.Select(p => p?.CloneOfModel(nodeModel)).ToArray(), // 拷贝属于节点方法的新入参描述
|
||||
ParameterDetailss = this.ParameterDetailss?.Select(p => p?.CloneOfModel(nodeModel)).ToArray() , // 拷贝属于节点方法的新入参描述
|
||||
IsAsync = this.IsAsync, // 拷贝
|
||||
IsStatic = this.IsStatic, // 拷贝
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user