Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/08 02:30:13 (16 years ago)
Author:
swagner
Message:

Implemented first functional prototype of ConfigMerger (#402)

Location:
trunk/tools/ConfigMerger
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/tools/ConfigMerger/ConfigMerger.cs

    r848 r849  
    2424using System.Linq;
    2525using System.Text;
     26using System.Xml;
    2627
    2728namespace HeuristicLab.Tools.ConfigMerger {
    28   class Program {
    29     static void Main(string[] args) {
     29  public class ConfigMerger {
     30    public static void Main(string[] args) {
     31      try {
     32        Merge(args[0], args[1]);
     33      }
     34      catch (Exception ex) {
     35        Console.Out.WriteLine(ex.Message);
     36      }
     37    }
     38
     39    public static void Merge(string sourceFile, string destinationFile) {
     40      XmlDocument source = new XmlDocument();
     41      source.Load(sourceFile);
     42      XmlDocument destination = new XmlDocument();
     43      destination.Load(destinationFile);
     44
     45      XmlNode sourceNode;
     46      XmlNode destinationNode;
     47
     48      sourceNode = source.SelectSingleNode("/configuration/configSections/sectionGroup[@name='applicationSettings']");
     49      destinationNode = destination.SelectSingleNode("/configuration/configSections/sectionGroup[@name='applicationSettings']");
     50      Merge(sourceNode, destinationNode, destination, "/configuration/configSections");
     51
     52      sourceNode = source.SelectSingleNode("/configuration/configSections/sectionGroup[@name='userSettings']");
     53      destinationNode = destination.SelectSingleNode("/configuration/configSections/sectionGroup[@name='userSettings']");
     54      Merge(sourceNode, destinationNode, destination, "/configuration/configSections");
     55
     56      sourceNode = source.SelectSingleNode("/configuration/applicationSettings");
     57      destinationNode = destination.SelectSingleNode("/configuration/applicationSettings");
     58      Merge(sourceNode, destinationNode, destination, "/configuration");
     59
     60      sourceNode = source.SelectSingleNode("/configuration/userSettings");
     61      destinationNode = destination.SelectSingleNode("/configuration/userSettings");
     62      Merge(sourceNode, destinationNode, destination, "/configuration");
     63
     64      destination.Save(destinationFile);
     65    }
     66
     67    private static void Merge(XmlNode source, XmlNode destination, XmlDocument document, string root) {
     68      if (source != null) {
     69        if (destination == null) {
     70          XmlNode clone = document.ImportNode(source, true);
     71          document.SelectSingleNode(root).AppendChild(clone);
     72        } else {
     73          foreach (XmlNode node in source.ChildNodes) {
     74            XmlNode clone = document.ImportNode(node, true);
     75            destination.AppendChild(clone);
     76          }
     77        }
     78      }
    3079    }
    3180  }
  • trunk/tools/ConfigMerger/ConfigMerger.csproj

    r848 r849  
    1515    <SignAssembly>true</SignAssembly>
    1616    <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
    17     <StartupObject>HeuristicLab.Tools.ConfigMerger.Program</StartupObject>
     17    <StartupObject>HeuristicLab.Tools.ConfigMerger.ConfigMerger</StartupObject>
    1818  </PropertyGroup>
    1919  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     
    5050  </ItemGroup>
    5151  <ItemGroup>
    52     <Compile Include="Program.cs" />
     52    <Compile Include="ConfigMerger.cs" />
    5353    <Compile Include="Properties\AssemblyInfo.cs" />
    5454  </ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.