using Bro.Common.Interface; using System; using System.IO; using System.Linq; using System.Reflection; namespace Bro.Common.Helper { public class StationFactory { /// /// 获取StationProcess /// /// 站点编号 S1~S7 /// 登录用户名称 /// 异常信息 /// public static IProcess CreateStationProcess(string stationCode, string userName, out string msg) { IProcess proc = null; msg = ""; try { var dllFiles = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).GetFiles("Bro.*.dll").Select(u => u.FullName).ToList(); foreach (string f in dllFiles) { try { Assembly assm = Assembly.LoadFrom(f); if (assm != null) { foreach (Type t in assm.GetTypes()) { if (typeof(IProcess).IsAssignableFrom(t)) { var attr = t.GetCustomAttribute(); if (attr != null && attr.ProcessCode == stationCode) { proc = Activator.CreateInstance(t, userName) as IProcess; break; } } } } } catch (Exception ex) { } } } catch (Exception ex) { msg = ex.GetExceptionMessage(); } return proc; } /// /// 获取StationConfig /// /// 站点编号 S1~S7 /// 异常信息 /// public static IProcessConfig CreateStationConfig(string stationCode, out string msg) { IProcessConfig config = null; msg = ""; try { var dllFiles = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).GetFiles("Bro.*.dll").Select(u => u.FullName).ToList(); foreach (string f in dllFiles) { try { Assembly assm = Assembly.LoadFrom(f); if (assm != null) { foreach (Type t in assm.GetTypes()) { if (typeof(IProcessConfig).IsAssignableFrom(t)) { var attr = t.GetCustomAttribute(); if (attr != null && attr.ProcessCode == stationCode) { config = Activator.CreateInstance(t) as IProcessConfig; break; } } } } } catch (Exception ex) { } } } catch (Exception ex) { msg = ex.GetExceptionMessage(); } return config; } } }