123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using log4net;
- namespace IntelligentControlForsx.Service.WindturbineInfo
- {
- public class UniformCodeInfoSvc
- {
- private static ILog logger = LogManager.GetLogger("AppInfoLog");
- /// <summary>
- /// 从xml配置信息中读取统一编码等信息
- /// </summary>
- /// <param name="stationId">场站编号</param>
- /// <param name="modelId">风机型号</param>
- /// <param name="controlName">所属功能</param>
- /// <returns></returns>
- public static IList<UniformCodeInfo> GetUniformCode(string stationId, string modelId, string controlName, string part = null)
- {
- IList<UniformCodeInfo> list = new List<UniformCodeInfo>();
- string path = Environment.CurrentDirectory;
- string filePath = path + "\\conf\\UniformCode.xml";
- XmlDocument xdoc = new XmlDocument();
- xdoc.Load(filePath); //加载xml文档
- XmlNodeList rootList = xdoc.SelectNodes("/root");
- if (rootList != null && rootList.Count > 0)
- {
- XmlNodeList stationNodeList = rootList[0].ChildNodes;
- foreach (XmlNode stationNode in stationNodeList)
- {
- string stationName = stationNode.Attributes["name"].Value;
- if (stationName == stationId)
- {
- XmlNodeList modelNodeList = stationNode.ChildNodes;
- foreach (XmlNode modelNode in modelNodeList)
- {
- string modelName = modelNode.Attributes["name"].Value;
- if (modelName == modelId)
- {
- XmlNodeList controlNodeList = modelNode.ChildNodes;
- foreach (XmlNode controlNode in controlNodeList)
- {
- string controlListName = controlNode.Attributes["name"].Value;
- if (controlListName == controlName)
- {
- XmlNodeList partNodeList = controlNode.ChildNodes;
- foreach (XmlNode partNode in partNodeList)
- {
- string partIndex = partNode.Attributes["index"].Value;
- string partName = partNode.Attributes["text"].Value;
- if (part != null)
- {
- if (partIndex == part)
- {
- XmlNodeList paramNodeList = partNode.ChildNodes;
- foreach (XmlNode paramNode in paramNodeList)
- {
- string plcName = "";
- string lblName = "";
- int? lblIndex = null;
- string lblUniformCode = "";
- string lblUnit = "";
- string lblWarningNum = "";
- try
- {
- if (paramNode.Attributes["plcName"] != null)
- plcName = paramNode.Attributes["plcName"].Value;
- if (paramNode.Attributes["name"] != null)
- lblName = paramNode.Attributes["name"].Value;
- if (paramNode.Attributes["num"] != null)
- lblIndex = Convert.ToInt32(paramNode.Attributes["num"].Value);
- if (paramNode.Attributes["value"] != null)
- lblUniformCode = paramNode.Attributes["value"].Value;
- if (paramNode.Attributes["unit"] != null)
- lblUnit = paramNode.Attributes["unit"].Value;
- if (paramNode.Attributes["warningNum"] != null)
- lblWarningNum = paramNode.Attributes["warningNum"].Value;
- UniformCodeInfo data = new UniformCodeInfo();
- data.PartIndex = partIndex;
- data.PartName = partName;
- data.UniformCode = lblUniformCode;
- data.Index = lblIndex.HasValue ? lblIndex.Value : 0;
- data.Unit = lblUnit;
- data.Name = lblName;
- data.PlcName = plcName;
- data.WarningNum = lblWarningNum;
- list.Add(data);
- }
- catch (Exception ex)
- {
- logger.Info("xml配置读取错误:" + ex.Message);
- }
- }
- }
- }
- else
- {
- XmlNodeList paramNodeList = partNode.ChildNodes;
- foreach (XmlNode paramNode in paramNodeList)
- {
- string plcName = "";
- string lblName = "";
- int? lblIndex = null;
- string lblUniformCode = "";
- string lblUnit = "";
- string lblWarningNum = "";
- try
- {
- if (paramNode.Attributes["plcName"] != null)
- plcName = paramNode.Attributes["plcName"].Value;
- if (paramNode.Attributes["name"] != null)
- lblName = paramNode.Attributes["name"].Value;
- if (paramNode.Attributes["num"] != null)
- lblIndex = Convert.ToInt32(paramNode.Attributes["num"].Value);
- if (paramNode.Attributes["value"] != null)
- lblUniformCode = paramNode.Attributes["value"].Value;
- if (paramNode.Attributes["unit"] != null)
- lblUnit = paramNode.Attributes["unit"].Value;
- if (paramNode.Attributes["warningNum"] != null)
- lblWarningNum = paramNode.Attributes["warningNum"].Value;
- UniformCodeInfo data = new UniformCodeInfo();
- data.PartIndex = partIndex;
- data.PartName = partName;
- data.UniformCode = lblUniformCode;
- data.Index = lblIndex.HasValue ? lblIndex.Value : 0;
- data.Unit = lblUnit;
- data.Name = lblName;
- data.PlcName = plcName;
- data.WarningNum = lblWarningNum;
- list.Add(data);
- }
- catch (Exception ex)
- {
- logger.Info("xml配置读取错误:" + ex.Message);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return list;
- }
- }
- }
|