/// <summary> /// 获取特定分组下的所有程序信息 /// </summary> /// <returns></returns> public static List <Bases.Program> GetProgramsFromGroup(string groupName) { xmlDoc.Load(xmlpath); if (!isGroupExists(groupName)) { return(null); } XmlNodeList list = mTargetGroupNode.SelectNodes("groupItem"); if (list == null) { return(null); } List <Bases.Program> programList = new List <Bases.Program>(); foreach (XmlNode item in list) { string name = item.SelectSingleNode("name").InnerText; string belong = item.SelectSingleNode("belong").InnerText; Bases.Program program = GetProgram(belong, name); programList.Add(program); } return(programList); }
/// <summary> /// 更新程序信息 /// </summary> /// <param name="deviceName">设备名</param> /// <param name="program">程序对象</param> public static void UpdateProgram(string deviceName, Bases.Program program) { xmlDoc.Load(xmlpath); if (isProgramExists(deviceName, program.Name)) { mTargetProgramNode.SelectSingleNode("name").InnerText = program.Name; mTargetProgramNode.SelectSingleNode("path").InnerText = program.Path; mTargetProgramNode.SelectSingleNode("args").InnerText = program.Args; } xmlDoc.Save(xmlpath); }
/// <summary> /// 写入程序信息 /// </summary> /// <param name="program">程序对象</param> public static void WriteProgram(Bases.Program program) { xmlDoc.Load(xmlpath); string deviceName = program.BelongDevice; if (!isDeviceExists(deviceName)) { return; } // Create device.DeviceName element XmlElement ele0 = xmlDoc.CreateElement("name"); XmlText text0 = xmlDoc.CreateTextNode(program.Name.ToString()); // Create device.DeviceUser element XmlElement ele1 = xmlDoc.CreateElement("path"); XmlText text1 = xmlDoc.CreateTextNode(program.Path.ToString()); // Create device.DevicePwd element XmlElement ele2 = xmlDoc.CreateElement("args"); XmlText text2 = xmlDoc.CreateTextNode(program.Args.ToString()); XmlElement ele3 = xmlDoc.CreateElement("belong"); XmlText text3 = xmlDoc.CreateTextNode(program.BelongDevice.ToString()); // Create the program Node XmlNode programNode = xmlDoc.CreateNode(XmlNodeType.Element, "program", ""); // Add elements to this node programNode.AppendChild(ele0); programNode.LastChild.AppendChild(text0); programNode.AppendChild(ele1); programNode.LastChild.AppendChild(text1); programNode.AppendChild(ele2); programNode.LastChild.AppendChild(text2); programNode.AppendChild(ele3); programNode.LastChild.AppendChild(text3); // Append the programNode to targetNode mTargetDeviceNode.AppendChild(programNode); xmlDoc.Save(xmlpath); }