using Common.Attributes; using System; using System.ComponentModel; using System.Threading; using System.Threading.Tasks; namespace Command { /// /// 对话框命令:在测试流程中弹出提示窗口。 /// 命令库为纯 .NET 类库,不直接引用 WPF 程序集; /// 实际的弹窗能力由宿主程序(ADP 外壳)在启动时注入到 委托中实现(依赖倒置)。 /// [ADPCommand] public static class CommandDialog { /// /// 弹窗类型 /// public enum DialogType { /// /// 信息提示 /// Info, /// /// 警告提示 /// Warning, /// /// 错误提示 /// Error } /// /// 弹窗处理委托(参数依次为:弹窗类型、弹窗详细、是否阻塞、自动关闭秒数、取消令牌)。 /// 由宿主程序启动时注入实现;未注入时弹窗命令降级为仅输出日志,不会抛异常。 /// [Browsable(false)] public static Func 弹窗处理器; /// /// 弹窗:在界面上显示一个提示对话框。 /// /// 弹窗样式:Info 信息 / Warning 警告 / Error 错误 /// 弹窗中显示的详细内容 /// true = 步骤暂停,等待用户关闭(或自动关闭)后才继续;false = 弹出后步骤立即继续 /// 大于 0 时,弹窗在指定秒数后自动关闭;小于等于 0 时不自动关闭,需用户手动关闭 /// 异步取消令牌 public static async Task 弹窗(DialogType 弹窗类型, string 弹窗详细, bool 是否阻塞, float 自动关闭秒数, CancellationToken ct) { var handler = 弹窗处理器; if (handler == null) { Console.WriteLine($"[弹窗命令] 宿主未注入弹窗处理器,跳过弹窗:{弹窗详细}"); return; } await handler(弹窗类型, 弹窗详细, 是否阻塞, 自动关闭秒数, ct); } } }