Files
ADP/Command/CommandDialog.cs
T
2026-08-27 14:26:22 +08:00

63 lines
2.5 KiB
C#

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