tangxu
2023-03-20 3bf8bf5179de8b83bbd6ad997e82d98302abd1c3
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
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation
{
    /// <summary>
    /// 
    /// </summary>
    public class EtaCalculationFactory 
    {
        private const string DllName_Custom = "IStation.EtaCalculation4Custom";
        private const string NameSpace_Custom = "IStation.EtaCalculation";
 
        //获取DLL名称
        private static string DllName
        {
            get
            {
                var dllName = string.Empty;
                var selector = Settings.Eta.Analy.Method;
                if (selector == 1)
                {
                    dllName = DllName_Custom;
                }
                return dllName;
            }
        }
 
        private static string NameSpace
        {
            get
            {
                var ns = string.Empty;
                var selector = Settings.Eta.Analy.Method;
                if (selector == 1)
                {
                    ns = NameSpace_Custom;
                }
                return ns;
            }
        }
 
        /// <summary>
        /// 创建
        /// </summary>
        public static I CreateT<I>() 
        {
            var dllName = DllName;
            if (string.IsNullOrEmpty(dllName))
            {
                LogHelper.Error($"EtaCalculationFactory工厂创建接口对象失败,请检查相关配置参数!");
                return default;
            }
            var ns = NameSpace;
            if (string.IsNullOrEmpty(ns))
            {
                LogHelper.Error($"EtaCalculationFactory工厂创建接口对象失败,请检查相关配置参数!");
                return default;
            }
 
            var type = typeof(I);
            var className = string.Format("{0}.{1}", ns, type.Name.Remove(0, 1));
            var obj = Assembly.Load(dllName).CreateInstance(className);
            return (I)obj;
        }
        /// <summary>
        /// 创建
        /// </summary>
        public static IStation.IEtaCalculation.IAnalyCalculator Create(long CorpID)
        {
            if (CorpID == 4)
                return new IStation.EtaCalculation.AnalyCalculator4SHYS();
            else if (CorpID == 5)
                return new IStation.EtaCalculation.AnalyCalculatorSMI();
            else
                return null;
        }
 
    }
}