private static void MergePropertyAndGroup()

in src/TestFramework/Core/ConfigurationReader.cs [668:753]


        private static void MergePropertyAndGroup(XmlNode newParent, XmlNode mergingParent, string name)
        {
            Dictionary<string, XmlNode> propertyDict = new Dictionary<string, XmlNode>();
            Dictionary<string, XmlNode> groupDict = new Dictionary<string, XmlNode>();
            string value = "";
            //record the first property node where the Group node to insert before
            XmlNode firstProperty = null;
            foreach (XmlNode child in mergingParent.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element)
                {
                    value = child.Attributes[name].Value;
                    try
                    {
                        if (child.Name == "Property")
                        {
                            propertyDict.Add(value, child);
                        }
                        else
                            groupDict.Add(value, child);
                    }
                    catch
                    {
                        throw new InvalidOperationException("Duplicate node with type\"" + child.Name + "name \"" + name + "\"=\"" + value + "\" found.");
                    }
                }
            }
            foreach (XmlNode child in groupDict.Values)
            {
                bool duplicate = false;
                XmlNode old = null;
                foreach (XmlNode xn in newParent.ChildNodes)
                {
                    if (xn.NodeType != XmlNodeType.Element)
                        continue;
                    if (xn.Name == "Property" && firstProperty == null)
                    {
                        firstProperty = xn;
                        continue;
                    }
                    if (xn.Name == "Group" && xn.Attributes[name].Value == child.Attributes[name].Value)
                    {
                        duplicate = true;
                        old = xn;
                        break;
                    }
                }
                if (duplicate)
                {
                    MergePropertyAndGroup(old, child.CloneNode(true), name);
                }
                else
                {
                    if(firstProperty == null)
                        newParent.AppendChild(child.CloneNode(true));
                    else
                        newParent.InsertBefore(child.CloneNode(true), firstProperty);
                }
            }
            foreach (XmlNode child in propertyDict.Values)
            {
                bool duplicate = false;
                XmlNode old = null;
                foreach (XmlNode xn in newParent.ChildNodes)
                {
                    if (xn.NodeType != XmlNodeType.Element || xn.Name != "Property")
                        continue;
                    if (xn.Attributes[name].Value == child.Attributes[name].Value)
                    {
                        duplicate = true;
                        old = xn;
                        break;
                    }
                }
                if (duplicate)
                {
                    newParent.ReplaceChild(child.CloneNode(true), old);
                }
                else
                {
                    newParent.AppendChild(child.CloneNode(true));
                }
            }
            groupDict.Clear();
            propertyDict.Clear();
        }