[848] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Text;
|
---|
[849] | 24 | using System.Xml;
|
---|
[848] | 25 |
|
---|
| 26 | namespace HeuristicLab.Tools.ConfigMerger {
|
---|
[849] | 27 | public class ConfigMerger {
|
---|
| 28 | public static void Main(string[] args) {
|
---|
| 29 | try {
|
---|
| 30 | Merge(args[0], args[1]);
|
---|
| 31 | }
|
---|
| 32 | catch (Exception ex) {
|
---|
[2602] | 33 | Console.Out.WriteLine(BuildErrorMessage(ex));
|
---|
[849] | 34 | }
|
---|
[848] | 35 | }
|
---|
[849] | 36 |
|
---|
| 37 | public static void Merge(string sourceFile, string destinationFile) {
|
---|
[3836] | 38 | Console.Out.WriteLine("ConfigMerger: Merge started ...");
|
---|
| 39 | Console.Out.WriteLine("ConfigMerger: Merge source: \"" + sourceFile + "\"");
|
---|
| 40 | Console.Out.WriteLine("ConfigMerger: Merge destination: \"" + destinationFile + "\"");
|
---|
| 41 |
|
---|
[849] | 42 | XmlDocument source = new XmlDocument();
|
---|
| 43 | source.Load(sourceFile);
|
---|
| 44 | XmlDocument destination = new XmlDocument();
|
---|
| 45 | destination.Load(destinationFile);
|
---|
| 46 |
|
---|
| 47 | XmlNode sourceNode;
|
---|
| 48 | XmlNode destinationNode;
|
---|
| 49 |
|
---|
[3284] | 50 | #region Merge 'system.serviceModel/behaviors/*'
|
---|
[943] | 51 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/behaviors");
|
---|
[3284] | 52 | if (destinationNode == null) {
|
---|
| 53 | destinationNode = destination.CreateElement("behaviors");
|
---|
| 54 | destination.SelectSingleNode("/configuration/system.serviceModel").AppendChild(destinationNode);
|
---|
| 55 | }
|
---|
[943] | 56 |
|
---|
[3284] | 57 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/behaviors/endpointBehaviors");
|
---|
| 58 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/behaviors/endpointBehaviors");
|
---|
| 59 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/behaviors");
|
---|
| 60 |
|
---|
| 61 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/behaviors/serviceBehaviors");
|
---|
| 62 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/behaviors/serviceBehaviors");
|
---|
| 63 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/behaviors");
|
---|
| 64 | #endregion
|
---|
| 65 |
|
---|
[943] | 66 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/services");
|
---|
| 67 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/services");
|
---|
| 68 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel");
|
---|
[6173] | 69 |
|
---|
[2697] | 70 | #region Merge 'system.serviceModel/bindings/*'
|
---|
[2725] | 71 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings");
|
---|
| 72 | if (destinationNode == null) {
|
---|
| 73 | destinationNode = destination.CreateElement("bindings");
|
---|
| 74 | destination.SelectSingleNode("/configuration/system.serviceModel").AppendChild(destinationNode);
|
---|
| 75 | }
|
---|
[2697] | 76 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/basicHttpBinding");
|
---|
| 77 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/basicHttpBinding");
|
---|
| 78 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
[943] | 79 |
|
---|
[2697] | 80 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/basicHttpContextBinding");
|
---|
| 81 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/basicHttpContextBinding");
|
---|
| 82 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
[951] | 83 |
|
---|
[2697] | 84 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/customBinding");
|
---|
| 85 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/customBinding");
|
---|
| 86 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 87 |
|
---|
| 88 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/mexHttpBinding");
|
---|
| 89 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/mexHttpBinding");
|
---|
| 90 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 91 |
|
---|
| 92 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/mexHttpsBinding");
|
---|
| 93 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/mexHttpsBinding");
|
---|
| 94 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 95 |
|
---|
| 96 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/mexNamedPipeBinding");
|
---|
| 97 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/mexNamedPipeBinding");
|
---|
| 98 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 99 |
|
---|
| 100 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/mexTcpBinding");
|
---|
| 101 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/mexTcpBinding");
|
---|
| 102 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 103 |
|
---|
| 104 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/msmqIntegrationBinding");
|
---|
| 105 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/msmqIntegrationBinding");
|
---|
| 106 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 107 |
|
---|
| 108 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/netMsmqBinding");
|
---|
| 109 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/netMsmqBinding");
|
---|
| 110 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 111 |
|
---|
| 112 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/netNamedPipeBinding");
|
---|
| 113 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/netNamedPipeBinding");
|
---|
| 114 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 115 |
|
---|
| 116 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/netPeerTcpBinding");
|
---|
| 117 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/netPeerTcpBinding");
|
---|
| 118 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 119 |
|
---|
| 120 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/netTcpBinding");
|
---|
| 121 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/netTcpBinding");
|
---|
| 122 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 123 |
|
---|
| 124 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/netTcpContextBinding");
|
---|
| 125 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/netTcpContextBinding");
|
---|
| 126 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 127 |
|
---|
| 128 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/webHttpBinding");
|
---|
| 129 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/webHttpBinding");
|
---|
| 130 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 131 |
|
---|
| 132 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/ws2007FederationHttpBinding");
|
---|
| 133 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/ws2007FederationHttpBinding");
|
---|
| 134 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 135 |
|
---|
| 136 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/ws2007HttpBinding");
|
---|
| 137 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/ws2007HttpBinding");
|
---|
| 138 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 139 |
|
---|
| 140 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/wsDualHttpBinding");
|
---|
| 141 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/wsDualHttpBinding");
|
---|
| 142 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 143 |
|
---|
| 144 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/wsFederationHttpBinding");
|
---|
| 145 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/wsFederationHttpBinding");
|
---|
| 146 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 147 |
|
---|
| 148 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/wsHttpBinding");
|
---|
| 149 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/wsHttpBinding");
|
---|
| 150 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 151 |
|
---|
| 152 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/bindings/wsHttpContextBinding");
|
---|
| 153 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/bindings/wsHttpContextBinding");
|
---|
| 154 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel/bindings");
|
---|
| 155 | #endregion
|
---|
| 156 |
|
---|
[951] | 157 | sourceNode = source.SelectSingleNode("/configuration/system.serviceModel/client");
|
---|
| 158 | destinationNode = destination.SelectSingleNode("/configuration/system.serviceModel/client");
|
---|
| 159 | Merge(sourceNode, destinationNode, destination, "/configuration/system.serviceModel");
|
---|
| 160 |
|
---|
[849] | 161 | sourceNode = source.SelectSingleNode("/configuration/configSections/sectionGroup[@name='applicationSettings']");
|
---|
| 162 | destinationNode = destination.SelectSingleNode("/configuration/configSections/sectionGroup[@name='applicationSettings']");
|
---|
| 163 | Merge(sourceNode, destinationNode, destination, "/configuration/configSections");
|
---|
| 164 |
|
---|
| 165 | sourceNode = source.SelectSingleNode("/configuration/configSections/sectionGroup[@name='userSettings']");
|
---|
| 166 | destinationNode = destination.SelectSingleNode("/configuration/configSections/sectionGroup[@name='userSettings']");
|
---|
| 167 | Merge(sourceNode, destinationNode, destination, "/configuration/configSections");
|
---|
| 168 |
|
---|
| 169 | sourceNode = source.SelectSingleNode("/configuration/applicationSettings");
|
---|
| 170 | destinationNode = destination.SelectSingleNode("/configuration/applicationSettings");
|
---|
| 171 | Merge(sourceNode, destinationNode, destination, "/configuration");
|
---|
| 172 |
|
---|
| 173 | sourceNode = source.SelectSingleNode("/configuration/userSettings");
|
---|
| 174 | destinationNode = destination.SelectSingleNode("/configuration/userSettings");
|
---|
| 175 | Merge(sourceNode, destinationNode, destination, "/configuration");
|
---|
| 176 |
|
---|
[1142] | 177 | sourceNode = source.SelectSingleNode("/configuration/connectionStrings");
|
---|
| 178 | destinationNode = destination.SelectSingleNode("/configuration/connectionStrings");
|
---|
| 179 | Merge(sourceNode, destinationNode, destination, "/configuration");
|
---|
| 180 |
|
---|
[2692] | 181 | sourceNode = source.SelectSingleNode("/configuration/system.data/DbProviderFactories");
|
---|
| 182 | destinationNode = destination.SelectSingleNode("/configuration/system.data/DbProviderFactories");
|
---|
| 183 | Merge(sourceNode, destinationNode, destination, "/configuration");
|
---|
| 184 |
|
---|
[6173] | 185 | sourceNode = source.SelectSingleNode("/configuration/system.diagnostics");
|
---|
| 186 | destinationNode = destination.SelectSingleNode("/configuration/system.diagnostics");
|
---|
| 187 | Merge(sourceNode, destinationNode, destination, "/configuration");
|
---|
| 188 |
|
---|
[14524] | 189 | sourceNode = source.SelectSingleNode("/configuration/oracle.manageddataaccess.client/version/dataSources");
|
---|
| 190 | destinationNode = destination.SelectSingleNode("/configuration/oracle.manageddataaccess.client/version/dataSources");
|
---|
| 191 | Merge(sourceNode, destinationNode, destination, "/configuration");
|
---|
[16715] | 192 |
|
---|
| 193 | sourceNode = source.SelectSingleNode("/configuration/oracle.manageddataaccess.client/version/settings");
|
---|
| 194 | destinationNode = destination.SelectSingleNode("/configuration/oracle.manageddataaccess.client/version/settings");
|
---|
| 195 | Merge(sourceNode, destinationNode, destination, "/configuration");
|
---|
| 196 |
|
---|
| 197 | sourceNode = source.SelectSingleNode("/configuration/oracle.manageddataaccess.client/version/LDAPsettings");
|
---|
| 198 | destinationNode = destination.SelectSingleNode("/configuration/oracle.manageddataaccess.client/version/LDAPsettings");
|
---|
| 199 | Merge(sourceNode, destinationNode, destination, "/configuration");
|
---|
[6173] | 200 |
|
---|
| 201 |
|
---|
| 202 |
|
---|
[849] | 203 | destination.Save(destinationFile);
|
---|
[3836] | 204 |
|
---|
| 205 | Console.Out.WriteLine("ConfigMerger: Merge successfully finished!");
|
---|
[849] | 206 | }
|
---|
| 207 |
|
---|
| 208 | private static void Merge(XmlNode source, XmlNode destination, XmlDocument document, string root) {
|
---|
[2602] | 209 | try {
|
---|
| 210 | if (source != null) {
|
---|
| 211 | if (destination == null) {
|
---|
| 212 | XmlNode newNode = document.ImportNode(source, true);
|
---|
| 213 | document.SelectSingleNode(root).AppendChild(newNode);
|
---|
| 214 | } else {
|
---|
| 215 | foreach (XmlNode node in source.ChildNodes) {
|
---|
| 216 | XmlNode newNode = document.ImportNode(node, true);
|
---|
| 217 | XmlNode oldNode = destination.SelectSingleNode(BuildXPathString(newNode));
|
---|
| 218 | if (oldNode != null)
|
---|
| 219 | destination.ReplaceChild(newNode, oldNode);
|
---|
| 220 | else
|
---|
| 221 | destination.AppendChild(newNode);
|
---|
| 222 | }
|
---|
[849] | 223 | }
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
[2602] | 226 | catch (Exception ex) {
|
---|
| 227 | StringBuilder sb = new StringBuilder();
|
---|
| 228 | sb.Append("Error while merging node \"").Append(source.Name).Append("\"");
|
---|
| 229 | throw new Exception(sb.ToString(), ex);
|
---|
| 230 | }
|
---|
[849] | 231 | }
|
---|
[875] | 232 |
|
---|
| 233 | private static string BuildXPathString(XmlNode node) {
|
---|
| 234 | StringBuilder builder = new StringBuilder();
|
---|
| 235 | builder.Append(node.Name);
|
---|
| 236 | if (node.Attributes.Count > 0) {
|
---|
| 237 | XmlAttribute attrib = node.Attributes[0];
|
---|
| 238 | builder.Append("[");
|
---|
| 239 | builder.Append("@" + attrib.Name + "='" + attrib.Value + "'");
|
---|
| 240 | for (int i = 1; i < node.Attributes.Count; i++) {
|
---|
| 241 | attrib = node.Attributes[i];
|
---|
| 242 | builder.Append(" and @" + attrib.Name + "='" + attrib.Value + "'");
|
---|
| 243 | }
|
---|
| 244 | builder.Append("]");
|
---|
| 245 | }
|
---|
| 246 | return builder.ToString();
|
---|
| 247 | }
|
---|
[2602] | 248 |
|
---|
| 249 | private static string BuildErrorMessage(Exception ex) {
|
---|
| 250 | StringBuilder sb = new StringBuilder();
|
---|
| 251 | sb.Append("\n\n");
|
---|
| 252 | sb.Append("### ConfigMerger ERROR ###########################################\n" + ex.Message + "\n" + ex.StackTrace + "\n");
|
---|
| 253 | while (ex.InnerException != null) {
|
---|
| 254 | ex = ex.InnerException;
|
---|
| 255 | sb.Append("-----\n" + ex.Message + "\n" + ex.StackTrace + "\n");
|
---|
| 256 | }
|
---|
| 257 | sb.Append("##################################################################\n\n");
|
---|
| 258 | return sb.ToString();
|
---|
| 259 | }
|
---|
[848] | 260 | }
|
---|
| 261 | }
|
---|