using OpenTap; using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Xml.Serialization; namespace AddInPlugin { //[Display("AdapterStep", Description: "ÔËÐÐ.Net", Group: "AddInPlugin")] [Browsable(false)] public class AdapterStep : VariableTestStep { #region Settings // ToDo: Add property here for each parameter the end user should be able to change //[Display("Instrument", Order: 0.0, Description: "The instrument that the query is sent to.")] //public DllAction Instrument { get; set; } //// ToDo: Add property here for each parameter the end user should be able to change //[Display("Dut", Order: 0.0, Description: "The instrument that the query is sent to.")] //public MyDUT Dut { get; set; } [XmlIgnore] private ITestStep innerStep; private string xmlString; public string XmlString { get => xmlString; set { xmlString = value; OnPropertyChanged(nameof(XmlString)); LoadStepFromXml(); } } private void LoadStepFromXml() { TapSerializer serializer = new TapSerializer(); innerStep = (ITestStep)serializer.DeserializeFromString(XmlString, TypeData.FromType(typeof(ITestStep))); UpdateVars(); } #endregion public AdapterStep() { // ToDo: Set default values for properties / settings. } protected override void OnMethodVariablesChanged(ObservableCollection variables) { UpdateVars(); } private void SetInnerProperty() { if (innerStep is VariableTestStep vts) { vts.MethodVariables = this.methodVariables; } } private void UpdateVars() { if (innerStep is VariableTestStep vts) { var temp = this.MethodVariables; methodVariables = vts.MethodVariables; foreach (var mv in this.MethodVariables) { mv.ValueStr = temp?.FirstOrDefault(e => e.Name == mv.Name)?.ValueStr; mv.Type = Type.GetType(mv.TypeName); } } } public override void PrePlanRun() { innerStep.PrePlanRun(); } public override void Run() { try { SetInnerProperty(); innerStep.PlanRun = this.PlanRun; innerStep.StepRun = this.StepRun; innerStep.Run(); this.Verdict = innerStep.Verdict; } catch (Exception ex) { Log.Error("AdapterStep Run Error. {0}", ex); this.Verdict = Verdict.Error; } } public override void PostPlanRun() { innerStep.PostPlanRun(); } } }