mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
改写NodeModelBase类,使其继承Serein.Library.Api下的IFlowNode接口,而实现类迁移到NodeModel项目,方便后续节点运行逻辑修改时不用重新编译类库。
This commit is contained in:
@@ -301,7 +301,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// 环境加载的节点集合
|
||||
/// Node Guid - Node Model
|
||||
/// </summary>
|
||||
private Dictionary<string, NodeModelBase> NodeModels { get; } = [];
|
||||
private Dictionary<string, IFlowNode> NodeModels { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 运行环境加载的画布集合
|
||||
@@ -746,7 +746,7 @@ namespace Serein.NodeFlow.Env
|
||||
sb.AppendLine();
|
||||
for (int i = 0; i < groupedNodes.Length; i++)
|
||||
{
|
||||
NodeModelBase? node = groupedNodes[i];
|
||||
IFlowNode? node = groupedNodes[i];
|
||||
sb.AppendLine($"{i} => {node.Guid}");
|
||||
}
|
||||
SereinEnv.WriteLine(InfoType.ERROR, $"无法卸载[{assemblyName}]程序集,因为这些节点依赖于此程序集:{sb.ToString()}");
|
||||
@@ -1047,7 +1047,7 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
return Task.FromResult<NodeInfo>(null);
|
||||
}
|
||||
NodeModelBase? nodeModel;
|
||||
IFlowNode? nodeModel;
|
||||
if (methodDetailsInfo is null
|
||||
|| string.IsNullOrEmpty(methodDetailsInfo.AssemblyName)
|
||||
|| string.IsNullOrEmpty(methodDetailsInfo.MethodName))
|
||||
@@ -1097,7 +1097,7 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
if (nodeModel.ContainerNode is INodeContainer tmpContainer)
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.WARN, $"节点放置失败,节点[{nodeGuid}]已经放置于容器节点[{((NodeModelBase)tmpContainer).Guid}]");
|
||||
SereinEnv.WriteLine(InfoType.WARN, $"节点放置失败,节点[{nodeGuid}]已经放置于容器节点[{((IFlowNode)tmpContainer).Guid}]");
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
@@ -1183,7 +1183,7 @@ namespace Serein.NodeFlow.Env
|
||||
var pCType = pnc.Key; // 连接类型
|
||||
for (int i = 0; i < pnc.Value.Count; i++)
|
||||
{
|
||||
NodeModelBase? pNode = pnc.Value[i];
|
||||
IFlowNode? pNode = pnc.Value[i];
|
||||
pNode.SuccessorNodes[pCType].Remove(remoteNode);
|
||||
|
||||
UIContextOperation?.Invoke(() => OnNodeConnectChange?.Invoke(new NodeConnectChangeEventArgs(
|
||||
@@ -1210,7 +1210,7 @@ namespace Serein.NodeFlow.Env
|
||||
var connectionType = snc.Key; // 连接类型
|
||||
for (int i = 0; i < snc.Value.Count; i++)
|
||||
{
|
||||
NodeModelBase? toNode = snc.Value[i];
|
||||
IFlowNode? toNode = snc.Value[i];
|
||||
|
||||
await RemoteConnectAsync(canvasGuid, remoteNode, toNode, connectionType);
|
||||
|
||||
@@ -1605,7 +1605,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <param name="nodeGuid">节点Guid</param>
|
||||
/// <returns>节点Model</returns>
|
||||
/// <exception cref="ArgumentNullException">无法获取节点、Guid/节点为null时报错</exception>
|
||||
public bool TryGetNodeModel(string nodeGuid,out NodeModelBase nodeModel)
|
||||
public bool TryGetNodeModel(string nodeGuid,out IFlowNode nodeModel)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeGuid))
|
||||
{
|
||||
@@ -1793,7 +1793,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <param name="toNodeGuid">目标节点Model</param>
|
||||
/// <param name="connectionType">连接关系</param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private async Task<bool> RemoteConnectAsync(string canvasGuid, NodeModelBase fromNode, NodeModelBase toNode, ConnectionInvokeType connectionType)
|
||||
private async Task<bool> RemoteConnectAsync(string canvasGuid, IFlowNode fromNode, IFlowNode toNode, ConnectionInvokeType connectionType)
|
||||
{
|
||||
if (!FlowCanvass.ContainsKey(canvasGuid))
|
||||
{
|
||||
@@ -1823,7 +1823,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <param name="toNodeGuid">目标节点Model</param>
|
||||
/// <param name="connectionType">连接关系</param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private async Task<bool> RemoteConnectAsync(string canvasGuid, NodeModelBase fromNode, NodeModelBase toNode, int argIndex)
|
||||
private async Task<bool> RemoteConnectAsync(string canvasGuid, IFlowNode fromNode, IFlowNode toNode, int argIndex)
|
||||
{
|
||||
if (!FlowCanvass.ContainsKey(canvasGuid))
|
||||
{
|
||||
@@ -1856,7 +1856,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// 创建节点
|
||||
/// </summary>
|
||||
/// <param name="nodeBase"></param>
|
||||
private bool TryAddNode(NodeModelBase nodeModel)
|
||||
private bool TryAddNode(IFlowNode nodeModel)
|
||||
{
|
||||
nodeModel.Guid ??= Guid.NewGuid().ToString();
|
||||
NodeModels.TryAdd(nodeModel.Guid, nodeModel);
|
||||
@@ -1882,8 +1882,8 @@ namespace Serein.NodeFlow.Env
|
||||
/// <param name="fromNodeJunctionType">发起连接节点的控制点类型</param>
|
||||
/// <param name="toNodeJunctionType">被连接节点的控制点类型</param>
|
||||
/// <returns></returns>
|
||||
public static (JunctionOfConnectionType,bool) CheckConnect(NodeModelBase fromNode,
|
||||
NodeModelBase toNode,
|
||||
public static (JunctionOfConnectionType,bool) CheckConnect(IFlowNode fromNode,
|
||||
IFlowNode toNode,
|
||||
JunctionType fromNodeJunctionType,
|
||||
JunctionType toNodeJunctionType)
|
||||
{
|
||||
@@ -1947,7 +1947,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <param name="fromNode">起始节点</param>
|
||||
/// <param name="toNode">目标节点</param>
|
||||
/// <param name="invokeType">连接关系</param>
|
||||
private bool ConnectInvokeOfNode(string canvasGuid, NodeModelBase fromNode, NodeModelBase toNode, ConnectionInvokeType invokeType)
|
||||
private bool ConnectInvokeOfNode(string canvasGuid, IFlowNode fromNode, IFlowNode toNode, ConnectionInvokeType invokeType)
|
||||
{
|
||||
if (fromNode.ControlType == NodeControlType.FlowCall)
|
||||
{
|
||||
@@ -2065,8 +2065,8 @@ namespace Serein.NodeFlow.Env
|
||||
/// <param name="argIndex"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> ConnectArgSourceOfNodeAsync(string canvasGuid,
|
||||
NodeModelBase fromNode,
|
||||
NodeModelBase toNode,
|
||||
IFlowNode fromNode,
|
||||
IFlowNode toNode,
|
||||
ConnectionArgSourceType connectionArgSourceType,
|
||||
int argIndex)
|
||||
{
|
||||
@@ -2127,7 +2127,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
/// <param name="cavnasModel">节点所在的画布</param>
|
||||
/// <param name="newStartNode">起始节点</param>
|
||||
private void SetStartNode(FlowCanvasDetails cavnasModel, NodeModelBase newStartNode)
|
||||
private void SetStartNode(FlowCanvasDetails cavnasModel, IFlowNode newStartNode)
|
||||
{
|
||||
var oldNodeGuid = cavnasModel.StartNode?.Guid;
|
||||
/*if(TryGetNodeModel(oldNodeGuid, out var newStartNodeModel))
|
||||
|
||||
@@ -560,7 +560,7 @@ namespace Serein.NodeFlow.Env
|
||||
currentFlowEnvironment.SetUIContextOperation(uiContextOperation);
|
||||
}
|
||||
|
||||
public bool TryGetNodeModel(string nodeGuid, out NodeModelBase nodeModel)
|
||||
public bool TryGetNodeModel(string nodeGuid, out IFlowNode nodeModel)
|
||||
{
|
||||
return currentFlowEnvironment.TryGetNodeModel(nodeGuid, out nodeModel);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// 环境加载的节点集合
|
||||
/// Node Guid - Node Model
|
||||
/// </summary>
|
||||
private Dictionary<string, NodeModelBase> NodeModels { get; } = [];
|
||||
private Dictionary<string, IFlowNode> NodeModels { get; } = [];
|
||||
|
||||
public event LoadDllHandler OnDllLoad;
|
||||
public event ProjectLoadedHandler OnProjectLoaded;
|
||||
@@ -1167,21 +1167,21 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
#region 私有方法
|
||||
|
||||
private NodeModelBase? GuidToModel(string nodeGuid)
|
||||
private IFlowNode? GuidToModel(string nodeGuid)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeGuid))
|
||||
{
|
||||
//throw new ArgumentNullException("not contains - Guid没有对应节点:" + (nodeGuid));
|
||||
return null;
|
||||
}
|
||||
if (!NodeModels.TryGetValue(nodeGuid, out NodeModelBase? nodeModel) || nodeModel is null)
|
||||
if (!NodeModels.TryGetValue(nodeGuid, out IFlowNode? nodeModel) || nodeModel is null)
|
||||
{
|
||||
//throw new ArgumentNullException("null - Guid存在对应节点,但节点为null:" + (nodeGuid));
|
||||
return null;
|
||||
}
|
||||
return nodeModel;
|
||||
}
|
||||
private bool TryAddNode(NodeModelBase nodeModel)
|
||||
private bool TryAddNode(IFlowNode nodeModel)
|
||||
{
|
||||
NodeModels[nodeModel.Guid] = nodeModel;
|
||||
return true;
|
||||
@@ -1268,7 +1268,7 @@ namespace Serein.NodeFlow.Env
|
||||
#region 确定节点之间的方法调用关系
|
||||
foreach (var nodeInfo in nodeInfos)
|
||||
{
|
||||
if (!NodeModels.TryGetValue(nodeInfo.Guid, out NodeModelBase? fromNode))
|
||||
if (!NodeModels.TryGetValue(nodeInfo.Guid, out IFlowNode? fromNode))
|
||||
{
|
||||
// 不存在对应的起始节点
|
||||
continue;
|
||||
@@ -1279,13 +1279,13 @@ namespace Serein.NodeFlow.Env
|
||||
(ConnectionInvokeType.IsError, nodeInfo.ErrorNodes),
|
||||
(ConnectionInvokeType.Upstream, nodeInfo.UpstreamNodes)];
|
||||
|
||||
List<(ConnectionInvokeType, NodeModelBase[])> fromNodes = allToNodes.Where(info => info.guids.Length > 0)
|
||||
List<(ConnectionInvokeType, IFlowNode[])> fromNodes = allToNodes.Where(info => info.guids.Length > 0)
|
||||
.Select(info => (info.connectionType,
|
||||
info.guids.Where(guid => NodeModels.ContainsKey(guid)).Select(guid => NodeModels[guid])
|
||||
.ToArray()))
|
||||
.ToList();
|
||||
// 遍历每种类型的节点分支(四种)
|
||||
foreach ((ConnectionInvokeType connectionType, NodeModelBase[] toNodes) item in fromNodes)
|
||||
foreach ((ConnectionInvokeType connectionType, IFlowNode[] toNodes) item in fromNodes)
|
||||
{
|
||||
// 遍历当前类型分支的节点(确认连接关系)
|
||||
foreach (var toNode in item.toNodes)
|
||||
@@ -1346,7 +1346,7 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
|
||||
|
||||
public bool TryGetNodeModel(string nodeGuid, out NodeModelBase nodeModel)
|
||||
public bool TryGetNodeModel(string nodeGuid, out IFlowNode nodeModel)
|
||||
{
|
||||
this.WriteLine(InfoType.INFO, "远程环境尚未实现的接口:TryGetNodeModel");
|
||||
nodeModel = null;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Serein.NodeFlow
|
||||
/// <param name="methodDetails">方法描述</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static NodeModelBase CreateNode(IFlowEnvironment env, NodeControlType nodeControlType,
|
||||
public static IFlowNode CreateNode(IFlowEnvironment env, NodeControlType nodeControlType,
|
||||
MethodDetails? methodDetails = null)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Serein.NodeFlow
|
||||
|
||||
// 生成实例
|
||||
var nodeObj = Activator.CreateInstance(nodeMVVM.ModelType, env);
|
||||
if (nodeObj is not NodeModelBase nodeModel)
|
||||
if (nodeObj is not IFlowNode nodeModel)
|
||||
{
|
||||
throw new Exception($"无法创建目标节点类型的实例[{nodeControlType}]");
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Serein.NodeFlow
|
||||
public async Task<bool> RunAsync(CancellationToken token)
|
||||
{
|
||||
#region 注册所有节点所属的类的类型,如果注册失败则退出
|
||||
List<NodeModelBase> nodes = new List<NodeModelBase>();
|
||||
List<IFlowNode> nodes = new List<IFlowNode>();
|
||||
foreach (var item in WorkOptions.Flows.Values)
|
||||
{
|
||||
var temp = item.GetNodes();
|
||||
@@ -85,7 +85,7 @@ namespace Serein.NodeFlow
|
||||
var flowNodes = flow.GetNodes();
|
||||
|
||||
// 找到流程的起始节点,开始运行
|
||||
NodeModelBase startNode = flow.GetStartNode();
|
||||
IFlowNode startNode = flow.GetStartNode();
|
||||
// 是否后台运行当前画布流程
|
||||
if (flow.IsTaskAsync)
|
||||
{
|
||||
@@ -110,7 +110,7 @@ namespace Serein.NodeFlow
|
||||
/// 初始化节点所需的所有类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool RegisterAllType(List<NodeModelBase> nodes)
|
||||
private bool RegisterAllType(List<IFlowNode> nodes)
|
||||
{
|
||||
var env = WorkOptions.Environment;
|
||||
|
||||
@@ -248,7 +248,7 @@ namespace Serein.NodeFlow
|
||||
/// </summary>
|
||||
/// <param name="startNode"></param>
|
||||
/// <returns></returns>
|
||||
private async Task CallStartNode(NodeModelBase startNode)
|
||||
private async Task CallStartNode(IFlowNode startNode)
|
||||
{
|
||||
var pool = WorkOptions.FlowContextPool;
|
||||
var token = WorkOptions.CancellationTokenSource.Token;
|
||||
@@ -268,7 +268,7 @@ namespace Serein.NodeFlow
|
||||
/// <param name="env"></param>
|
||||
/// <param name="startNode"></param>
|
||||
/// <returns></returns>
|
||||
public async Task StartFlowInSelectNodeAsync(IFlowEnvironment env, NodeModelBase startNode)
|
||||
public async Task StartFlowInSelectNodeAsync(IFlowEnvironment env, IFlowNode startNode)
|
||||
{
|
||||
var pool = WorkOptions.FlowContextPool;
|
||||
var context = pool.Allocate();
|
||||
|
||||
@@ -20,12 +20,12 @@ namespace Serein.NodeFlow
|
||||
/// <summary>
|
||||
/// 流程起始节点
|
||||
/// </summary>
|
||||
public Func<NodeModelBase> GetStartNode { get; set; }
|
||||
public Func<IFlowNode> GetStartNode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前画布流程的所有节点
|
||||
/// </summary>
|
||||
public Func<List<NodeModelBase>> GetNodes { get; set; }
|
||||
public Func<List<IFlowNode>> GetNodes { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
157
NodeFlow/Model/NodeModelBaseData.cs
Normal file
157
NodeFlow/Model/NodeModelBaseData.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.NodeGenerator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Net.Mime;
|
||||
using System.Threading;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 节点基类(数据)
|
||||
/// </summary>
|
||||
[NodeProperty(ValuePath = NodeValuePath.Node)]
|
||||
public abstract partial class NodeModelBase : IFlowNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 节点运行环境
|
||||
/// </summary>
|
||||
[PropertyInfo(IsProtection = true)]
|
||||
private IFlowEnvironment _env;
|
||||
|
||||
/// <summary>
|
||||
/// 标识节点对象全局唯一
|
||||
/// </summary>
|
||||
[PropertyInfo(IsProtection = true)]
|
||||
private string _guid;
|
||||
|
||||
/// <summary>
|
||||
/// 描述节点对应的控件类型
|
||||
/// </summary>
|
||||
[PropertyInfo(IsProtection = true)]
|
||||
private NodeControlType _controlType;
|
||||
|
||||
/// <summary>
|
||||
/// 所属画布
|
||||
/// </summary>
|
||||
[PropertyInfo(IsProtection = true)]
|
||||
private FlowCanvasDetails _canvasDetails ;
|
||||
|
||||
/// <summary>
|
||||
/// 在画布中的位置
|
||||
/// </summary>
|
||||
[PropertyInfo(IsProtection = true)]
|
||||
private PositionOfUI _position ;
|
||||
|
||||
/// <summary>
|
||||
/// 显示名称
|
||||
/// </summary>
|
||||
[PropertyInfo]
|
||||
private string _displayName;
|
||||
|
||||
/// <summary>
|
||||
/// 是否公开
|
||||
/// </summary>
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
private bool _isPublic;
|
||||
|
||||
/* /// <summary>
|
||||
/// 是否保护参数
|
||||
/// </summary>
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
private bool _isProtectionParameter;*/
|
||||
|
||||
/// <summary>
|
||||
/// 附加的调试功能
|
||||
/// </summary>
|
||||
[PropertyInfo(IsProtection = true)]
|
||||
private NodeDebugSetting _debugSetting ;
|
||||
|
||||
/// <summary>
|
||||
/// 方法描述。包含参数信息。不包含Method与委托,如若需要调用对应的方法,需要通过MethodName从环境中获取委托进行调用。
|
||||
/// </summary>
|
||||
[PropertyInfo]
|
||||
private MethodDetails _methodDetails ;
|
||||
}
|
||||
|
||||
|
||||
public abstract partial class NodeModelBase : IDynamicFlowNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否为基础节点
|
||||
/// </summary>
|
||||
public virtual bool IsBase { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 可以放置多少个节点
|
||||
/// </summary>
|
||||
public virtual int MaxChildrenCount { get; } = 0;
|
||||
|
||||
public NodeModelBase(IFlowEnvironment environment)
|
||||
{
|
||||
PreviousNodes = new Dictionary<ConnectionInvokeType, List<IFlowNode>>();
|
||||
SuccessorNodes = new Dictionary<ConnectionInvokeType, List<IFlowNode>>();
|
||||
foreach (ConnectionInvokeType ctType in NodeStaticConfig.ConnectionTypes)
|
||||
{
|
||||
PreviousNodes[ctType] = new List<IFlowNode>();
|
||||
SuccessorNodes[ctType] = new List<IFlowNode>();
|
||||
}
|
||||
ChildrenNode = new List<IFlowNode>();
|
||||
DebugSetting = new NodeDebugSetting(this);
|
||||
this.Env = environment;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 不同分支的父节点(流程调用)
|
||||
/// </summary>
|
||||
public Dictionary<ConnectionInvokeType, List<IFlowNode>> PreviousNodes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 不同分支的子节点(流程调用)
|
||||
/// </summary>
|
||||
public Dictionary<ConnectionInvokeType, List<IFlowNode>> SuccessorNodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 该节点的容器节点
|
||||
/// </summary>
|
||||
public IFlowNode ContainerNode { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 该节点的子项节点(如果该节点是容器节点,那就会有这个参数)
|
||||
/// </summary>
|
||||
public List<IFlowNode> ChildrenNode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点公开状态发生改变
|
||||
/// </summary>
|
||||
partial void OnIsPublicChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
// 公开节点
|
||||
if (!CanvasDetails.PublicNodes.Contains(this))
|
||||
{
|
||||
CanvasDetails.PublicNodes.Add(this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 取消公开
|
||||
if (CanvasDetails.PublicNodes.Contains(this))
|
||||
{
|
||||
CanvasDetails.PublicNodes.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
151
NodeFlow/Model/NodeModelBaseFunc.cs
Normal file
151
NodeFlow/Model/NodeModelBaseFunc.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.Library.Utils.SereinExpression;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 节点基类
|
||||
/// </summary>
|
||||
public abstract partial class NodeModelBase : IDynamicFlowNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体节点创建完成后调用的方法,调用时间早于 LoadInfo() 方法
|
||||
/// </summary>
|
||||
public virtual void OnCreating()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存自定义信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual NodeInfo SaveCustomData(NodeInfo nodeInfo)
|
||||
{
|
||||
return nodeInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载自定义数据
|
||||
/// </summary>
|
||||
/// <param name="nodeInfo"></param>
|
||||
public virtual void LoadCustomData(NodeInfo nodeInfo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除该节点
|
||||
/// </summary>
|
||||
public virtual void Remove()
|
||||
{
|
||||
if (this.DebugSetting.CancelInterrupt != null)
|
||||
{
|
||||
this.DebugSetting.CancelInterrupt?.Invoke();
|
||||
}
|
||||
|
||||
if (this.IsPublic)
|
||||
{
|
||||
this.CanvasDetails.PublicNodes.Remove(this);
|
||||
}
|
||||
|
||||
this.DebugSetting.NodeModel = null;
|
||||
this.DebugSetting = null;
|
||||
if(this.MethodDetails is not null)
|
||||
{
|
||||
if (this.MethodDetails.ParameterDetailss != null)
|
||||
{
|
||||
foreach (var pd in this.MethodDetails.ParameterDetailss)
|
||||
{
|
||||
pd.DataValue = null;
|
||||
pd.Items = null;
|
||||
pd.NodeModel = null;
|
||||
pd.ExplicitType = null;
|
||||
pd.DataType = null;
|
||||
pd.Name = null;
|
||||
pd.ArgDataSourceNodeGuid = null;
|
||||
pd.InputType = ParameterValueInputType.Input;
|
||||
}
|
||||
}
|
||||
this.MethodDetails.ParameterDetailss = null;
|
||||
this.MethodDetails.NodeModel = null;
|
||||
this.MethodDetails.ReturnType = null;
|
||||
this.MethodDetails.ActingInstanceType = null;
|
||||
this.MethodDetails = null;
|
||||
}
|
||||
|
||||
this.Position = null;
|
||||
this.DisplayName = null;
|
||||
|
||||
this.Env = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行节点对应的方法
|
||||
/// </summary>
|
||||
/// <param name="context">流程上下文</param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="args">自定义参数</param>
|
||||
/// <returns>节点传回数据对象</returns>
|
||||
public virtual async Task<FlowResult> ExecutingAsync(IDynamicContext context, CancellationToken token)
|
||||
{
|
||||
// 执行触发检查是否需要中断
|
||||
if (DebugSetting.IsInterrupt)
|
||||
{
|
||||
context.Env.TriggerInterrupt(Guid, "", InterruptTriggerEventArgs.InterruptTriggerType.Monitor); // 通知运行环境该节点中断了
|
||||
await DebugSetting.GetInterruptTask.Invoke();
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"[{this.MethodDetails?.MethodName}]中断已取消,开始执行后继分支");
|
||||
if (token.IsCancellationRequested) { return null; }
|
||||
}
|
||||
|
||||
MethodDetails md = MethodDetails;
|
||||
if (md is null)
|
||||
{
|
||||
throw new Exception($"节点{this.Guid}不存在方法信息,请检查是否需要重写节点的ExecutingAsync");
|
||||
}
|
||||
if (!context.Env.TryGetDelegateDetails(md.AssemblyName, md.MethodName, out var dd)) // 流程运行到某个节点
|
||||
{
|
||||
|
||||
throw new Exception($"节点{this.Guid}不存在对应委托");
|
||||
}
|
||||
|
||||
var instance = Env.IOC.Get(md.ActingInstanceType);
|
||||
if (instance is null)
|
||||
{
|
||||
Env.IOC.Register(md.ActingInstanceType).Build();
|
||||
instance = Env.IOC.Get(md.ActingInstanceType);
|
||||
}
|
||||
object[] args = await this.GetParametersAsync(context, token);
|
||||
var result = await dd.InvokeAsync(instance, args);
|
||||
var flowReslt = new FlowResult(this, context, result);
|
||||
return flowReslt;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -40,7 +40,7 @@ namespace Serein.NodeFlow.Model
|
||||
/// <summary>
|
||||
/// 接口节点
|
||||
/// </summary>
|
||||
private NodeModelBase targetNode;
|
||||
private IFlowNode targetNode;
|
||||
/// <summary>
|
||||
/// 缓存的方法信息
|
||||
/// </summary>
|
||||
|
||||
@@ -49,14 +49,14 @@ namespace Serein.NodeFlow.Model
|
||||
/// <summary>
|
||||
/// 数据来源的节点
|
||||
/// </summary>
|
||||
private NodeModelBase? DataNode;
|
||||
private IFlowNode? DataNode;
|
||||
|
||||
/// <summary>
|
||||
/// 有节点被放置
|
||||
/// </summary>
|
||||
/// <param name="nodeModel"></param>
|
||||
/// <returns></returns>
|
||||
public bool PlaceNode(NodeModelBase nodeModel)
|
||||
public bool PlaceNode(IFlowNode nodeModel)
|
||||
{
|
||||
if(DataNode is null)
|
||||
{
|
||||
@@ -76,7 +76,7 @@ namespace Serein.NodeFlow.Model
|
||||
}
|
||||
|
||||
|
||||
public bool TakeOutNode(NodeModelBase nodeModel)
|
||||
public bool TakeOutNode(IFlowNode nodeModel)
|
||||
{
|
||||
if (ChildrenNode.Contains(nodeModel))
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Serein.NodeFlow
|
||||
/// <summary>
|
||||
/// 对应的节点
|
||||
/// </summary>
|
||||
public NodeModelBase NodeModel { get; private set; }
|
||||
public IFlowNode NodeModel { get; private set; }
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Serein.NodeFlow
|
||||
/// </summary>
|
||||
/// <param name="environment">运行环境</param>
|
||||
/// <param name="nodeModel">节点</param>
|
||||
public ScriptFlowApi(IFlowEnvironment environment, NodeModelBase nodeModel)
|
||||
public ScriptFlowApi(IFlowEnvironment environment, IFlowNode nodeModel)
|
||||
{
|
||||
Env = environment;
|
||||
NodeModel = nodeModel;
|
||||
|
||||
Reference in New Issue
Block a user