private string ConvertionToXml() { string sText = string.Empty; sText += GetXmlString(CommonEnum.XmlType.XmlTile); sText += GetXmlString(CommonEnum.XmlType.XmlRoot); if (sectionInfo != null) { sText += FillChar(0, 4, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefine, "configSections"); foreach (SectionInfo item in sectionInfo) { sText += FillChar(0, 8, ' ') + "<section" + " name=\"" + item.Name + "\"" + " type=\"" + item.Type + "\"" + " />" + Environment.NewLine; } sText += FillChar(0, 4, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefineTail, "configSections"); } if (workflowObj != null) { sText += FillChar(0, 4, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefine, "LogicPath"); sText += FillChar(0, 8, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefine, "NodeGroup"); foreach (WorkflowInfo item in workflowObj) { sText += FillChar(0, 12, ' ') + "<NodeInfo" + " EventLogicPath=\"" + item.Name + "\"" + " GotoLogicPath=\"" + "" + "\"" + " Memo=\"" + item.Title + "\"" + Environment.NewLine + FillChar(0, 16, ' ') + "IndexId=\"" + item.Id + "\"" + " />" + Environment.NewLine; } sText += FillChar(0, 8, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefineTail, "NodeGroup"); sText += FillChar(0, 4, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefineTail, "LogicPath"); } foreach (TreeNode item in this.treeWorkflow.Nodes) { if (item.Tag.ToString() == "LevelOne") { foreach (TreeNode itemTwo in item.Nodes) { int index = itemTwo.Text.IndexOf("("); string sSectionId = itemTwo.Text.Substring(0, index); sText += FillChar(0, 4, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefine, sSectionId); sText += FillChar(0, 8, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefine, "NodeGroup"); foreach (TreeNode itemThree in itemTwo.Nodes) { ActivityInfo activeInfo = itemThree.Tag as ActivityInfo; sText += FillChar(0, 12, ' ') + "<NodeInfo" + " SalfLogicPath=\"" + activeInfo.WorkflowName + "\"" + " GotoLogicPath=\"" + "" + "\"" + " ModuleName=\"" + activeInfo.ModuleName + "\"" + Environment.NewLine + FillChar(0, 16, ' ') + "StartClass=\"" + activeInfo.ClassName + "\"" + Environment.NewLine + FillChar(0, 16, ' ') + "StartFunction=\"" + activeInfo.FunctionName + "\"" + " IsCreate=\"" + (activeInfo.IsCreate ? "true" : "false") + "\"" + " Enabled=\"" + (activeInfo.IsEnabled ? "true" : "false") + "\"" + Environment.NewLine + FillChar(0, 16, ' ') + "Memo=\"" + activeInfo.Title + "\"" + " IndexId=\"" + activeInfo.Id + "\"" + " />" + Environment.NewLine; } sText += FillChar(0, 8, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefineTail, "NodeGroup"); sText += FillChar(0, 4, ' ') + GetXmlString(CommonEnum.XmlType.XmlSelfDefineTail, sSectionId); } } } sText += GetXmlString(CommonEnum.XmlType.XmlRootTail); return(sText); }
/// <summary> /// 从xml获取内容 /// </summary> /// <param name="fullConfigFileName"></param> /// <returns></returns> private List <WorkflowInfo> LoadFileByXml(string fullConfigFileName) { List <WorkflowInfo> result = new List <WorkflowInfo>(); XDocument doc = XDocument.Load(fullConfigFileName); XElement configurationElement = doc.Elements().FirstOrDefault(p => p.Name == "configuration"); if (configurationElement != null) { //读取工作流配置 XElement logicPathElement = configurationElement.Elements().FirstOrDefault(p => p.Name == "LogicPath"); if (logicPathElement != null) { XElement nodeGroupElement = logicPathElement.Elements().FirstOrDefault(p => p.Name == "NodeGroup"); if (nodeGroupElement != null) { foreach (XElement nodeElement in nodeGroupElement.Elements()) { string id = null; string name = null; string title = null; foreach (XAttribute attribute in nodeElement.Attributes()) { switch (attribute.Name.LocalName) { case "IndexId": id = attribute.Value; break; case "EventLogicPath": name = attribute.Value; break; case "Memo": title = attribute.Value; break; default: break; } } WorkflowInfo workflow = new WorkflowInfo(id, name, title); result.Add(workflow); } } } //读取工作流节点 foreach (WorkflowInfo workflow in result) { XElement workflowElement = configurationElement.Elements().FirstOrDefault(p => p.Name == workflow.Name); if (workflowElement != null) { XElement nodeGroupElement = workflowElement.Elements().FirstOrDefault(p => p.Name == "NodeGroup"); if (nodeGroupElement != null) { foreach (XElement nodeElement in nodeGroupElement.Elements()) { string id = null; string workflowName = null; string title = null; bool isEnabled = false; string moduleName = null; string className = null; string functionName = null; bool isCreate = false; foreach (XAttribute attribute in nodeElement.Attributes()) { switch (attribute.Name.LocalName) { case "IndexId": id = attribute.Value; break; case "SalfLogicPath": workflowName = attribute.Value; break; case "Enabled": isEnabled = attribute.Value != "false"; break; case "Memo": title = attribute.Value; break; case "ModuleName": moduleName = attribute.Value; break; case "StartClass": className = attribute.Value; break; case "StartFunction": functionName = attribute.Value; break; case "IsCreate": isCreate = attribute.Value != "false"; break; default: break; } } List <string> names = new List <string>(); if (!string.IsNullOrWhiteSpace(functionName)) { names.Add(functionName); } if (!string.IsNullOrWhiteSpace(className)) { names.Add(className); } if (!string.IsNullOrWhiteSpace(moduleName)) { names.Add(moduleName); } ActivityInfo activity = new ActivityInfo(workflowName, id, title, isEnabled, functionName, moduleName, className, string.Join(",", names), workflow.Title, isCreate); workflow.Activities.Add(activity); } } } } } return(result); }