using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XKRS.Common.Interface;
using XKRS.Common.Model.Helper;
namespace XKRS.Common.Factory
{
public static class ProcessFactory
{
///
/// 获取项目中所有流程,即寻找所有带有[Process]的
///
/// 返回流程名称列表
public static List GetProcessCodes()
{
var attrs = FactoryHelper.GetAttributeType().Keys;
List processCodes = attrs.Select(u => u.ProcessCode).Distinct().ToList();
return processCodes;
}
///
/// 获取StationProcess
///
/// 流程代码
///
/// 异常信息
///
public static IProcess CreateStationProcess(string processCode,string productionCode,out string msg)
{
IProcess proc = null;
msg = "";
try
{
var typeDict = FactoryHelper.GetAttributeType();
foreach(KeyValuePairpair 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;
}
}
}