chr
2025-03-03 7b903bb86375e9df24a725288d1c876b8d2b0e61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml.Serialization;
using HMI.Core.Api;
 
namespace WPFProject.Models
{
    public class Step : NotifyBase
    {
        private static readonly Type InterfaceType = typeof(IStepRunner);
        private static readonly Dictionary<string, Assembly> Cache = new Dictionary<string, Assembly>();
        #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);
            }
        }
    }
}