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;
|
}
|
}
|
}
|