LeakCheckResultManager.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Xml;
  7. using Aitex.Common.Util;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.Util;
  10. using VirgoCommon;
  11. namespace VirgoCommon
  12. {
  13. public class LeakCheckResultManager : Singleton<LeakCheckResultManager>
  14. {
  15. private string _template = "<?xml version=\"1.0\" encoding=\"utf-16\"?> <LeakCheckResult xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"></LeakCheckResult>";
  16. private Dictionary<string, XmlDocument> _dicXmlFile = new Dictionary<string, XmlDocument>();
  17. string _filePath = PathManager.GetAppDir() + "\\LeakCheckResult\\";
  18. string _fileName = "\\LeakCheckResult.xml";
  19. public void Initialize(string Module)
  20. {
  21. try
  22. {
  23. XmlDocument _dom = new XmlDocument();
  24. if (!Directory.Exists(_filePath + Module))
  25. {
  26. Directory.CreateDirectory(_filePath + Module);
  27. }
  28. if (!File.Exists(_filePath + Module + _fileName))
  29. {
  30. _dom.LoadXml(_template);
  31. _dom.Save(_filePath + Module + _fileName);
  32. }
  33. else
  34. {
  35. _dom.Load(_filePath + Module + _fileName);
  36. }
  37. _dicXmlFile.Add(Module, _dom);
  38. }
  39. catch (Exception ex)
  40. {
  41. LOG.Write(ex);
  42. throw;
  43. }
  44. }
  45. /*
  46. *
  47. *
  48. * Date = Convert.ToDateTime(element.GetAttribute("Date")),
  49. LeakCheckStatus = element.GetAttribute("LeakCheckStatus"),
  50. LeakRate = Convert.ToDouble(element.GetAttribute("LeakCheckStatus")),
  51. StartPressure = Convert.ToInt32(element.GetAttribute("StartPressure")),
  52. StopPressure = Convert.ToInt32(element.GetAttribute("StopPressure")),
  53. LeakCheckMode = element.GetAttribute("LeakCheckMode"),
  54. LeakCheckTime = Convert.ToInt32(element.GetAttribute("LeakCheckTime")),
  55. *
  56. */
  57. public void AddLeakCheck(string Module, DateTime date, int leakCheckTime, double beginPressure, double endPressure, double leakRate, string status, string mode)
  58. {
  59. try
  60. {
  61. XmlElement node = _dicXmlFile[Module].CreateNode(XmlNodeType.Element, "LeakCheck", _dicXmlFile[Module].NamespaceURI) as XmlElement;
  62. node.SetAttribute("Id", Guid.NewGuid().ToString());
  63. node.SetAttribute("Date", date.ToString("yyyy-MM-dd HH:mm:ss.fff"));
  64. node.SetAttribute("LeakCheckStatus", status);
  65. node.SetAttribute("LeakRate", leakRate.ToString("F5"));
  66. node.SetAttribute("StartPressure", beginPressure.ToString());
  67. node.SetAttribute("StopPressure", endPressure.ToString());
  68. node.SetAttribute("LeakCheckMode", mode);
  69. node.SetAttribute("LeakCheckTime", leakCheckTime.ToString());
  70. XmlElement root = _dicXmlFile[Module].SelectSingleNode("/LeakCheckResult") as XmlElement;
  71. root.AppendChild(node);
  72. _dicXmlFile[Module].Save(_filePath + Module + _fileName);
  73. }
  74. catch (Exception ex)
  75. {
  76. LOG.Write(ex);
  77. }
  78. }
  79. /*
  80. *
  81. <LeakCheck Date="" StartPressure="" StopPressure
  82. */
  83. public List<LeakCheckResultItem> GetHistoryLeakCheck(string Module)
  84. {
  85. List<LeakCheckResultItem> result = new List<LeakCheckResultItem>();
  86. try
  87. {
  88. XmlNodeList lst = _dicXmlFile[Module].SelectNodes("/LeakCheckResult/LeakCheck");
  89. if (lst != null)
  90. {
  91. foreach (XmlElement element in lst)
  92. {
  93. result.Add(new LeakCheckResultItem()
  94. {
  95. Id = element.GetAttribute("Id"),
  96. Date = Convert.ToDateTime(element.GetAttribute("Date")),
  97. LeakCheckStatus = element.GetAttribute("LeakCheckStatus"),
  98. LeakRate = Convert.ToDouble(element.GetAttribute("LeakRate")),
  99. StartPressure = Convert.ToDouble(element.GetAttribute("StartPressure")),
  100. StopPressure = Convert.ToDouble(element.GetAttribute("StopPressure")),
  101. LeakCheckMode = element.GetAttribute("LeakCheckMode"),
  102. LeakCheckTime = Convert.ToInt32(element.GetAttribute("LeakCheckTime")),
  103. });
  104. }
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. LOG.Write(ex);
  110. }
  111. return result;
  112. }
  113. public void Delete(string Module, string id)
  114. {
  115. try
  116. {
  117. XmlElement node = _dicXmlFile[Module].SelectSingleNode(string.Format("/LeakCheckResult/LeakCheck[@Id='{0}']", id)) as XmlElement;
  118. node.ParentNode.RemoveChild(node);
  119. _dicXmlFile[Module].Save(_filePath + Module + _fileName);
  120. }
  121. catch (Exception ex)
  122. {
  123. LOG.Write(ex);
  124. }
  125. }
  126. }
  127. }