Esempio n. 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.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Apply Node variation specified in default template.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private bool ApplyNodeVariation(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.
            DefaultNodeVariation temp = new DefaultNodeVariation();

            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);
            }

            //			NodeVariation nodevariation = currentScenario.GetNodeVariation(nodeid);
            //			if (nodevariation == null)
            //			{
            //				RestoreDefaults(node, temp.attributestable);
            //				temp = null;
            //				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.
            NodeVariation nodevariation = (NodeVariation)currentScenario.nodevariationList[nodeid];

            // Create PlaceHolder.
            if (placeholdernode == null)
            {
                CreatePlaceHolder();
            }

            if (String.IsNullOrEmpty(nodevariation.VariationChildrenXml) == false)
            {
                placeholdernode.InnerXml = nodevariation.VariationChildrenXml;
            }
            else
            {
                placeholdernode.InnerXml = "";
            }

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

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

            while (placeholdernode.ChildNodes.Count > 0)
            {
                refchild = parentnode.InsertAfter(placeholdernode.ChildNodes[0], refchild);
            }

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

            CleanupPlaceHolder();

            return(true);
        }