FileHelper.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. namespace OTSModelSharp.ServiceCenter
  9. {
  10. public static class FileHelper
  11. {
  12. static XmlDocument Hardwareconfigdoc=null;
  13. public static string GetFolderName(string a_strPathName)
  14. {
  15. if (a_strPathName == "Untitled")
  16. {
  17. return null;
  18. }
  19. string folderName = a_strPathName.Substring(0, a_strPathName.LastIndexOf("\\"));
  20. return folderName;
  21. }
  22. public static string GetXMLInformations(string Name)
  23. {
  24. try
  25. {
  26. XmlDocument doc;
  27. string value = string.Empty;
  28. if (Hardwareconfigdoc == null)
  29. {
  30. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  31. Hardwareconfigdoc = new XmlDocument();
  32. Hardwareconfigdoc.Load(xmlFilePath); //加载Xml文件
  33. doc = Hardwareconfigdoc;
  34. }
  35. else
  36. {
  37. doc = Hardwareconfigdoc;
  38. }
  39. XmlElement root = doc.DocumentElement; //获取根节点
  40. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  41. foreach (XmlNode node in mainNodes)
  42. {
  43. //获取Name属性值
  44. string name = ((XmlElement)node).GetAttribute("RegName");
  45. if (name.Equals(Name))
  46. {
  47. value = ((XmlElement)node).GetAttribute("Value");
  48. break;
  49. }
  50. }
  51. return value;
  52. }
  53. catch (Exception)
  54. {
  55. return "";
  56. }
  57. }
  58. /// <summary>
  59. /// 获取XML节点参数
  60. /// </summary>
  61. /// <param name="Name">节点参数名称</param>
  62. /// <returns>节点参数</returns>
  63. public static string GetIfDelayQuantify()
  64. {
  65. try
  66. {
  67. XmlDocument doc;
  68. string value = string.Empty;
  69. if (Hardwareconfigdoc == null)
  70. {
  71. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  72. Hardwareconfigdoc = new XmlDocument();
  73. Hardwareconfigdoc.Load(xmlFilePath); //加载Xml文件
  74. doc = Hardwareconfigdoc;
  75. }
  76. else
  77. {
  78. doc = Hardwareconfigdoc;
  79. }
  80. XmlElement root = doc.DocumentElement; //获取根节点
  81. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  82. foreach (XmlNode node in mainNodes)
  83. {
  84. //获取Name属性值
  85. string name = ((XmlElement)node).GetAttribute("RegName");
  86. if (name.Equals("EDSName"))
  87. {
  88. value = ((XmlElement)node).GetAttribute("DelayQuantify");
  89. break;
  90. }
  91. }
  92. return value;
  93. }
  94. catch (Exception)
  95. {
  96. return "false";
  97. }
  98. }
  99. public static string GetOxfordInputSourceType()
  100. {
  101. try
  102. {
  103. string value = string.Empty;
  104. XmlDocument doc = new XmlDocument();
  105. if (Hardwareconfigdoc == null)
  106. {
  107. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  108. Hardwareconfigdoc = new XmlDocument();
  109. Hardwareconfigdoc.Load(xmlFilePath); //加载Xml文件
  110. doc = Hardwareconfigdoc;
  111. }
  112. else
  113. {
  114. doc = Hardwareconfigdoc;
  115. }
  116. XmlElement root = doc.DocumentElement; //获取根节点
  117. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  118. foreach (XmlNode node in mainNodes)
  119. {
  120. //获取Name属性值
  121. string name = ((XmlElement)node).GetAttribute("RegName");
  122. if (name.Equals("SemControllerName"))
  123. {
  124. value = ((XmlElement)node).GetAttribute("ImageInputSources");
  125. break;
  126. }
  127. }
  128. return value;
  129. }
  130. catch (Exception)
  131. {
  132. return "";
  133. }
  134. }
  135. }
  136. }