using AddInPlugin.Util; using OpenTap; using OpenTap.Addin.Annotation; using System; using System.Collections.ObjectModel; using System.Linq; using System.Xml.Serialization; namespace AddInPlugin { [Display("Goto", Group: "流程控制", Order: 0)] public class GotoStep : TestStep { private string condition; [Display("条件")] public string Condition { get => condition; set { condition = value; OnPropertyChanged(nameof(Condition)); } } private Guid nextId; [Display("To")] [DynamicSelect("Datasource", "Name", "Id")] public Guid NextId { get => nextId; set { nextId = value; OnPropertyChanged(nameof(NextId)); } } [XmlIgnore] public ObservableCollection Datasource { get => new ObservableCollection(Parent.ChildTestSteps.Where(e => e.Id != this.Id).ToList()); } public GotoStep() : base() { Rules.Add(() => Datasource.FirstOrDefault(e => e.Id == NextId) != null, "指定步骤应该在序列中", nameof(NextId)); } public override void Run() { try { var targetId = NextId; if (string.IsNullOrEmpty(Condition)) { StepRun.SuggestedNextStep = targetId; } else if (PlanRun.Resolve(this, Condition)) { StepRun.SuggestedNextStep = targetId; } UpgradeVerdict(Verdict.NotSet); } catch (Exception ex) { Log.Error("Goto error. {0}", ex); UpgradeVerdict(Verdict.Error); } } public override void PostPlanRun() { } } }