public void Save() { List <XmlNode> unknownSections = GetUnknownSections(); XmlDocument doc = new XmlDocument(); XmlNode rootNode = doc.CreateElement(_rootSectionName); doc.AppendChild(rootNode); doc.Save(_fileName); foreach (KeyValuePair <String, ProgramConfiguration> kvp in _configurations) { // XmlNode sectionNode = doc.AddSubNode(kvp.Key); XmlNode subNode = KanoopSerializableObject.Serialize(kvp.Value, doc.DocumentElement); // sectionNode.AddSubNode(subNode); // doc.AddSubNode(subNode); } foreach (XmlNode node in unknownSections) { doc.AddSubNode(node); } doc.Save(_fileName); }
void LoadProgramConfigurations() { Configurations.Clear(); /** load the XML file */ XmlDocument doc = new XmlDocument(); doc.Load(_fileName); /** load each program confguration within it */ foreach (XmlNode node in doc.DocumentElement.ChildNodes) { String configTypeName; Type configurationType; if (node.Attributes != null && node.TryGetAttribute(SerializationXML.ATTR_TYPE, out configTypeName) && (configurationType = KanoopSerializableObject.GetTypeFromAssembly(configTypeName)) != null && configurationType.IsSubclassOf(typeof(ProgramConfiguration))) { Object config = KanoopSerializableObject.Deserialize(node); ((ProgramConfiguration)config).ConfigFile = this; Configurations.Add(configurationType.FullName, (ProgramConfiguration)config); ((ProgramConfiguration)config).ConfigLoadComplete(); } } }
List <XmlNode> GetUnknownSections() { List <XmlNode> unknownSections = new List <XmlNode>(); /** load the XML file */ XmlDocument doc = new XmlDocument(); doc.Load(_fileName); /** save off any sections we can't resolve in this assembly */ foreach (XmlNode node in doc.DocumentElement.ChildNodes) { String configType; if (node.TryGetAttribute(SerializationXML.ATTR_TYPE, out configType) && KanoopSerializableObject.GetTypeFromAssembly(configType) == null) { unknownSections.Add(node); } } return(unknownSections); }