using HandyControl.Interactivity; using HandyControl.Tools; using System; using System.Collections.Generic; using System.Threading; using TeamAAS.FlowEditor.Models; using TeamAAS.FlowEditor.Plugins; using Plugins.Standard.Models; namespace Plugins.Standard { /// /// 条件判断插件 - 无自定义视图,双击弹出PropertyGrid编辑器 /// [PluginAttribute("条件判断", PluginCategory.逻辑判断, typeof(IfConditionModel), "CallSplit", Description = "条件判断,运行满足条件的下节点", NodeShape = NodeCategory.Decision)] [System.Serializable] public class IfConditionPlugin : BasePlugin { public IfConditionPlugin() { // 设置节点形状为判断 } /// /// 动态输出声明:固定的 结果/执行分支数,加上按条件数量声明的 [分支]执行流程N /// (与运行时写入的键格式一致,使分支节点的输出跑之前就能被绑定树索引)。 /// public override List DeclareOutputs() { var list = new List { new OutputField("结果", typeof(bool)), new OutputField("执行分支数", typeof(int)), }; int n = Model?.IFModels?.Count ?? 0; for (int i = 1; i <= n; i++) list.Add(new OutputField($"[分支]执行流程{i}", typeof(string))); return list; } public override NodeRunStatus PluginRun(CancellationToken token, out Dictionary results) { results = new Dictionary(); BranchTargets = new List(); int index = 0; try { Log(3, $"开始条件判断,共 {Model.IFModels?.Count ?? 0} 个条件"); for (int i = 0; i < Model.IFModels.Count; i++) { bool Result = GetValue(Model.IFModels[i].DisplayIndex); if (Model.IFModels[i].IsNegate) { Result = !Result; } Log(4, $"条件{i + 1} 判定={Result}{(Model.IFModels[i].IsNegate ? "(取反)" : "")} → 目标[{Model.IFModels[i].ToolName}]"); if (Result) { BranchTargets.Add(Model.IFModels[i].ToolName); results[$"[分支]执行流程{index + 1}"] = Model.IFModels[i].ToolName; index++; } } results["执行分支数"] = index; results["结果"] = index > 0; if (index == 0) { results["程序异常:"] = "无执行流程"; Log(1, "条件判断无任何分支命中", TeamAAS.LogLevel.Warning); return NodeRunStatus.Failed; } Log(2, $"条件判断命中 {index} 个分支: {string.Join(", ", BranchTargets)}"); return NodeRunStatus.Success; } catch (Exception ex) { results["结果"] = false; Log(1, $"条件判断异常: {ex.Message}", TeamAAS.LogLevel.Error); return NodeRunStatus.Failed; } } } }