/// <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."); } }
/// <summary> /// Similar to NodeVariation only Xml Text content is changed. /// </summary> /// <param name="node"></param> /// <returns></returns> private bool ApplyTextVariation(XmlNode node) { if (currentScenario == null) { // There nothing to do. return(false); } if (node.HasChildNodes == false) { // Todo: Attribute variation has to have one child node Throw exception return(false); } if (node.ChildNodes.Count > 1) { // Todo: Only one allowed. Throw exception return(false); } DefaultTextVariation temp = new DefaultTextVariation(); temp.Initialize(node); string nodeid = temp.ID; if (variationids.Count != 0) { if (variationids.Contains(nodeid) == false) { RestoreDefaults(node, temp.attributestable); return(false); } } else if (variationids.Contains(nodeid) == false) { RestoreDefaults(node, temp.attributestable); return(false); } if (currentScenario.textVariationList.Contains(nodeid) == false) { RestoreDefaults(node, temp.attributestable); return(false); } XmlNode nodetomodify = node.ChildNodes[0]; if (nodetomodify == null) { // Nothing to change. RestoreDefaults(node, temp.attributestable); return(false); } TextVariation textvariation = (TextVariation)currentScenario.textVariationList[nodeid]; nodetomodify.InnerText = textvariation.Text; NodeVariationApplied(node.ParentNode, nodetomodify, textvariation.attributestable); // Get Parent of current node. XmlNode parentnode = node.ParentNode; parentnode.InsertAfter(nodetomodify, node); parentnode.RemoveChild(node); variationids.Remove(nodeid); CleanupPlaceHolder(); return(true); }