コード例 #1
0
        /// <summary>
        /// Reads all variations specified in current scenario.
        /// Setup to read only when required when the default tree is being parsed for example.
        /// </summary>
        internal virtual void ReadVariations()
        {
            if (currentscenarionode == null)
            {
                UtilsLogger.LogDiagnostic = "Current scenario is null, there is no variations to read.";
                return;
            }

            if (currentscenarionode.HasChildNodes == false)
            {
                UtilsLogger.LogDiagnostic = "Current scenario does not contain any Variations";
                return;
            }

            // In Scenario elements nested Variation elements are not allowed.
            // Thus the loop here only looks for child elements of the Scenario node.
            // If there are nested Variation elements an Exception will be thrown when the
            // variation is initialized.
            // If a non-variation element is found that element is stored in a list for processing
            // by later processing.
            for (int i = 0; i < currentscenarionode.ChildNodes.Count; i++)
            {
                if (currentscenarionode.ChildNodes[i] == null)
                {
                    continue;
                }

                switch (currentscenarionode.ChildNodes[i].Name)
                {
                case Constants.NodeVariationElement:
                    NodeVariation newnodevariation = new NodeVariation();
                    newnodevariation.Initialize(currentscenarionode.ChildNodes[i]);
                    nodevariationList.Add(newnodevariation.ID, newnodevariation);

//						if (nodevariationList.ContainsKey(newnodevariation.ID))
//						{
//							nodevariationList.Add(Convert.ToInt32(GenerateRandomNumber()) + "_" + newnodevariation.ID, newnodevariation);
//						}
//						else
//						{
//							nodevariationList.Add(newnodevariation.ID, newnodevariation);
//						}
                    break;

                case Constants.AttributeVariationElement:
                    AttributeVariation newattribvariation = new AttributeVariation();
                    newattribvariation.Initialize(currentscenarionode.ChildNodes[i]);
                    attributeVariationList.Add(newattribvariation);
                    break;

                case Constants.TextVariationElement:
                    TextVariation newtextvariation = new TextVariation();
                    newtextvariation.Initialize(currentscenarionode.ChildNodes[i]);
                    textVariationList.Add(newtextvariation.ID, newtextvariation);
                    break;

                case Constants.RootNodeVariationElement:
                    if (rootnodevariation != null)
                    {
                        throw new ApplicationException("No more than one RootNodeVariation can be specified in the document.");
                    }

                    rootnodevariation = new RootNodeVariation();
                    rootnodevariation.Initialize(currentscenarionode.ChildNodes[i]);
                    break;

                default:
                    if (unrecognizednodeslist == null)
                    {
                        unrecognizednodeslist = new List <XmlNode>();
                    }

                    unrecognizednodeslist.Add(currentscenarionode.ChildNodes[i]);
                    break;
                }
            }

            if (nodevariationList.Count == 0 && attributeVariationList.Count == 0 && textVariationList.Count == 0)
            {
                // Todo: Removed this exception to allow changing only filename for a variation.
                //throw new NotSupportedException("Current scenario does not contain any supported variations.");
            }
        }
コード例 #2
0
ファイル: VariationGenerator.cs プロジェクト: dotnet/wpf-test
        /// <summary>
        /// Apply Node variation specified in default template.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private bool ApplyRootNodeVariation(XmlNode node)
        {
            // Get variation ID from element.
            // Check if variation is all or selected numbers. If all apply all variations.
            // If selected only do selected variations.

            if (currentScenario == null)
            {
                // There nothing to do.
                return(false);
            }

            // Using Default Node variation instead of Node variation as it supports having
            // nested NodeVariation or AttributeVariation/TextVariation combinations.
            RootNodeVariation temp = new RootNodeVariation();

            temp.Initialize(node);

            // Check if the Node is in the list of variation ids in the scenario.
            string nodeid = temp.ID;

            if (variationids.Count != 0)
            {
                if (variationids.Contains(nodeid) == false)
                {
                    RestoreDefaults(node, temp.attributestable);
                    return(true);
                }
            }
            else if (variationids.Contains(nodeid) == false)
            {
                RestoreDefaults(node, temp.attributestable);
                return(false);
            }

            // Check if the id is in the list of variations in the default variations list.
            // If not restore the default.
            //if (currentScenario.nodevariationList.Contains(nodeid) == false)
            //{
            //    RestoreDefaults(node, temp.attributestable);
            //    temp = null;
            //    return false;
            //}

            // First create a placeholder and update the placeholder xml.
            // Call NodeVariationApplied method to have derived classes extract information relevant to them.
            // Finally apply the xml to the default template.
            RootNodeVariation rootnodevariation = currentScenario.rootnodevariation;

            //rootnodevariation.ElementValue

            NodeVariationApplied(node.ParentNode, placeholdernode, rootnodevariation.attributestable);

            if (String.IsNullOrEmpty(rootnodevariation.ElementValue))
            {
                throw new ApplicationException("RootNodeVariation elementvalue cannot be null");
            }

            // Create a new Element here.
            // Copy all the existing root element attributes if none have to be changed.
            // Assign existing innerxml to the new element.
            XmlNode newnode = node.OwnerDocument.CreateElement(rootnodevariation.ElementValue, this.tokendocumentnamespace);

            node.ParentNode.AppendChild(newnode);

            XmlNode rootnode = node.ChildNodes[0];

            for (int i = 0; i < rootnode.Attributes.Count; i++)
            {
                newnode.Attributes.Append(rootnode.Attributes[i]);
            }

            for (int i = 0; i < rootnode.ChildNodes.Count; i++)
            {
                newnode.AppendChild(rootnode.ChildNodes[i]);
            }

            // Get Parent of current node.
            XmlNode parentnode = node.ParentNode;

            parentnode.RemoveChild(node);

            // Remove Variation element & variation id from list of variations to be applied.
            variationids.Remove(nodeid);

            return(true);
        }