实现流程模板存储
public abstract class PorcessRuntimeProvider
{
#region 构造实例
/// <summary>
/// 构造实例
/// </summary>
private static PorcessRuntimeProvider _defaultInstance = null;
/// <summary>
/// 构造实例类
/// </summary>
public static string types = "MSTC.WorkFlow.Core.WFGrapModel.MeberShip.PorcessRuntimeMemberShip,MSTC.WorkFlow.Core";
/// <summary>
/// 构造器
/// </summary>
/// <returns></returns>
public static PorcessRuntimeProvider Instance()
{
try
{
if (_defaultInstance != null) return _defaultInstance;
Type type = Type.GetType(types);
if (type != null)
{
_defaultInstance = (Activator.CreateInstance(type, new object[0]) as PorcessRuntimeProvider);
}
}
catch (Exception exception)
{
throw new Exception(exception.Message, exception);
}
return _defaultInstance;
}
#endregion
#region 创建流程实例
/// <summary>
///创建流程实例
/// </summary>
/// <param name="prcessentityguid"></param>
/// <returns></returns>
public abstract GraphModelRuntime CreateProcessRuntime(Guid prcessentityguid);
#endregion
#region 创建流程模板
/// <summary>
/// 创建流程模板
/// </summary>
/// <param name="gm">步骤集合</param>
/// <param name="cm">关系集合</param>
/// <param name="pm">模板对象基础信息</param>
/// <returns></returns>
public abstract bool CreateProcessModel(NodeModel[] gm, ConnectorModel[] cm,ProcessModel pm);
public abstract string GetProcessGrapModel(Guid processmodelguid);
#endregion
}
二.实例接口
public sealed class PorcessRuntimeMemberShip : MSTC.WorkFlow.Core.WFGrapModel.Provider.PorcessRuntimeProvider
{
/// <summary>
/// 创建流程实例
/// </summary>
/// <param name="processentityguid">流程实例GUID</param>
/// <returns>流程实例信息</returns>
public override GraphModelRuntime CreateProcessRuntime(Guid processentityguid)
{
GraphModelRuntime gp = new GraphModelRuntime();
return gp;
}
/// <summary>
/// 创建流程模板
/// </summary>
/// <param name="gm">步骤列表</param>
/// <param name="cm">步骤连线列表</param>
/// <returns>true:成功/false:失败</returns>
public override bool CreateProcessModel(NodeModel[] gm, ConnectorModel[] cm, ProcessModel pm)
{
try
{
string pmfield = string.Empty,
pmSql = string.Empty,
gmfield = string.Empty,
gmSql = string.Empty,
cmfield = string.Empty,
cmSql = string.Empty,
pamfield = string.Empty,
pamSql = string.Empty;
//1.得到流程模板列SQL
pmfield = GetAppModelProperties<ProcessModel>.
GetPropertiesFields(WFAssimentTables.Processmodeltable,
pm.ProcessModelXml, WFAssimentTables.Processstype);
pmSql = AppPropertiesValues.SetfiledValue(pmfield, pm, WFAssimentTables.Processstype);
//2.得到步骤列SQL
gmfield = GetAppModelProperties<NodeModel>.
GetPropertiesFields(WFAssimentTables.StepModuletable,
pm.ProcessModelXml, WFAssimentTables.Stepstype);
gmSql = AppPropertiesValues.SetfiledValue(gmfield, gm, WFAssimentTables.Stepstype);
//3.得到分支列SQL
cmfield = GetAppModelProperties<ConnectorModel>.
GetPropertiesFields(WFAssimentTables.Relationtable,
pm.ProcessModelXml, WFAssimentTables.Relationtype);
cmSql = AppPropertiesValues.SetfiledValue(cmfield, cm, WFAssimentTables.Relationtype);
//4.得到步骤处理人
pamfield = GetAppModelProperties<ProcessAuditorModule>.
GetPropertiesFields(WFAssimentTables.WorkflowBandtable,
pm.ProcessModelXml, WFAssimentTables.WorkflowBandtype);
pamSql = AppPropertiesValues.SetfiledValue(pamfield, new NodeModel().getProcessAuditorModule(gm),
WFAssimentTables.WorkflowBandtype);
MSTC.WorkFlow.Core.DBAess.SqlAcess.ExecSQL(pmSql + gmSql + cmSql + pamSql);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return true;
}
/// <summary>
/// 对比是否在Model.xml文件中存在定义属性
/// </summary>
/// <param name="filename">实体属性名称</param>
/// <param name="ProcessModelXml">流程XML</param>
/// <param name="Processstype">类别</param>
/// <returns>true:存在,false:不存在</returns>
public static bool ComparePropertie(string filename, string ProcessModelXml, string Processstype)
{
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
xmldoc.LoadXml(ProcessModelXml);
switch (Processstype)
{
//判断是否为流程模板属性
case "Processs":
{
if (xmldoc.SelectSingleNode("//ProcessModel/Processs/Attributes/" + filename + "") != null)
return true;
}
break;
//判断是否为步骤模板属性
case "Bandtype":
case "Steps":
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(xmldoc.SelectSingleNode("//ProcessModel/Processs/Attributes/ProcessGrap").InnerText);
if ((doc.SelectSingleNode("/mxGraphModel/root/Shape/mxCell/mxGeometry") != null ?
doc.SelectSingleNode("/mxGraphModel/root/Shape/mxCell/mxGeometry").Attributes.GetNamedItem(filename) : null) != null)
return true;
if ((doc.SelectSingleNode("/mxGraphModel/root/Roundrect/mxCell/mxGeometry") != null ?
doc.SelectSingleNode("/mxGraphModel/root/Roundrect/mxCell/mxGeometry").Attributes.GetNamedItem(filename) : null) != null)
return true;
if ((doc.SelectSingleNode("/mxGraphModel/root/Rectangle/mxCell/mxGeometry") != null ?
doc.SelectSingleNode("/mxGraphModel/root/Rectangle/mxCell/mxGeometry").Attributes.GetNamedItem(filename) : null) != null)
return true;
}
break;
//判断是否为分支模板属性
case "Relationtype":
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(xmldoc.SelectSingleNode("//ProcessModel/Processs/Attributes/ProcessGrap").InnerText);
if ((doc.SelectSingleNode("/mxGraphModel/root/Connector/mxCell/mxGeometry").Attributes.GetNamedItem(filename) != null ?
doc.SelectSingleNode("/mxGraphModel/root/Connector/mxCell/mxGeometry").Attributes.GetNamedItem(filename) : null) != null)
return true;
}
break;
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="processmodelguid"></param>
/// <returns></returns>
public override string GetProcessGrapModel(Guid processmodelguid)
{
return new ProcessModel(processmodelguid).ProcessGrap;
}
}
/// <summary>
/// 获取对象属性
/// </summary>
/// <typeparam name="T">泛型类型</typeparam>
public class GetAppModelProperties<T>
{
/// <summary>
/// 获取Model.xml属性
/// </summary>
/// <param name="tablename">表名</param>
/// <param name="ProcessModelXml">流程XML</param>
/// <param name="Processstype">类别</param>
/// <returns>返回SQL</returns>
public static string GetPropertiesFields(string tablename, string ProcessModelXml, string Processstype)
{
//获取实体属性
PropertyInfo[] properites = typeof(T).GetProperties();
StringBuilder appfield = new StringBuilder();
//遍历实体属性
foreach (PropertyInfo propertyInfo in properites)
{
//比较propertyInfo.Name是否在流程模板中定义
if (PorcessRuntimeMemberShip.ComparePropertie
(propertyInfo.Name, ProcessModelXml, Processstype))
appfield.Append(propertyInfo.Name).Append(WFAssimentTables.Splistrh);
}
if (appfield.Length > 0)
{
appfield.Remove(appfield.Length - 1, 1);
}
return appfield.ToString();
}
}