UniformCodeInfoSvc.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using log4net;
  8. namespace IntelligentControlForsx.Service.WindturbineInfo
  9. {
  10. public class UniformCodeInfoSvc
  11. {
  12. private static ILog logger = LogManager.GetLogger("AppInfoLog");
  13. /// <summary>
  14. /// 从xml配置信息中读取统一编码等信息
  15. /// </summary>
  16. /// <param name="stationId">场站编号</param>
  17. /// <param name="modelId">风机型号</param>
  18. /// <param name="controlName">所属功能</param>
  19. /// <returns></returns>
  20. public static IList<UniformCodeInfo> GetUniformCode(string stationId, string modelId, string controlName, string part = null)
  21. {
  22. IList<UniformCodeInfo> list = new List<UniformCodeInfo>();
  23. string path = Environment.CurrentDirectory;
  24. string filePath = path + "\\conf\\UniformCode.xml";
  25. XmlDocument xdoc = new XmlDocument();
  26. xdoc.Load(filePath); //加载xml文档
  27. XmlNodeList rootList = xdoc.SelectNodes("/root");
  28. if (rootList != null && rootList.Count > 0)
  29. {
  30. XmlNodeList stationNodeList = rootList[0].ChildNodes;
  31. foreach (XmlNode stationNode in stationNodeList)
  32. {
  33. string stationName = stationNode.Attributes["name"].Value;
  34. if (stationName == stationId)
  35. {
  36. XmlNodeList modelNodeList = stationNode.ChildNodes;
  37. foreach (XmlNode modelNode in modelNodeList)
  38. {
  39. string modelName = modelNode.Attributes["name"].Value;
  40. if (modelName == modelId)
  41. {
  42. XmlNodeList controlNodeList = modelNode.ChildNodes;
  43. foreach (XmlNode controlNode in controlNodeList)
  44. {
  45. string controlListName = controlNode.Attributes["name"].Value;
  46. if (controlListName == controlName)
  47. {
  48. XmlNodeList partNodeList = controlNode.ChildNodes;
  49. foreach (XmlNode partNode in partNodeList)
  50. {
  51. string partIndex = partNode.Attributes["index"].Value;
  52. string partName = partNode.Attributes["text"].Value;
  53. if (part != null)
  54. {
  55. if (partIndex == part)
  56. {
  57. XmlNodeList paramNodeList = partNode.ChildNodes;
  58. foreach (XmlNode paramNode in paramNodeList)
  59. {
  60. string plcName = "";
  61. string lblName = "";
  62. int? lblIndex = null;
  63. string lblUniformCode = "";
  64. string lblUnit = "";
  65. string lblWarningNum = "";
  66. try
  67. {
  68. if (paramNode.Attributes["plcName"] != null)
  69. plcName = paramNode.Attributes["plcName"].Value;
  70. if (paramNode.Attributes["name"] != null)
  71. lblName = paramNode.Attributes["name"].Value;
  72. if (paramNode.Attributes["num"] != null)
  73. lblIndex = Convert.ToInt32(paramNode.Attributes["num"].Value);
  74. if (paramNode.Attributes["value"] != null)
  75. lblUniformCode = paramNode.Attributes["value"].Value;
  76. if (paramNode.Attributes["unit"] != null)
  77. lblUnit = paramNode.Attributes["unit"].Value;
  78. if (paramNode.Attributes["warningNum"] != null)
  79. lblWarningNum = paramNode.Attributes["warningNum"].Value;
  80. UniformCodeInfo data = new UniformCodeInfo();
  81. data.PartIndex = partIndex;
  82. data.PartName = partName;
  83. data.UniformCode = lblUniformCode;
  84. data.Index = lblIndex.HasValue ? lblIndex.Value : 0;
  85. data.Unit = lblUnit;
  86. data.Name = lblName;
  87. data.PlcName = plcName;
  88. data.WarningNum = lblWarningNum;
  89. list.Add(data);
  90. }
  91. catch (Exception ex)
  92. {
  93. logger.Info("xml配置读取错误:" + ex.Message);
  94. }
  95. }
  96. }
  97. }
  98. else
  99. {
  100. XmlNodeList paramNodeList = partNode.ChildNodes;
  101. foreach (XmlNode paramNode in paramNodeList)
  102. {
  103. string plcName = "";
  104. string lblName = "";
  105. int? lblIndex = null;
  106. string lblUniformCode = "";
  107. string lblUnit = "";
  108. string lblWarningNum = "";
  109. try
  110. {
  111. if (paramNode.Attributes["plcName"] != null)
  112. plcName = paramNode.Attributes["plcName"].Value;
  113. if (paramNode.Attributes["name"] != null)
  114. lblName = paramNode.Attributes["name"].Value;
  115. if (paramNode.Attributes["num"] != null)
  116. lblIndex = Convert.ToInt32(paramNode.Attributes["num"].Value);
  117. if (paramNode.Attributes["value"] != null)
  118. lblUniformCode = paramNode.Attributes["value"].Value;
  119. if (paramNode.Attributes["unit"] != null)
  120. lblUnit = paramNode.Attributes["unit"].Value;
  121. if (paramNode.Attributes["warningNum"] != null)
  122. lblWarningNum = paramNode.Attributes["warningNum"].Value;
  123. UniformCodeInfo data = new UniformCodeInfo();
  124. data.PartIndex = partIndex;
  125. data.PartName = partName;
  126. data.UniformCode = lblUniformCode;
  127. data.Index = lblIndex.HasValue ? lblIndex.Value : 0;
  128. data.Unit = lblUnit;
  129. data.Name = lblName;
  130. data.PlcName = plcName;
  131. data.WarningNum = lblWarningNum;
  132. list.Add(data);
  133. }
  134. catch (Exception ex)
  135. {
  136. logger.Info("xml配置读取错误:" + ex.Message);
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }
  148. return list;
  149. }
  150. }
  151. }