IFlowNodePlugin.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using TeamAAS.FlowEditor.Execution;
  5. using TeamAAS.FlowEditor.Models;
  6. namespace TeamAAS.FlowEditor.Plugins
  7. {
  8. /// <summary>
  9. /// 插件接口 - 每个工具节点对应一个插件实现
  10. /// 参照 VisionKit 的 IVisionTool 接口
  11. /// </summary>
  12. public interface IFlowNodePlugin : IDisposable
  13. {
  14. /// <summary>获取/设置插件模型</summary>
  15. BasePluginModel GetModel
  16. {
  17. get;
  18. set;
  19. }
  20. /// <summary>所属流程绑定的结果注册表(运行态=Main,编辑/调试态=Debug;null 时回退 Debug)</summary>
  21. ResultRegistry Registry { get; set; }
  22. /// <summary>初始化插件(加载时调用)</summary>
  23. bool InitPlugin();
  24. /// <summary>执行插件逻辑</summary>
  25. NodeRunStatus PluginRun(CancellationToken token, out Dictionary<string, object> results);
  26. /// <summary>运行插件(封装计时+状态管理,内部调用PluginRun)</summary>
  27. NodeRunStatus Run(CancellationToken token);
  28. /// <summary>
  29. /// 初始化运行(每次运行前调用,内部调用InitPlugin),返回是否成功
  30. /// </summary>
  31. /// <returns></returns>
  32. bool InitRun();
  33. /// <summary>运行耗时(ms)</summary>
  34. int CostTime { get; }
  35. /// <summary>执行状态</summary>
  36. NodeRunStatus IsSuccess { get; set; }
  37. /// <summary>是否启用</summary>
  38. bool IsEnable { get; set; }
  39. /// <summary>最近一次运行的结果字典</summary>
  40. Dictionary<string, object> LastResults { get; }
  41. /// <summary>声明插件的输出字段(键名+类型),创建时即知输出 schema</summary>
  42. List<OutputField> DeclareOutputs();
  43. /// <summary>分支节点返回的下一个要执行的节点名列表(null=非分支节点)</summary>
  44. List<string> BranchTargets { get; }
  45. }
  46. /// <summary>
  47. /// 插件输出字段声明
  48. /// </summary>
  49. public class OutputField
  50. {
  51. public string Key { get; }
  52. public Type ValueType { get; }
  53. public OutputField(string key, Type valueType = null)
  54. {
  55. Key = key;
  56. ValueType = valueType;
  57. }
  58. }
  59. /// <summary>
  60. /// 插件描述符 - 插件加载后的元信息
  61. /// </summary>
  62. public class PluginDescriptor
  63. {
  64. public System.Type PluginType { get; set; }
  65. public PluginAttribute Attribute { get; set; }
  66. public string DisplayName => Attribute?.DisplayName;
  67. public PluginCategory Category => Attribute?.Category ?? PluginCategory.其他;
  68. public string IconGeometry => Attribute?.IconGeometry;
  69. public bool HasCustomView => Attribute?.ViewType != null;
  70. public NodeCategory NodeShape => Attribute?.NodeShape ?? NodeCategory.Normal;
  71. /// <summary>是否为子流程专用节点(不进主流程工具箱)。</summary>
  72. public bool IsSubFlowNode => Attribute?.IsSubFlowNode ?? false;
  73. /// <summary>子流程工具箱分组用的视觉类别(VisionPlugin 枚举)。</summary>
  74. public VisionPlugin VisionCategory => Attribute?.VisionCategory ?? VisionPlugin.其他;
  75. }
  76. /// <summary>
  77. /// 工具箱项信息(UI展示用,从PluginDescriptor生成)
  78. /// </summary>
  79. public class NodePluginInfo
  80. {
  81. public string PluginId { get; set; }
  82. public string DisplayName { get; set; }
  83. public NodeCategory Category { get; set; }
  84. public string IconGeometry { get; set; }
  85. public string Description { get; set; }
  86. public PluginCategory Group { get; set; }
  87. public string FlowPluginId { get; set; }
  88. /// <summary>是否为子流程专用节点(true=不进主流程工具箱,只在对应子流程编辑器中出现)。</summary>
  89. public bool IsSubFlowNode { get; set; }
  90. /// <summary>子流程工具箱分组类别(VisionPlugin 枚举)。</summary>
  91. public VisionPlugin VisionCategory { get; set; }
  92. }
  93. }