2025-07-30 21:15:07 +08:00
|
|
|
|
using Serein.Library.Api;
|
2025-07-06 14:34:49 +08:00
|
|
|
|
using Serein.Library.Utils;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2025-07-07 20:40:24 +08:00
|
|
|
|
namespace Serein.Library
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 流程调用树,管理所有的调用节点
|
|
|
|
|
|
/// </summary>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public class FlowCallTree : IFlowCallTree
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
2025-07-07 20:40:24 +08:00
|
|
|
|
private readonly SortedDictionary<string, CallNode> _callNodes = new SortedDictionary<string,CallNode>();
|
2025-07-06 14:34:49 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 索引器,允许通过字符串索引访问CallNode
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="index"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public CallNode this[string index]
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
_callNodes.TryGetValue(index, out CallNode callNode);
|
|
|
|
|
|
return callNode;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
// 设置指定索引的值
|
2025-07-07 20:40:24 +08:00
|
|
|
|
_callNodes.Add(index, value);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加一个调用节点到流程调用树中
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="nodeGuid"></param>
|
|
|
|
|
|
/// <param name="action"></param>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public void AddCallNode(string nodeGuid, Action<IFlowContext> action)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
2025-07-07 20:40:24 +08:00
|
|
|
|
var node = new CallNode(nodeGuid, action);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
_callNodes[nodeGuid] = node;
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加一个调用节点到流程调用树中,使用异步函数
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="nodeGuid"></param>
|
|
|
|
|
|
/// <param name="func"></param>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public void AddCallNode(string nodeGuid, Func<IFlowContext, Task> func)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
2025-07-07 20:40:24 +08:00
|
|
|
|
var node = new CallNode(nodeGuid, func);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
_callNodes[nodeGuid] = node;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定Key的CallNode,如果不存在则返回null
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public CallNode Get(string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _callNodes.TryGetValue(key, out CallNode callNode) ? callNode : null;
|
|
|
|
|
|
}
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-07 20:40:24 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 调用节点,代表一个流程中的调用点,可以是一个Action或一个异步函数。
|
|
|
|
|
|
/// </summary>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public class CallNode
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2025-07-23 16:20:41 +08:00
|
|
|
|
private Func<IFlowContext, Task> taskFunc;
|
|
|
|
|
|
private Action<IFlowContext> action;
|
2025-07-06 14:34:49 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建一个新的调用节点,使用指定的节点Guid。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="nodeGuid"></param>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public CallNode(string nodeGuid)
|
|
|
|
|
|
{
|
|
|
|
|
|
Guid = nodeGuid;
|
|
|
|
|
|
Init();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建一个新的调用节点,使用指定的节点Guid和Action。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="nodeGuid"></param>
|
|
|
|
|
|
/// <param name="action"></param>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public CallNode(string nodeGuid, Action<IFlowContext> action)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
Guid = nodeGuid;
|
|
|
|
|
|
this.action = action;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
Init();
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建一个新的调用节点,使用指定的节点Guid和异步函数。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="nodeGuid"></param>
|
|
|
|
|
|
/// <param name="func"></param>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public CallNode(string nodeGuid, Func<IFlowContext, Task> func)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
Guid = nodeGuid;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
this.taskFunc = func;
|
2025-07-06 14:34:49 +08:00
|
|
|
|
Init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化调用节点,设置默认的子节点和后继节点字典。
|
|
|
|
|
|
/// </summary>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
private void Init()
|
|
|
|
|
|
{
|
2025-07-08 17:37:03 +08:00
|
|
|
|
//PreviousNodes = new Dictionary<ConnectionInvokeType, List<CallNode>>();
|
2025-07-06 14:34:49 +08:00
|
|
|
|
SuccessorNodes = new Dictionary<ConnectionInvokeType, List<CallNode>>();
|
|
|
|
|
|
foreach (ConnectionInvokeType ctType in NodeStaticConfig.ConnectionTypes)
|
|
|
|
|
|
{
|
2025-07-08 17:37:03 +08:00
|
|
|
|
//PreviousNodes[ctType] = new List<CallNode>();
|
2025-07-06 14:34:49 +08:00
|
|
|
|
SuccessorNodes[ctType] = new List<CallNode>();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
2025-07-29 14:25:31 +08:00
|
|
|
|
private enum ActionType
|
|
|
|
|
|
{
|
|
|
|
|
|
Action,
|
|
|
|
|
|
Task,
|
|
|
|
|
|
}
|
|
|
|
|
|
private ActionType actionType = ActionType.Action;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置调用节点的Action,表示该节点执行一个同步操作。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="action"></param>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public void SetAction(Action<IFlowContext> action)
|
2025-07-07 20:40:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.action = action;
|
2025-07-29 14:25:31 +08:00
|
|
|
|
actionType = ActionType.Action;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置调用节点的异步函数,表示该节点执行一个异步操作。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="taskFunc"></param>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public void SetAction(Func<IFlowContext, Task> taskFunc)
|
2025-07-07 20:40:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.taskFunc = taskFunc;
|
2025-07-29 14:25:31 +08:00
|
|
|
|
actionType = ActionType.Task;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-06 14:34:49 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 对应的节点
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string Guid { get; }
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
#if false
|
|
|
|
|
|
|
2025-07-06 14:34:49 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 不同分支的父节点(流程调用)
|
|
|
|
|
|
/// </summary>
|
2025-07-30 21:15:07 +08:00
|
|
|
|
public Dictionary<ConnectionInvokeType, List<CallNode>> PreviousNodes { get; private set; }
|
2025-07-06 14:34:49 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
#endif
|
2025-07-06 14:34:49 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 不同分支的子节点(流程调用)
|
|
|
|
|
|
/// </summary>
|
2025-07-08 17:37:03 +08:00
|
|
|
|
public Dictionary<ConnectionInvokeType, List<CallNode>> SuccessorNodes { get; private set; }
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 子节点数组,分为四个分支:上游、成功、失败、错误,每个分支最多支持16个子节点。
|
|
|
|
|
|
/// </summary>
|
2025-07-08 17:37:03 +08:00
|
|
|
|
public CallNode[][] ChildNodes { get; private set; } = new CallNode[][]
|
|
|
|
|
|
{
|
2025-07-29 14:25:31 +08:00
|
|
|
|
new CallNode[MaxChildNodeCount],
|
|
|
|
|
|
new CallNode[MaxChildNodeCount],
|
|
|
|
|
|
new CallNode[MaxChildNodeCount],
|
|
|
|
|
|
new CallNode[MaxChildNodeCount]
|
2025-07-08 17:37:03 +08:00
|
|
|
|
};
|
2025-07-29 14:25:31 +08:00
|
|
|
|
private const int MaxChildNodeCount = 16; // 每个分支最多支持16个子节点
|
2025-07-08 17:37:03 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定类型的子节点数量。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-08 17:37:03 +08:00
|
|
|
|
public int GetCount(ConnectionInvokeType type)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (type == ConnectionInvokeType.Upstream) return UpstreamNodeCount;
|
|
|
|
|
|
if (type == ConnectionInvokeType.IsSucceed) return IsSuccessorNodeCount;
|
|
|
|
|
|
if (type == ConnectionInvokeType.IsFail) return IsFailNodeCount;
|
|
|
|
|
|
if (type == ConnectionInvokeType.IsError) return IsErrorNodeCount;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2025-07-06 14:34:49 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取当前节点的子节点数量。
|
|
|
|
|
|
/// </summary>
|
2025-07-08 17:37:03 +08:00
|
|
|
|
public int UpstreamNodeCount { get; private set; } = 0;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取当前节点的成功后继子节点数量。
|
|
|
|
|
|
/// </summary>
|
2025-07-08 17:37:03 +08:00
|
|
|
|
public int IsSuccessorNodeCount { get; private set; } = 0;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取当前节点的失败后继子节点数量。
|
|
|
|
|
|
/// </summary>
|
2025-07-08 17:37:03 +08:00
|
|
|
|
public int IsFailNodeCount { get; private set; } = 0;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取当前节点的错误后继子节点数量。
|
|
|
|
|
|
/// </summary>
|
2025-07-08 17:37:03 +08:00
|
|
|
|
public int IsErrorNodeCount { get; private set; } = 0;
|
2025-07-06 14:34:49 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加一个上游子节点到当前节点。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="callNode"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public CallNode AddChildNodeUpstream(CallNode callNode)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
var connectionInvokeType = ConnectionInvokeType.Upstream;
|
2025-07-08 17:37:03 +08:00
|
|
|
|
ChildNodes[(int)connectionInvokeType][UpstreamNodeCount++] = callNode;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
SuccessorNodes[connectionInvokeType].Add(callNode);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2025-07-08 17:37:03 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加一个成功后继子节点到当前节点。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="callNode"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public CallNode AddChildNodeSucceed(CallNode callNode)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
2025-07-08 17:37:03 +08:00
|
|
|
|
ChildNodes[0][UpstreamNodeCount++] = callNode;
|
|
|
|
|
|
|
|
|
|
|
|
var connectionInvokeType = ConnectionInvokeType.IsSucceed;
|
|
|
|
|
|
ChildNodes[(int)connectionInvokeType][IsSuccessorNodeCount++] = callNode;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
SuccessorNodes[connectionInvokeType].Add(callNode);
|
|
|
|
|
|
|
2025-07-06 14:34:49 +08:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加一个失败后继子节点到当前节点。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="callNode"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public CallNode AddChildNodeFail(CallNode callNode)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
2025-07-07 20:40:24 +08:00
|
|
|
|
var connectionInvokeType = ConnectionInvokeType.IsFail;
|
2025-07-08 17:37:03 +08:00
|
|
|
|
ChildNodes[(int)connectionInvokeType][IsFailNodeCount++] = callNode;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
SuccessorNodes[connectionInvokeType].Add(callNode);
|
|
|
|
|
|
|
2025-07-06 14:34:49 +08:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加一个错误后继子节点到当前节点。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="callNode"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public CallNode AddChildNodeError(CallNode callNode)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
var connectionInvokeType = ConnectionInvokeType.IsError;
|
2025-07-08 17:37:03 +08:00
|
|
|
|
ChildNodes[(int)connectionInvokeType][IsErrorNodeCount++] = callNode;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
SuccessorNodes[connectionInvokeType].Add(callNode);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 调用
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="InvalidOperationException"></exception>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public async Task InvokeAsync(IFlowContext context, CancellationToken token)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (token.IsCancellationRequested)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-07-29 14:25:31 +08:00
|
|
|
|
if (actionType == ActionType.Action)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
2025-07-29 14:25:31 +08:00
|
|
|
|
action.Invoke(context);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
2025-07-29 14:25:31 +08:00
|
|
|
|
else if (actionType == ActionType.Task)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
2025-07-29 14:25:31 +08:00
|
|
|
|
await taskFunc.Invoke(context);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new InvalidOperationException($"生成了错误的CallNode。【{Guid}】");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
private static readonly ObjectPool<Stack<CallNode>> _stackPool = new ObjectPool<Stack<CallNode>>(() => new Stack<CallNode>());
|
2025-07-07 20:40:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-07-06 14:34:49 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 开始执行
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
|
/// <param name="token">流程运行</param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public async Task<FlowResult> StartFlowAsync(IFlowContext context, CancellationToken token)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
2025-07-30 21:15:07 +08:00
|
|
|
|
var stack = _stackPool.Allocate();
|
2025-07-06 14:34:49 +08:00
|
|
|
|
stack.Push(this);
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (token.IsCancellationRequested)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception($"流程执行被取消,未能获取到流程结果。");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 执行相关
|
|
|
|
|
|
// 从栈中弹出一个节点作为当前节点进行处理
|
|
|
|
|
|
var currentNode = stack.Pop();
|
|
|
|
|
|
context.NextOrientation = ConnectionInvokeType.None; // 重置上下文状态
|
|
|
|
|
|
FlowResult flowResult = null;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-07-29 14:25:31 +08:00
|
|
|
|
context.NextOrientation = ConnectionInvokeType.IsSucceed; // 默认执行成功
|
2025-07-06 14:34:49 +08:00
|
|
|
|
await currentNode.InvokeAsync(context, token);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2025-07-30 11:29:12 +08:00
|
|
|
|
flowResult = FlowResult.Fail(currentNode.Guid, context, ex.Message);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
context.Env.WriteLine(InfoType.ERROR, $"节点[{currentNode}]异常:" + ex);
|
|
|
|
|
|
context.NextOrientation = ConnectionInvokeType.IsError;
|
|
|
|
|
|
context.ExceptionOfRuning = ex;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 执行完成时更新栈
|
|
|
|
|
|
// 首先将指定类别后继分支的所有节点逆序推入栈中
|
|
|
|
|
|
var nextNodes = currentNode.SuccessorNodes[context.NextOrientation];
|
|
|
|
|
|
for (int index = nextNodes.Count - 1; index >= 0; index--)
|
|
|
|
|
|
{
|
2025-07-29 14:25:31 +08:00
|
|
|
|
var node = nextNodes[index];
|
|
|
|
|
|
context.SetPreviousNode(node.Guid, currentNode.Guid);
|
|
|
|
|
|
stack.Push(node);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 然后将指上游分支的所有节点逆序推入栈中
|
|
|
|
|
|
var upstreamNodes = currentNode.SuccessorNodes[ConnectionInvokeType.Upstream];
|
|
|
|
|
|
for (int index = upstreamNodes.Count - 1; index >= 0; index--)
|
|
|
|
|
|
{
|
2025-07-29 14:25:31 +08:00
|
|
|
|
var node = upstreamNodes[index];
|
|
|
|
|
|
context.SetPreviousNode(node.Guid, currentNode.Guid);
|
|
|
|
|
|
stack.Push(node);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 执行完成后检查
|
|
|
|
|
|
|
|
|
|
|
|
if (stack.Count == 0)
|
|
|
|
|
|
{
|
2025-07-30 21:15:07 +08:00
|
|
|
|
_stackPool.Free(stack);
|
2025-07-07 20:40:24 +08:00
|
|
|
|
flowResult = context.GetFlowData(currentNode.Guid);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
return flowResult; // 说明流程到了终点
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (context.RunState == RunState.Completion)
|
|
|
|
|
|
{
|
2025-07-07 20:40:24 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
_stackPool.Free(stack);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
context.Env.WriteLine(InfoType.INFO, $"流程执行到节点[{currentNode.Guid}]时提前结束,将返回当前执行结果。");
|
2025-07-29 14:25:31 +08:00
|
|
|
|
flowResult = context.GetFlowData(currentNode.Guid);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
return flowResult; // 流程执行完成,返回结果
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (token.IsCancellationRequested)
|
|
|
|
|
|
{
|
2025-07-30 21:15:07 +08:00
|
|
|
|
_stackPool.Free(stack);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
throw new Exception($"流程执行到节点[{currentNode.Guid}]时被取消,未能获取到流程结果。");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
2025-07-07 20:40:24 +08:00
|
|
|
|
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-07 20:40:24 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 流程调用树接口,提供获取CallNode的方法。
|
|
|
|
|
|
/// </summary>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public interface IFlowCallTree
|
|
|
|
|
|
{
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定Key的CallNode,如果不存在则返回null。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
CallNode Get(string key);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-06 14:34:49 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 轻量级流程控制器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class LightweightFlowControl : IFlowControl
|
|
|
|
|
|
{
|
2025-07-07 20:40:24 +08:00
|
|
|
|
private readonly IFlowCallTree flowCallTree;
|
|
|
|
|
|
private readonly IFlowEnvironment flowEnvironment;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 轻量级流程上下文池,使用对象池模式来管理流程上下文的创建和回收。
|
|
|
|
|
|
/// </summary>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public static Serein.Library.Utils.ObjectPool<IFlowContext> FlowContextPool { get; set; }
|
2025-07-06 14:34:49 +08:00
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 单例IOC容器,用于依赖注入和服务定位。
|
|
|
|
|
|
/// </summary>
|
2025-07-18 22:45:06 +08:00
|
|
|
|
public ISereinIOC IOC => throw new NotImplementedException();
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 轻量级流程控制器构造函数,接受流程调用树和流程环境作为参数。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="flowCallTree"></param>
|
|
|
|
|
|
/// <param name="flowEnvironment"></param>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public LightweightFlowControl(IFlowCallTree flowCallTree, IFlowEnvironment flowEnvironment)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
2025-07-07 20:40:24 +08:00
|
|
|
|
this.flowCallTree = flowCallTree;
|
|
|
|
|
|
this.flowEnvironment = flowEnvironment;
|
2025-07-23 16:20:41 +08:00
|
|
|
|
FlowContextPool = new Utils.ObjectPool<IFlowContext>(() =>
|
2025-07-08 17:37:03 +08:00
|
|
|
|
{
|
2025-07-23 16:20:41 +08:00
|
|
|
|
return new FlowContext(flowEnvironment);
|
2025-07-08 17:37:03 +08:00
|
|
|
|
});
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public Task<object> InvokeAsync(string apiGuid, Dictionary<string, object> dict)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public Task<TResult> InvokeAsync<TResult>(string apiGuid, Dictionary<string, object> dict)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-07 20:40:24 +08:00
|
|
|
|
|
|
|
|
|
|
//private readonly DefaultObjectPool<IDynamicContext> _stackPool = new DefaultObjectPool<IDynamicContext>(new DynamicContext(this));
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public async Task<TResult> StartFlowAsync<TResult>(string startNodeGuid)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
2025-07-23 16:20:41 +08:00
|
|
|
|
IFlowContext context = Serein.Library.LightweightFlowControl.FlowContextPool.Allocate();
|
2025-07-07 20:40:24 +08:00
|
|
|
|
CancellationTokenSource cts = new CancellationTokenSource();
|
2025-07-08 17:37:03 +08:00
|
|
|
|
FlowResult flowResult;
|
2025-07-07 20:40:24 +08:00
|
|
|
|
#if DEBUG
|
2025-07-08 17:37:03 +08:00
|
|
|
|
flowResult = await BenchmarkHelpers.BenchmarkAsync(async () =>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
var node = flowCallTree.Get(startNodeGuid);
|
|
|
|
|
|
var flowResult = await node.StartFlowAsync(context, cts.Token);
|
|
|
|
|
|
return flowResult;
|
|
|
|
|
|
});
|
|
|
|
|
|
#else
|
|
|
|
|
|
var node = flowCallTree.Get(startNodeGuid);
|
2025-07-08 17:37:03 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
flowResult = await node.StartFlowAsync(context, cts.Token);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (global::System.Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
context.Reset();
|
|
|
|
|
|
FlowContextPool.Free(context);
|
|
|
|
|
|
}
|
2025-07-07 20:40:24 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
cts?.Cancel();
|
|
|
|
|
|
cts?.Dispose();
|
|
|
|
|
|
if (flowResult.Value is TResult result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (flowResult is FlowResult && flowResult is TResult result2)
|
|
|
|
|
|
{
|
|
|
|
|
|
return result2;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentNullException($"类型转换失败,流程返回数据与泛型不匹配,当前返回类型为[{flowResult.Value.GetType().FullName}]。");
|
|
|
|
|
|
}
|
2025-07-06 14:34:49 +08:00
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public Task<bool> StartFlowAsync(string[] canvasGuids)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public Task<bool> ExitFlowAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 无须实现
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void ActivateFlipflopNode(string nodeGuid)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void MonitorObjectNotification(string nodeGuid, object monitorData, MonitorObjectEventArgs.ObjSourceType sourceType)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void TerminateFlipflopNode(string nodeGuid)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void TriggerInterrupt(string nodeGuid, string expression, InterruptTriggerEventArgs.InterruptTriggerType type)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void UseExternalIOC(ISereinIOC ioc)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
2025-07-18 22:45:06 +08:00
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-18 22:45:06 +08:00
|
|
|
|
public void UseExternalIOC(ISereinIOC ioc, Action<ISereinIOC> setDefultMemberOnReset = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-06 14:34:49 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 轻量级流程环境事件实现
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class LightweightFlowEnvironmentEvent : IFlowEnvironmentEvent
|
|
|
|
|
|
{
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event LoadDllHandler DllLoad;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event ProjectLoadedHandler ProjectLoaded;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event ProjectSavingHandler ProjectSaving;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event NodeConnectChangeHandler NodeConnectChanged;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event CanvasCreateHandler CanvasCreated;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event CanvasRemoveHandler CanvasRemoved;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event NodeCreateHandler NodeCreated;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event NodeRemoveHandler NodeRemoved;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event NodePlaceHandler NodePlace;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event NodeTakeOutHandler NodeTakeOut;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event StartNodeChangeHandler StartNodeChanged;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event FlowRunCompleteHandler FlowRunComplete;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event MonitorObjectChangeHandler MonitorObjectChanged;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event NodeInterruptStateChangeHandler NodeInterruptStateChanged;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event ExpInterruptTriggerHandler InterruptTriggered;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event IOCMembersChangedHandler IOCMembersChanged;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event NodeLocatedHandler NodeLocated;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public event EnvOutHandler EnvOutput;
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnDllLoad(LoadDllEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
DllLoad?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnProjectLoaded(ProjectLoadedEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
ProjectLoaded?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnProjectSaving(ProjectSavingEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
ProjectSaving?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnNodeConnectChanged(NodeConnectChangeEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeConnectChanged?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnCanvasCreated(CanvasCreateEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
CanvasCreated?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnCanvasRemoved(CanvasRemoveEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
CanvasRemoved?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnNodeCreated(NodeCreateEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeCreated?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnNodeRemoved(NodeRemoveEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeRemoved?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnNodePlace(NodePlaceEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodePlace?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnNodeTakeOut(NodeTakeOutEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeTakeOut?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnStartNodeChanged(StartNodeChangeEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
StartNodeChanged?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnFlowRunComplete(FlowEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowRunComplete?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnMonitorObjectChanged(MonitorObjectEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
MonitorObjectChanged?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnNodeInterruptStateChanged(NodeInterruptStateChangeEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeInterruptStateChanged?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnInterruptTriggered(InterruptTriggerEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
InterruptTriggered?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnIOCMembersChanged(IOCMembersChangedEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
IOCMembersChanged?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnNodeLocated(NodeLocatedEventArgs eventArgs)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeLocated?.Invoke(eventArgs);
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void OnEnvOutput(InfoType type, string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
EnvOutput?.Invoke(type, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 轻量级流程环境实现
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class LightweightFlowEnvironment : IFlowEnvironment
|
|
|
|
|
|
{
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 轻量级流程环境构造函数,接受一个流程环境事件接口。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="lightweightFlowEnvironmentEvent"></param>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public LightweightFlowEnvironment(IFlowEnvironmentEvent lightweightFlowEnvironmentEvent)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Event = lightweightFlowEnvironmentEvent;
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
|
2025-07-31 23:59:31 +08:00
|
|
|
|
public void WriteLine(InfoType type, string message, InfoClass @class = InfoClass.Debug)
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public ISereinIOC IOC => throw new NotImplementedException();
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public IFlowEdit FlowEdit => throw new NotImplementedException();
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public IFlowControl FlowControl => throw new NotImplementedException();
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-07 20:40:24 +08:00
|
|
|
|
public IFlowEnvironmentEvent Event { get; private set; }
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public string EnvName => throw new NotImplementedException();
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public string ProjectFileLocation => throw new NotImplementedException();
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-28 12:16:29 +08:00
|
|
|
|
public bool _IsGlobalInterrupt => throw new NotImplementedException();
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public bool IsControlRemoteEnv => throw new NotImplementedException();
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public InfoClass InfoClass { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public RunState FlowState { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public IFlowEnvironment CurrentEnv => throw new NotImplementedException();
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public UIContextOperation UIContextOperation => throw new NotImplementedException();
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/* public Task<(bool, RemoteMsgUtil)> ConnectRemoteEnv(string addres, int port, string token)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}*/
|
|
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void ExitRemoteEnv()
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public Task<FlowEnvInfo> GetEnvInfoAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public SereinProjectData GetProjectInfoAsync()
|
2025-07-06 14:34:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void LoadAllNativeLibraryOfRuning(string path, bool isRecurrence = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void LoadLibrary(string dllPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public bool LoadNativeLibraryOfRuning(string file)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void LoadProject(string filePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public Task LoadProjetAsync(string filePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public Task NotificationNodeValueChangeAsync(string nodeGuid, string path, object value)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void SaveProject()
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void SetUIContextOperation(UIContextOperation uiContextOperation)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public Task StartRemoteServerAsync(int port = 7525)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public void StopRemoteServer()
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public bool TryGetDelegateDetails(string assemblyName, string methodName, out DelegateDetails del)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public bool TryGetMethodDetailsInfo(string assemblyName, string methodName, out MethodDetailsInfo mdInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public bool TryGetNodeModel(string nodeGuid, out IFlowNode nodeModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <inheritdoc/>
|
2025-07-06 14:34:49 +08:00
|
|
|
|
public bool TryUnloadLibrary(string assemblyFullName)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|