using System; using System.Collections.Generic; using System.Reflection; using System.Xml.Serialization; using VisionBuilder.Core.Api; namespace WPFProject.Models { public class Step : NotifyBase { private static readonly Type InterfaceType = typeof(IStepRunner); private static readonly Dictionary Cache = new Dictionary(); #region 字段 [XmlIgnore] public Program Program { get; set; } [XmlIgnore] public Sequence Sequence { get; set; } private int _Index; public int Index { get { return _Index; } set => RaiseAndSetIfChanged(ref _Index, value); } private string _Name; public string Name { get { return _Name; } set => RaiseAndSetIfChanged(ref _Name, value); } private string _DllPath = "C:/Users/cheng/source/repos/WPFProject/VisionBuilder.Test/bin/Debug/VisionBuilder.Test.dll"; public string DllPath { get { return _DllPath; } set => RaiseAndSetIfChanged(ref _DllPath, value); } private string _ClassName = "VisionBuilder.Test.PluginOne"; public string ClassName { get { return _ClassName; } set => RaiseAndSetIfChanged(ref _ClassName, value); } private string _MethodName; public string MethodName { get { return _MethodName; } set => RaiseAndSetIfChanged(ref _MethodName, value); } private string _Description; public string Description { get { return _Description; } set => RaiseAndSetIfChanged(ref _Description, value); } #endregion public void RunStep() { Assembly assembly = Assembly.LoadFrom(DllPath); Type type = assembly.GetType(ClassName); if (type != null && InterfaceType.IsAssignableFrom(type)) { IStepRunner stepRunner = (IStepRunner)assembly.CreateInstance(ClassName); stepRunner.RunStep(Sequence.Program.TempVars); } } } }