using OpenTap;
|
using OpenTap.Addin.Util;
|
using System;
|
using System.Linq;
|
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 string StartVal { get; set; } = "0";
|
|
[Display("循环次数")]
|
public string LoopNum { get; set; }
|
|
[Display("步进")]
|
public string 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);
|
}
|
}
|
|
protected override void RunDetail()
|
{
|
try
|
{
|
PlanRun.Update(this, VariableName, StartVal);
|
int num = 0;
|
int loops = PlanRun.Resolve(this, LoopNum);
|
while (num < loops && 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;
|
}
|
}
|
}
|