| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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
- {
- /// <summary>
- /// 休眠工具插件 - 无自定义视图,双击弹出PropertyGrid编辑器
- /// </summary>
- [PluginAttribute("休眠", PluginCategory.其他, typeof(SleepKitModel),
- "ClockOutline",
- Description="休眠工具,用于在流程中添加延迟")]
- [System.Serializable]
- public class SleepToolPlugin : BasePlugin<SleepKitModel>
- {
- public override List<OutputField> DeclareOutputs() => new List<OutputField>
- {
- new OutputField("休眠时间(ms)", typeof(int)),
- };
- public override NodeRunStatus PluginRun(CancellationToken token, out Dictionary<string, object> results)
- {
- results = new Dictionary<string, object>();
- try
- {
- int waitTime = GetValue<int>(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;
- }
- }
- }
- }
|