IwbProcess.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.IO;
  2. using System.Reflection;
  3. using System.Xml;
  4. using IwbZero.IwbBase;
  5. using IwbZero.ToolCommon.StringModel;
  6. namespace IwbZero.Processes
  7. {
  8. public class IwbProcess:IIwbId
  9. {
  10. public static IwbProcess LoadById(string piProcessId)
  11. {
  12. string fileName = "IwbZero.Processes.ProcessInfos.Process.xml";
  13. XmlDocument xDoc = new XmlDocument();
  14. Assembly asm = Assembly.GetExecutingAssembly();
  15. //读取嵌入式资源
  16. Stream sm = asm.GetManifestResourceStream(fileName);
  17. if (sm != null)
  18. {
  19. xDoc.Load(sm);
  20. }
  21. if (!xDoc.HasChildNodes)
  22. {
  23. return null;
  24. }
  25. XmlNode xmlNode = xDoc.LastChild;
  26. return LoadByXmlNode(xmlNode, piProcessId);
  27. }
  28. public static IwbProcess LoadByXmlNode(XmlNode xmlNode, string piProcessId)
  29. {
  30. if (!xmlNode.HasChildNodes)
  31. {
  32. return null;
  33. }
  34. foreach (XmlNode child in xmlNode.ChildNodes)
  35. {
  36. if (child.Attributes?["id"] != null && child.Attributes["id"].Value.UAndT() == piProcessId.UAndT())
  37. {
  38. IwbProcess process = new IwbProcess()
  39. {
  40. Id = piProcessId,
  41. ProcessId = child.Attributes["id"].Value,
  42. };
  43. if (child.HasChildNodes)
  44. {
  45. foreach (XmlNode node in child.ChildNodes)
  46. {
  47. switch (node.Name.Trim())
  48. {
  49. case "Name":
  50. process.ProcessName = node.FirstChild?.Value;
  51. break;
  52. case "Parameters":
  53. process.ProcessParameters = node.FirstChild?.Value;
  54. break;
  55. case "Description":
  56. process.Description = node.FirstChild?.Value;
  57. break;
  58. case "ProcessType":
  59. process.Description = node.FirstChild?.Value;
  60. break;
  61. case "Script":
  62. process.ProcessScript = node.FirstChild?.Value;
  63. break;
  64. case "Class":
  65. process.ProcessClass = node.FirstChild?.Value;
  66. break;
  67. case "Lib":
  68. process.ProcessLib = node.FirstChild?.Value;
  69. break;
  70. case "IsStatic":
  71. process.IsStatic = node.FirstChild?.Value.ValB()??false;
  72. break;
  73. }
  74. }
  75. }
  76. return process;
  77. }
  78. }
  79. return null;
  80. }
  81. public string Id { get; set; }
  82. public string ProcessId { get; set; }
  83. public string ProcessName { get; set; }
  84. public string ProcessParameters { get; set; }
  85. public string Description { get; set; }
  86. public string ProcessType { get; set; }
  87. public string ProcessScript { get; set; }
  88. public string ProcessClass { get; set; }
  89. public string ProcessLib { get; set; }
  90. public bool IsStatic { get; set; }
  91. }
  92. }