using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using TeamAAS.FlowEditor.Models;
using TeamAAS.FlowEditor.Plugins;
using Plugins.Standard.Models;
namespace Plugins.Standard
{
///
/// 休眠工具插件 - 无自定义视图,双击弹出PropertyGrid编辑器
///
[PluginAttribute("休眠", PluginCategory.其他, typeof(SleepKitModel),
"ClockOutline",
Description="休眠工具,用于在流程中添加延迟")]
[System.Serializable]
public class SleepToolPlugin : BasePlugin
{
public override List DeclareOutputs() => new List
{
new OutputField("休眠时间(ms)", typeof(int)),
};
public override NodeRunStatus PluginRun(CancellationToken token, out Dictionary results)
{
results = new Dictionary();
try
{
int waitTime = GetValue(Model.WaitTime);
Log(4, $"开始休眠 {waitTime}ms");
Task.Delay(waitTime, token).Wait(token);
results["休眠时间(ms)"] = waitTime;
Log(2, $"休眠完成,耗时 {waitTime}ms");
return NodeRunStatus.Success;
}
catch (System.OperationCanceledException)
{
results["异常"] = "休眠被取消";
Log(1, "休眠被取消", TeamAAS.LogLevel.Warning);
return NodeRunStatus.Failed;
}
catch (System.Exception ex)
{
results["异常"] = ex.Message;
Log(1, $"休眠异常: {ex.Message}", TeamAAS.LogLevel.Error);
return NodeRunStatus.Failed;
}
}
}
}