123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Xml;
- using Aitex.Common.Util;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using Aitex.Triton160.Common;
- namespace Aitex.Triton160.RT.Module
- {
- class LeakCheckResultManager : Singleton<LeakCheckResultManager>
- {
- 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>";
- private XmlDocument _dom = new XmlDocument();
- string _fileName = PathManager.GetCfgDir() + "\\LeakCheckResult.xml";
-
- public void Initialize()
- {
- try
- {
-
- if (!File.Exists(_fileName))
- {
- _dom.LoadXml(_template);
- _dom.Save(_fileName);
- }
- else
- {
- _dom.Load(_fileName);
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- throw;
- }
- }
- /*
- *
- *
- * Date = Convert.ToDateTime(element.GetAttribute("Date")),
- LeakCheckStatus = element.GetAttribute("LeakCheckStatus"),
- LeakRate = Convert.ToDouble(element.GetAttribute("LeakCheckStatus")),
- StartPressure = Convert.ToInt32(element.GetAttribute("StartPressure")),
- StopPressure = Convert.ToInt32(element.GetAttribute("StopPressure")),
- LeakCheckMode = element.GetAttribute("LeakCheckMode"),
- LeakCheckTime = Convert.ToInt32(element.GetAttribute("LeakCheckTime")),
- *
- */
- public void AddLeakCheck(DateTime date, int leakCheckTime, int beginPressure, int endPressure, double leakRate, string status, string mode)
- {
- try
- {
- XmlElement node = _dom.CreateNode(XmlNodeType.Element, "LeakCheck", _dom.NamespaceURI) as XmlElement;
- node.SetAttribute("Id", Guid.NewGuid().ToString());
- node.SetAttribute("Date", date.ToString("yyyy-MM-dd HH:mm:ss.fff"));
- node.SetAttribute("LeakCheckStatus", status);
- node.SetAttribute("LeakRate", leakRate.ToString("F5"));
- node.SetAttribute("StartPressure", beginPressure.ToString());
- node.SetAttribute("StopPressure", endPressure.ToString());
- node.SetAttribute("LeakCheckMode", mode);
- node.SetAttribute("LeakCheckTime", leakCheckTime.ToString());
- XmlElement root = _dom.SelectSingleNode("/LeakCheckResult") as XmlElement;
- root.AppendChild(node);
- _dom.Save(_fileName);
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
-
- }
- /*
- *
- <LeakCheck Date="" StartPressure="" StopPressure
- */
- public List<LeakCheckResultItem> GetHistoryLeakCheck()
- {
- List<LeakCheckResultItem> result = new List<LeakCheckResultItem>();
- try
- {
- XmlNodeList lst = _dom.SelectNodes("/LeakCheckResult/LeakCheck");
- if (lst != null)
- {
- foreach (XmlElement element in lst)
- {
- result.Add(new LeakCheckResultItem()
- {
- Id = element.GetAttribute("Id"),
- Date = Convert.ToDateTime(element.GetAttribute("Date")),
- LeakCheckStatus = element.GetAttribute("LeakCheckStatus"),
- LeakRate = Convert.ToDouble(element.GetAttribute("LeakRate")),
- StartPressure = Convert.ToInt32(element.GetAttribute("StartPressure")),
- StopPressure = Convert.ToInt32(element.GetAttribute("StopPressure")),
- LeakCheckMode = element.GetAttribute("LeakCheckMode"),
- LeakCheckTime = Convert.ToInt32(element.GetAttribute("LeakCheckTime")),
- });
- }
- }
- }catch( Exception ex)
- {
- LOG.Write(ex);
- }
- return result;
- }
- public void Delete(string id)
- {
- try
- {
- XmlElement node = _dom.SelectSingleNode(string.Format("/LeakCheckResult/LeakCheck[@Id='{0}']", id)) as XmlElement;
- node.ParentNode.RemoveChild(node);
- _dom.Save(_fileName);
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- }
- }
|