using System;
using System.Collections.Generic;
using System.Threading;
using TeamAAS.FlowEditor.Execution;
using TeamAAS.FlowEditor.Models;
namespace TeamAAS.FlowEditor.Plugins
{
///
/// 插件接口 - 每个工具节点对应一个插件实现
/// 参照 VisionKit 的 IVisionTool 接口
///
public interface IFlowNodePlugin : IDisposable
{
/// 获取/设置插件模型
BasePluginModel GetModel
{
get;
set;
}
/// 所属流程绑定的结果注册表(运行态=Main,编辑/调试态=Debug;null 时回退 Debug)
ResultRegistry Registry { get; set; }
/// 初始化插件(加载时调用)
bool InitPlugin();
/// 执行插件逻辑
NodeRunStatus PluginRun(CancellationToken token, out Dictionary results);
/// 运行插件(封装计时+状态管理,内部调用PluginRun)
NodeRunStatus Run(CancellationToken token);
///
/// 初始化运行(每次运行前调用,内部调用InitPlugin),返回是否成功
///
///
bool InitRun();
/// 运行耗时(ms)
int CostTime { get; }
/// 执行状态
NodeRunStatus IsSuccess { get; set; }
/// 是否启用
bool IsEnable { get; set; }
/// 最近一次运行的结果字典
Dictionary LastResults { get; }
/// 声明插件的输出字段(键名+类型),创建时即知输出 schema
List DeclareOutputs();
/// 分支节点返回的下一个要执行的节点名列表(null=非分支节点)
List BranchTargets { get; }
}
///
/// 插件输出字段声明
///
public class OutputField
{
public string Key { get; }
public Type ValueType { get; }
public OutputField(string key, Type valueType = null)
{
Key = key;
ValueType = valueType;
}
}
///
/// 插件描述符 - 插件加载后的元信息
///
public class PluginDescriptor
{
public System.Type PluginType { get; set; }
public PluginAttribute Attribute { get; set; }
public string DisplayName => Attribute?.DisplayName;
public PluginCategory Category => Attribute?.Category ?? PluginCategory.其他;
public string IconGeometry => Attribute?.IconGeometry;
public bool HasCustomView => Attribute?.ViewType != null;
public NodeCategory NodeShape => Attribute?.NodeShape ?? NodeCategory.Normal;
/// 是否为子流程专用节点(不进主流程工具箱)。
public bool IsSubFlowNode => Attribute?.IsSubFlowNode ?? false;
/// 子流程工具箱分组用的视觉类别(VisionPlugin 枚举)。
public VisionPlugin VisionCategory => Attribute?.VisionCategory ?? VisionPlugin.其他;
}
///
/// 工具箱项信息(UI展示用,从PluginDescriptor生成)
///
public class NodePluginInfo
{
public string PluginId { get; set; }
public string DisplayName { get; set; }
public NodeCategory Category { get; set; }
public string IconGeometry { get; set; }
public string Description { get; set; }
public PluginCategory Group { get; set; }
public string FlowPluginId { get; set; }
/// 是否为子流程专用节点(true=不进主流程工具箱,只在对应子流程编辑器中出现)。
public bool IsSubFlowNode { get; set; }
/// 子流程工具箱分组类别(VisionPlugin 枚举)。
public VisionPlugin VisionCategory { get; set; }
}
}