using Bro.Common.Interface;
|
using System;
|
using System.IO;
|
using System.Linq;
|
using System.Reflection;
|
|
namespace Bro.Common.Helper
|
{
|
public class StationFactory
|
{
|
/// <summary>
|
/// 获取StationProcess
|
/// </summary>
|
/// <param name="stationCode">站点编号 S1~S7</param>
|
/// <param name="userName">登录用户名称</param>
|
/// <param name="msg">异常信息</param>
|
/// <returns></returns>
|
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<ProcessAttribute>();
|
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;
|
}
|
|
/// <summary>
|
/// 获取StationConfig
|
/// </summary>
|
/// <param name="stationCode">站点编号 S1~S7</param>
|
/// <param name="msg">异常信息</param>
|
/// <returns></returns>
|
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<ProcessAttribute>();
|
if (attr != null && attr.ProcessCode == stationCode)
|
{
|
config = Activator.CreateInstance(t) as IProcessConfig;
|
break;
|
}
|
}
|
}
|
}
|
}
|
catch (Exception ex) { }
|
}
|
}
|
catch (Exception ex)
|
{
|
msg = ex.GetExceptionMessage();
|
}
|
|
return config;
|
}
|
}
|
}
|