Пример #1
0
        /// <summary>
        /// Set Propert under Properties node into DefaultGroup
        /// </summary>
        public void AdjustDefaultGroup(PtfProperty RootNode)
        {
            PtfProperty defaultGroup = new PtfProperty()
            {
                Name        = StringResource.DefaultGroupName,
                Description = "",
                ValueType   = PtfPropertyType.Group
            };

            for (int i = 0; i < RootNode.Count; i++)
            {
                if (RootNode[i].ValueType != PtfPropertyType.Group)
                {
                    defaultGroup.Add(RootNode[i]);
                    RootNode.RemoveAt(i);
                    i--;
                }
            }
            //Set DefaultGroup node to be the first one
            RootNode.Insert(0, defaultGroup);
        }
Пример #2
0
        /// <summary>
        /// recurrsively create Config Node tree from ptfconfig file
        /// </summary>
        /// <param name="baseConfigNode"></param>
        /// <param name="root"></param>
        private void MergePropertyAndGroup(PtfProperty baseConfigNode, XmlNode root)
        {
            Dictionary <string, XmlNode> propertyDict = new Dictionary <string, XmlNode>();
            Dictionary <string, XmlNode> groupDict    = new Dictionary <string, XmlNode>();
            string value = "";
            //to sort Group node before Property node
            //record the pos of first Property node. If no Propert, default value is -1
            int propertyPos = -1;

            foreach (XmlNode child in root.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element)
                {
                    value = child.Attributes["name"].Value;

                    if (child.Name == "Property")
                    {
                        if (propertyDict.ContainsKey(value))
                        {
                            throw new InvalidOperationException(
                                      string.Format(StringResource.DuplicatePTFConfigNode, child.Name, value));
                        }

                        propertyDict.Add(value, child);
                    }
                    else
                    {
                        if (groupDict.ContainsKey(value))
                        {
                            throw new InvalidOperationException(
                                      string.Format(StringResource.DuplicatePTFConfigNode, child.Name, value));
                        }
                        groupDict.Add(value, child);
                    }
                }
            }

            //Merge Group First
            foreach (XmlNode child in groupDict.Values)
            {
                bool        duplicate = false;
                PtfProperty config    = null;
                for (int i = 0; i < baseConfigNode.Count; i++)
                {
                    if (baseConfigNode[i].ValueType != PtfPropertyType.Group && propertyPos == -1)
                    {
                        propertyPos = i;
                    }
                    if (baseConfigNode[i].ValueType == PtfPropertyType.Group && baseConfigNode[i].Name == child.Attributes["name"].Value)
                    {
                        duplicate = true;
                        config    = baseConfigNode[i];
                        break;
                    }
                }
                if (duplicate)
                {
                    //duplicate, first merge Group Node's Attribute
                    //Recurrsively Merge Property and Group to create data structure
                    if (child.Attributes["description"] != null)
                    {
                        config.Description = child.Attributes["description"].Value;
                        config.RefXmlNode  = child;
                    }
                    MergePropertyAndGroup(config, child);
                }
                else
                {
                    //create new Group Node
                    //Insert Group before Property
                    //Recurrsively Merge Property and Group to create data structure
                    PtfProperty newGroup = new PtfProperty(child, true);
                    if (propertyPos >= 0)
                    {
                        baseConfigNode.Insert(propertyPos, newGroup);
                        propertyPos++;
                    }
                    else
                    {
                        baseConfigNode.Add(newGroup);
                    }
                    MergePropertyAndGroup(newGroup, child);
                }
            }
            //Merge Property
            foreach (XmlNode child in propertyDict.Values)
            {
                bool        duplicate = false;
                PtfProperty config    = null;
                foreach (PtfProperty childConfig in baseConfigNode)
                {
                    if (childConfig.ValueType != PtfPropertyType.Group && childConfig.Name == child.Attributes["name"].Value)
                    {
                        duplicate = true;
                        config    = childConfig;
                        break;
                    }
                }
                //First remove old node
                if (duplicate)
                {
                    baseConfigNode.Remove(config);
                }
                //Insert new node
                PtfProperty newProperty = new PtfProperty(child, false);
                baseConfigNode.Add(newProperty);
            }
            groupDict.Clear();
            propertyDict.Clear();
        }