public static IEnumerable <ReadPluginInfo> ReadConfigFile(string configFilePath) { var fileFound = File.Exists(configFilePath); if (!fileFound) { return(null); } var readPlugins = new List <ReadPluginInfo>(); //read the file stream var fileStream = new FileStream(configFilePath, FileMode.Open); //create the reader var xmlReader = XmlReader.Create(fileStream); ReadPluginInfo currentInfo = null; while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: if (xmlReader.Name == "plugins") { continue; } currentInfo = new ReadPluginInfo() { Active = Convert.ToBoolean(xmlReader.GetAttribute("active")), Installed = Convert.ToBoolean(xmlReader.GetAttribute("installed")) }; break; case XmlNodeType.Text: if (currentInfo != null) { currentInfo.SystemName = xmlReader.Value; } break; case XmlNodeType.EndElement: if (currentInfo != null) { readPlugins.Add(currentInfo); } currentInfo = null; break; } } //close the stream fileStream.Close(); return(readPlugins); }
public static IEnumerable<ReadPluginInfo> ReadConfigFile(string configFilePath) { var fileFound = File.Exists(configFilePath); if (!fileFound) return null; var readPlugins = new List<ReadPluginInfo>(); //read the file stream var fileStream = new FileStream(configFilePath, FileMode.Open); //create the reader var xmlReader = XmlReader.Create(fileStream); ReadPluginInfo currentInfo = null; while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: if (xmlReader.Name == "plugins") continue; currentInfo = new ReadPluginInfo() { Active = Convert.ToBoolean(xmlReader.GetAttribute("active")), Installed = Convert.ToBoolean(xmlReader.GetAttribute("installed")) }; break; case XmlNodeType.Text: if (currentInfo != null) currentInfo.SystemName = xmlReader.Value; break; case XmlNodeType.EndElement: readPlugins.Add(currentInfo); currentInfo = null; break; } } //close the stream fileStream.Close(); return readPlugins; }