/// <summary> /// 解析XML的设备信息 /// </summary> /// <param name="xmlNodeList"></param> internal void Analyze(XmlNodeList xmlNodeList) { _devdefs.Clear(); if (xmlNodeList == null || xmlNodeList.Count == 0) { Console.WriteLine("没有设备信息可以进行解析"); return; } foreach (XmlElement e in xmlNodeList) { string id = e.GetAttribute("id"); string name = e.GetAttribute("name"); string connecttype = e.GetAttribute("connecttype"); Devdef devdef = new Devdef(id, name, connecttype); foreach (XmlElement a in e.ChildNodes) { string attid = a.GetAttribute("id"); string attname = a.GetAttribute("name"); int start = int.Parse(a.GetAttribute("start")); int ent = int.Parse(a.GetAttribute("end")); DevAtt devAtt = new DevAtt(attid, attname, start, ent); foreach (XmlElement d in a.ChildNodes) { string key = d.GetAttribute("key"); string value = d.GetAttribute("value"); AttDic attDic = new AttDic(key, value); devAtt.AddAttDic(attDic); } devdef.AddDevAtt(devAtt); } _devdefs.Add(devdef); } }
/// <summary> /// 添加设备定义操作类 /// </summary> /// <param name="devdef"></param> public void AddDevdef(Devdef devdef) { XmlElement devX = XMLMaster.XMLHelper._xmldoc.CreateElement("Devdef"); devX.SetAttribute("id", devdef.ID); devX.SetAttribute("name", devdef.Name); devX.SetAttribute("connecttype", devdef.ConnetType); XMLMaster.XMLHelper.AddToNode("//Config/Devdefs", devX); }
/// <summary> /// 修改设备定义 /// </summary> /// <param name="devdef"></param> public void EditeDevdef(Devdef devdef) { ////Config/Devdefs/Devdef[id='AGV'] XmlElement devdefx = XMLMaster.XMLHelper.GetSingleNode("//Config/Devdefs/Devdef[@id='" + devdef.ID + "']"); if (devdefx != null) { if (devdefx.GetAttribute("id").Equals(devdef.ID)) { devdefx.SetAttribute("name", devdef.Name); devdefx.SetAttribute("connecttype", devdef.ConnetType); } } }
/// <summary> /// 修改设备定义的信息 /// </summary> /// <param name="devdef">设备类型信息</param> public static void EditeDevdef(Devdef devdef) { Devdefs.EditeDevdef(devdef); SaveAndReload(); }
/// <summary> /// 添加设备定义 /// </summary> /// <param name="devdef">设备类型信息</param> public static void AddDevdef(Devdef devdef) { Devdefs.AddDevdef(devdef); SaveAndReload(); }