LeakCheckResultManager.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 Aitex.Triton160.Common;
  11. namespace Aitex.Triton160.RT.Module
  12. {
  13. 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 XmlDocument _dom = new XmlDocument();
  17. string _fileName = PathManager.GetCfgDir() + "\\LeakCheckResult.xml";
  18. public void Initialize()
  19. {
  20. try
  21. {
  22. if (!File.Exists(_fileName))
  23. {
  24. _dom.LoadXml(_template);
  25. _dom.Save(_fileName);
  26. }
  27. else
  28. {
  29. _dom.Load(_fileName);
  30. }
  31. }
  32. catch (Exception ex)
  33. {
  34. LOG.Write(ex);
  35. throw;
  36. }
  37. }
  38. /*
  39. *
  40. *
  41. * Date = Convert.ToDateTime(element.GetAttribute("Date")),
  42. LeakCheckStatus = element.GetAttribute("LeakCheckStatus"),
  43. LeakRate = Convert.ToDouble(element.GetAttribute("LeakCheckStatus")),
  44. StartPressure = Convert.ToInt32(element.GetAttribute("StartPressure")),
  45. StopPressure = Convert.ToInt32(element.GetAttribute("StopPressure")),
  46. LeakCheckMode = element.GetAttribute("LeakCheckMode"),
  47. LeakCheckTime = Convert.ToInt32(element.GetAttribute("LeakCheckTime")),
  48. *
  49. */
  50. public void AddLeakCheck(DateTime date, int leakCheckTime, int beginPressure, int endPressure, double leakRate, string status, string mode)
  51. {
  52. try
  53. {
  54. XmlElement node = _dom.CreateNode(XmlNodeType.Element, "LeakCheck", _dom.NamespaceURI) as XmlElement;
  55. node.SetAttribute("Id", Guid.NewGuid().ToString());
  56. node.SetAttribute("Date", date.ToString("yyyy-MM-dd HH:mm:ss.fff"));
  57. node.SetAttribute("LeakCheckStatus", status);
  58. node.SetAttribute("LeakRate", leakRate.ToString("F5"));
  59. node.SetAttribute("StartPressure", beginPressure.ToString());
  60. node.SetAttribute("StopPressure", endPressure.ToString());
  61. node.SetAttribute("LeakCheckMode", mode);
  62. node.SetAttribute("LeakCheckTime", leakCheckTime.ToString());
  63. XmlElement root = _dom.SelectSingleNode("/LeakCheckResult") as XmlElement;
  64. root.AppendChild(node);
  65. _dom.Save(_fileName);
  66. }
  67. catch (Exception ex)
  68. {
  69. LOG.Write(ex);
  70. }
  71. }
  72. /*
  73. *
  74. <LeakCheck Date="" StartPressure="" StopPressure
  75. */
  76. public List<LeakCheckResultItem> GetHistoryLeakCheck()
  77. {
  78. List<LeakCheckResultItem> result = new List<LeakCheckResultItem>();
  79. try
  80. {
  81. XmlNodeList lst = _dom.SelectNodes("/LeakCheckResult/LeakCheck");
  82. if (lst != null)
  83. {
  84. foreach (XmlElement element in lst)
  85. {
  86. result.Add(new LeakCheckResultItem()
  87. {
  88. Id = element.GetAttribute("Id"),
  89. Date = Convert.ToDateTime(element.GetAttribute("Date")),
  90. LeakCheckStatus = element.GetAttribute("LeakCheckStatus"),
  91. LeakRate = Convert.ToDouble(element.GetAttribute("LeakRate")),
  92. StartPressure = Convert.ToInt32(element.GetAttribute("StartPressure")),
  93. StopPressure = Convert.ToInt32(element.GetAttribute("StopPressure")),
  94. LeakCheckMode = element.GetAttribute("LeakCheckMode"),
  95. LeakCheckTime = Convert.ToInt32(element.GetAttribute("LeakCheckTime")),
  96. });
  97. }
  98. }
  99. }catch( Exception ex)
  100. {
  101. LOG.Write(ex);
  102. }
  103. return result;
  104. }
  105. public void Delete(string id)
  106. {
  107. try
  108. {
  109. XmlElement node = _dom.SelectSingleNode(string.Format("/LeakCheckResult/LeakCheck[@Id='{0}']", id)) as XmlElement;
  110. node.ParentNode.RemoveChild(node);
  111. _dom.Save(_fileName);
  112. }
  113. catch (Exception ex)
  114. {
  115. LOG.Write(ex);
  116. }
  117. }
  118. }
  119. }