using AddInPlugin.Util;
|
using OpenTap;
|
using System;
|
using System.Linq;
|
|
namespace AddInPlugin
|
{
|
[AllowAnyChild]
|
[Display(Name: "While", Group: "流程控制", Description: "While循环", Order: 0)]
|
public class WhileStep : ConditionBase, CanBreakBase, CanContinueBase
|
{
|
public bool? IsBreaked { get; set; }
|
public bool? IsContinued { get; set; }
|
|
public WhileStep() : base()
|
{
|
|
}
|
|
public override void PrePlanRun()
|
{
|
}
|
|
public void RunCustom()
|
{
|
IsContinued = null;
|
var steps = EnabledChildSteps.ToArray();
|
foreach (var _step in steps)
|
{
|
var step = _step;
|
try
|
{
|
if (IsBreaked == true || IsContinued == true)
|
{
|
break;
|
}
|
try
|
{
|
PlanRun.MainThread.AbortToken.ThrowIfCancellationRequested();
|
}
|
catch (Exception ex)
|
{
|
break;
|
}
|
var run = RunChildStep(step);
|
}
|
finally
|
{
|
|
}
|
}
|
}
|
|
public TapThread GetTop()
|
{
|
var current = TapThread.Current;
|
while (current?.Parent != null)
|
{
|
current = current.Parent;
|
}
|
return current;
|
}
|
|
public override void Run()
|
{
|
try
|
{
|
ConditionResult = PlanRun.Resolve<bool>(this, Condition);
|
while (ConditionResult == true && IsBreaked != true)
|
{
|
try
|
{
|
PlanRun.MainThread.AbortToken.ThrowIfCancellationRequested();
|
}
|
catch (Exception ex)
|
{
|
break;
|
}
|
|
RunCustom();
|
ConditionResult = PlanRun.Resolve<bool>(this, Condition);
|
}
|
UpgradeVerdict(Verdict.NotSet);
|
}
|
catch (Exception ex)
|
{
|
Log.Error("While Run Error. {0}", ex);
|
ConditionResult = null;
|
UpgradeVerdict(Verdict.Error);
|
}
|
}
|
|
public override void PostPlanRun()
|
{
|
}
|
}
|
}
|