From 423fc0d8fc22a397d26a16530af8eebdfa0e30fc Mon Sep 17 00:00:00 2001 From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com> Date: Fri, 30 May 2025 10:53:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=8A=82=E7=82=B9=E6=89=A7=E8=A1=8C=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E5=90=8E=E7=BB=AD=E8=B0=83=E7=94=A8=E7=9A=84=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=97=A0=E6=B3=95=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=85=A5=E5=8F=82=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Api/IDynamicContext.cs | 18 ++++++++++++ Library/Extension/FlowModelExtension.cs | 17 +++++++----- Library/FlowNode/DynamicContext.cs | 34 +++++++++++++++++++++++ Library/FlowNode/ParameterDetails.cs | 14 ++++++++++ NodeFlow/Model/SingleFlowCallNode.cs | 27 +++++++++++++++++- Workbench/ViewModels/FlowEditViewModel.cs | 2 +- 6 files changed, 103 insertions(+), 9 deletions(-) diff --git a/Library/Api/IDynamicContext.cs b/Library/Api/IDynamicContext.cs index dcb1b81..96eb052 100644 --- a/Library/Api/IDynamicContext.cs +++ b/Library/Api/IDynamicContext.cs @@ -37,6 +37,24 @@ namespace Serein.Library.Api /// Exception ExceptionOfRuning { get; set; } + /* /// + /// 忽略处理该节点流程 + /// + void IgnoreFlowHandle(NodeModelBase node); + /// + /// 获取此次流程处理状态 + /// + /// + /// + bool GetIgnodeFlowStateUpload(NodeModelBase node); + /// + /// 恢复流程处理状态 + /// + /// + /// + void RecoverIgnodeFlowStateUpload(NodeModelBase node);*/ + + /// /// 设置节点的运行时上一节点,用以多线程中隔开不同流程的数据 /// diff --git a/Library/Extension/FlowModelExtension.cs b/Library/Extension/FlowModelExtension.cs index 84b22f6..a83001a 100644 --- a/Library/Extension/FlowModelExtension.cs +++ b/Library/Extension/FlowModelExtension.cs @@ -209,14 +209,11 @@ namespace Serein.Library && token.IsCancellationRequested == false // 没有取消 && stack.Count > 0) // 循环中直到栈为空才会退出循环 { - - #if DEBUG await Task.Delay(1); #endif #region 执行相关 - // 从栈中弹出一个节点作为当前节点进行处理 var currentNode = stack.Pop(); context.NextOrientation = ConnectionInvokeType.None; // 重置上下文状态 @@ -238,11 +235,14 @@ namespace Serein.Library context.NextOrientation = ConnectionInvokeType.IsError; context.ExceptionOfRuning = ex; } - context.AddOrUpdate(currentNode, flowResult); // 上下文中更新数据 #endregion #region 执行完成 - + //var ignodeState = context.GetIgnodeFlowStateUpload(currentNode); + // 更新数据 + //if(!ignodeState) + context.AddOrUpdate(currentNode, flowResult); // 上下文中更新数据 + // 首先将指定类别后继分支的所有节点逆序推入栈中 var nextNodes = currentNode.SuccessorNodes[context.NextOrientation]; for (int index = nextNodes.Count - 1; index >= 0; index--) @@ -250,7 +250,8 @@ namespace Serein.Library // 筛选出启用的节点的节点 if (nextNodes[index].DebugSetting.IsEnable) { - context.SetPreviousNode(nextNodes[index], currentNode); + //if (!ignodeState) + context.SetPreviousNode(nextNodes[index], currentNode); stack.Push(nextNodes[index]); } } @@ -261,10 +262,12 @@ namespace Serein.Library // 筛选出启用的节点的节点 if (upstreamNodes[index].DebugSetting.IsEnable) { - context.SetPreviousNode(upstreamNodes[index], currentNode); + //if (!ignodeState) + context.SetPreviousNode(upstreamNodes[index], currentNode); stack.Push(upstreamNodes[index]); } } + //context.RecoverIgnodeFlowStateUpload(currentNode); #endregion } diff --git a/Library/FlowNode/DynamicContext.cs b/Library/FlowNode/DynamicContext.cs index 2a43d31..c2223f8 100644 --- a/Library/FlowNode/DynamicContext.cs +++ b/Library/FlowNode/DynamicContext.cs @@ -56,6 +56,11 @@ namespace Serein.Library /// private readonly ConcurrentDictionary dictPreviousNodes = new ConcurrentDictionary(); + /// + /// 记录忽略处理的流程 + /// + private readonly ConcurrentDictionary dictIgnoreNodeFlow = new ConcurrentDictionary(); + /// /// 设置运行时上一节点 /// @@ -66,6 +71,35 @@ namespace Serein.Library dictPreviousNodes.AddOrUpdate(currentNodeModel, (_) => PreviousNode, (o, n) => PreviousNode); } + /// + /// 忽略处理该节点流程 + /// + /// + public void IgnoreFlowHandle(NodeModelBase node) + { + dictIgnoreNodeFlow.AddOrUpdate(node, (o) => true, (o, n) => true); + } + + /// + /// 获取此次流程处理状态 + /// + /// + /// + public bool GetIgnodeFlowStateUpload(NodeModelBase node) + { + return dictIgnoreNodeFlow.TryGetValue(node, out var state) ? state : false; + } + /// + /// 恢复流程处理状态 + /// + /// + /// + public void RecoverIgnodeFlowStateUpload(NodeModelBase node) + { + dictIgnoreNodeFlow.AddOrUpdate(node, (o) => false, (o, n) => false); + } + + /// /// 获取当前节点的运行时上一节点 /// diff --git a/Library/FlowNode/ParameterDetails.cs b/Library/FlowNode/ParameterDetails.cs index d864a62..12d8fa4 100644 --- a/Library/FlowNode/ParameterDetails.cs +++ b/Library/FlowNode/ParameterDetails.cs @@ -3,6 +3,7 @@ using Serein.Library.Utils; using Serein.Library.Utils.SereinExpression; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Reflection; using System.Threading; @@ -254,10 +255,23 @@ namespace Serein.Library } else { + + if(!env.TryGetNodeModel(ArgDataSourceNodeGuid, out var argSourceNodeModel)) { throw new Exception($"[arg{Index}][{Name}][{DataType}]需要节点[{ArgDataSourceNodeGuid}]的参数,但节点不存在"); } + + // 如果是公开的节点,需要判断上下文调用中是否存在流程接口节点 + if (argSourceNodeModel.IsPublic) + { + var pn = context.GetPreviousNode(NodeModel); + if(pn.ControlType == NodeControlType.FlowCall) + { + argSourceNodeModel = pn; + } + } + if (ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData) { var flowData = context.GetFlowData(argSourceNodeModel); diff --git a/NodeFlow/Model/SingleFlowCallNode.cs b/NodeFlow/Model/SingleFlowCallNode.cs index dcf5618..c3351de 100644 --- a/NodeFlow/Model/SingleFlowCallNode.cs +++ b/NodeFlow/Model/SingleFlowCallNode.cs @@ -193,7 +193,32 @@ namespace Serein.NodeFlow.Model this.MethodDetails = targetNode.MethodDetails; } this.SuccessorNodes = targetNode.SuccessorNodes; - return await base.ExecutingAsync(context, token); + var flowData = await base.ExecutingAsync(context, token); + + if (IsShareParam) + { + // 设置运行时上一节点 + + // 此处代码与SereinFlow.Library.FlowNode.ParameterDetails + // ToMethodArgData()方法中判断流程接口节点分支逻辑耦合 + // 不要轻易修改 + context.AddOrUpdate(targetNode, flowData); + foreach (ConnectionInvokeType ctType in NodeStaticConfig.ConnectionTypes) + { + if (this.SuccessorNodes[ctType] == null) continue; + foreach (var node in this.SuccessorNodes[ctType]) + { + if (node.DebugSetting.IsEnable) + { + + context.SetPreviousNode(node, this); + } + } + } + } + + + return flowData; } diff --git a/Workbench/ViewModels/FlowEditViewModel.cs b/Workbench/ViewModels/FlowEditViewModel.cs index 502ea71..ef37377 100644 --- a/Workbench/ViewModels/FlowEditViewModel.cs +++ b/Workbench/ViewModels/FlowEditViewModel.cs @@ -49,7 +49,7 @@ namespace Serein.Workbench.ViewModels partial void OnSelectedTabChanged(FlowEditorTabModel value) { - flowNodeService.CurrentSelectCanvas = value.Content; + flowNodeService.CurrentSelectCanvas = value?.Content; }