Free cookie consent management tool by TermsFeed Policy Generator

Changeset 875 for trunk/tools


Ignore:
Timestamp:
11/30/08 00:40:01 (16 years ago)
Author:
swagner
Message:

Enhanced ConfigMerger to prevent multiple merges of application and user settings (#409)

File:
1 edited

Legend:

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

    r849 r875  
    6868      if (source != null) {
    6969        if (destination == null) {
    70           XmlNode clone = document.ImportNode(source, true);
    71           document.SelectSingleNode(root).AppendChild(clone);
     70          XmlNode newNode = document.ImportNode(source, true);
     71          document.SelectSingleNode(root).AppendChild(newNode);
    7272        } else {
    7373          foreach (XmlNode node in source.ChildNodes) {
    74             XmlNode clone = document.ImportNode(node, true);
    75             destination.AppendChild(clone);
     74            XmlNode newNode = document.ImportNode(node, true);
     75            XmlNode oldNode = destination.SelectSingleNode(BuildXPathString(newNode));
     76            if (oldNode != null)
     77              destination.ReplaceChild(newNode, oldNode);
     78            else
     79              destination.AppendChild(newNode);
    7680          }
    7781        }
    7882      }
    7983    }
     84
     85    private static string BuildXPathString(XmlNode node) {
     86      StringBuilder builder = new StringBuilder();
     87      builder.Append(node.Name);
     88      if (node.Attributes.Count > 0) {
     89        XmlAttribute attrib = node.Attributes[0];
     90        builder.Append("[");
     91        builder.Append("@" + attrib.Name + "='" + attrib.Value + "'");
     92        for (int i = 1; i < node.Attributes.Count; i++) {
     93          attrib = node.Attributes[i];
     94          builder.Append(" and @" + attrib.Name + "='" + attrib.Value + "'");
     95        }
     96        builder.Append("]");
     97      }
     98      return builder.ToString();
     99    }
    80100  }
    81101}
Note: See TracChangeset for help on using the changeset viewer.