+2006-11-28 Marek Habersack <grendello@gmail.com>
+
+ * SectionGroupInfo.cs: Implement merging of section groups with
+ the same names and parents.
+
+ * ConfigInfo.cs: Add an abstract method for merging sections.
+
+ * SectionInfo.cs: Add implementation of an abstract base method
+
2006-08-23 Konstantin Triger <kostat@mainsoft.com>
* SectionInfo.cs: refactoring - remove unneeded bool? usage.
public abstract void WriteConfig (Configuration cfg, XmlWriter writer, ConfigurationSaveMode mode);
public abstract void ReadData (Configuration config, XmlTextReader reader, bool overrideAllowed);
public abstract void WriteData (Configuration config, XmlWriter writer, ConfigurationSaveMode mode);
+
+ internal abstract void Merge (ConfigInfo data);
}
}
if (name == "section")
cinfo = new SectionInfo ();
- else if (name == "sectionGroup")
+ else if (name == "sectionGroup") {
cinfo = new SectionGroupInfo ();
- else
+ } else
ThrowException ("Unrecognized element: " + reader.Name, reader);
cinfo.ReadConfig (cfg, streamName, reader);
if (actInfo != null) {
if (actInfo.GetType () != cinfo.GetType ())
ThrowException ("A section or section group named '" + cinfo.Name + "' already exists", reader);
+ // Merge all the new data
+ actInfo.Merge (cinfo);
+
// Make sure that this section is saved in this configuration file:
actInfo.StreamName = streamName;
}
if (data != null)
return data;
}
+ // It might be in the root section group
return null;
}
+ internal override void Merge (ConfigInfo newData)
+ {
+ SectionGroupInfo data = newData as SectionGroupInfo;
+ if (data == null)
+ return;
+ ConfigInfo actInfo;
+ if (data.sections != null && data.sections.Count > 0)
+ foreach (string key in data.sections.AllKeys) {
+ actInfo = sections[key];
+ if (actInfo != null)
+ continue;
+ sections.Add (key, data.sections[key]);
+ }
+
+ if (data.groups != null && data.sections.Count > 0)
+ foreach (string key in data.groups.AllKeys) {
+ actInfo = groups[key];
+ if (actInfo != null)
+ continue;
+ groups.Add (key, data.groups[key]);
+ }
+ }
+
public void WriteRootData (XmlWriter writer, Configuration config, ConfigurationSaveMode mode)
{
WriteContent (writer, config, mode, false);