领胜LDS 键盘AOI检测项目
wells.liu
2020-07-06 99587d3c26f5b952cb7dc87a56be91b08c5d277b
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
76
77
78
79
80
81
using Bro.Common.Helper;
using Bro.Common.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace Bro.Common.Factory
{
    public static class ProcessFactory
    {
        public static List<string> GetProcessCodes()
        {
            var attrs = FactoryHelper.GetAttributeType<ProcessAttribute>().Keys;
            List<string> processCodes = attrs.Select(u => u.ProcessCode).Distinct().ToList();
 
            return processCodes;
        }
 
        /// <summary>
        /// 获取StationProcess
        /// </summary>
        /// <param name="processCode">流程代码</param>
        /// <param name="msg">异常信息</param>
        /// <returns></returns>
        public static IProcess CreateStationProcess(string processCode, string productionCode, out string msg)
        {
            IProcess proc = null;
            msg = "";
 
            try
            {
                var typeDict = FactoryHelper.GetAttributeType<ProcessAttribute>();
                foreach (KeyValuePair<ProcessAttribute, Type> pair in typeDict)
                {
                    if (typeof(IProcess).IsAssignableFrom(pair.Value) && pair.Key.ProcessCode == processCode)
                    {
                        proc = Activator.CreateInstance(pair.Value, productionCode) as IProcess;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                msg = ex.GetExceptionMessage();
            }
 
            return proc;
        }
 
        /// <summary>
        /// 获取StationConfig
        /// </summary>
        /// <param name="processCode">流程代码</param>
        /// <param name="msg">异常信息</param>
        /// <returns></returns>
        public static IProcessConfig CreateStationConfig(string processCode, out string msg)
        {
            IProcessConfig config = null;
            msg = "";
 
            try
            {
                var typeDict = FactoryHelper.GetAttributeType<ProcessAttribute>();
                foreach (KeyValuePair<ProcessAttribute, Type> pair in typeDict)
                {
                    if (typeof(IProcessConfig).IsAssignableFrom(pair.Value) && pair.Key.ProcessCode == processCode)
                    {
                        config = Activator.CreateInstance(pair.Value) as IProcessConfig;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                msg = ex.GetExceptionMessage();
            }
 
            return config;
        }
    }
}