FileHelper.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. /// <summary>
  23. /// 获取XML节点参数
  24. /// </summary>
  25. /// <param name="Name">节点参数名称</param>
  26. /// <returns>节点参数</returns>
  27. public static string GetXMLInformations(string Name)
  28. {
  29. try
  30. {
  31. XmlDocument doc;
  32. string value = string.Empty;
  33. if (Hardwareconfigdoc == null)
  34. {
  35. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  36. Hardwareconfigdoc = new XmlDocument();
  37. Hardwareconfigdoc.Load(xmlFilePath); //加载Xml文件
  38. doc = Hardwareconfigdoc;
  39. }
  40. else
  41. {
  42. doc = Hardwareconfigdoc;
  43. }
  44. XmlElement root = doc.DocumentElement; //获取根节点
  45. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  46. foreach (XmlNode node in mainNodes)
  47. {
  48. //获取Name属性值
  49. string name = ((XmlElement)node).GetAttribute("RegName");
  50. if (name.Equals(Name))
  51. {
  52. value = ((XmlElement)node).GetAttribute("Value");
  53. break;
  54. }
  55. }
  56. return value;
  57. }
  58. catch (Exception)
  59. {
  60. return "";
  61. }
  62. }
  63. public static string GetOxfordInputSourceType()
  64. {
  65. try
  66. {
  67. string value = string.Empty;
  68. XmlDocument doc = new XmlDocument();
  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("SemControllerName"))
  87. {
  88. value = ((XmlElement)node).GetAttribute("ImageInputSources");
  89. break;
  90. }
  91. }
  92. return value;
  93. }
  94. catch (Exception)
  95. {
  96. return "";
  97. }
  98. }
  99. }
  100. }