using AddInPlugin.Util; using OpenTap; using System; using System.Linq; using System.Threading; using System.Xml.Serialization; namespace AddInPlugin { [Display("For", Group: "流程控制", Order: 0)] [AllowAnyChild] public class ForStep : TestStep, CanBreakBase, CanContinueBase { [Display("变量名")] public string VariableName { get; set; } [Display("起始值")] public int StartVal { get; set; } = 0; [Display("循环次数")] public int LoopNum { get; set; } [Display("步进")] public int StepVal { get; set; } = 1; [XmlIgnore] public bool? IsBreaked { get; set; } [XmlIgnore] public bool? IsContinued { get; set; } public ForStep() : base() { } public override void PrePlanRun() { } void RunChildrenInLoop() { var steps = EnabledChildSteps.ToArray(); foreach (var _step in steps) { if (IsBreaked == true) { break; } if (IsContinued == true) { IsContinued = false; continue; } var now = DateTime.Now; RunChildStep(_step); } } public override void Run() { try { PlanRun.Update(this, VariableName, StartVal); int num = 0; while (num < LoopNum && IsBreaked != true) { RunChildrenInLoop(); string add = $"{VariableName} = {VariableName} + {StepVal}"; PlanRun.Update(this, add); num++; } if (IsBreaked == true) { Log.Info("Breaked"); } UpgradeVerdict(Verdict.NotSet); } catch (Exception ex) { Log.Error("For Run error. {0}", ex); UpgradeVerdict(Verdict.Error); } finally { } } public override void PostPlanRun() { // 重置状态 IsBreaked = null; } } }