/// <summary> /// The method Evaluates for loop. /// <param name="loopNode">XML node of Foreach</param> /// <param name="DCO">Current iteration DCO of the parent for-each loop</param> /// </summary> public void EvaluateLoop(XmlNode loopNode, TDCOLib.IDCO DCO) { Stopwatch sw = Stopwatch.StartNew(); DataElement dataElement = new DataElement(); Conditions conditionEvaluator = new Conditions(); Tables table = new Tables(); try { int forEachlevel = getIntValueForEachObjectType(loopNode.Attributes["select"].Value); nestingLevel = setAndValidateNestingLevel(loopNode); validateForLoop(forEachlevel, DCO); for (int i = 0; i < DCO.NumOfChildren(); i++) { //setting the currentIterationDCO , so that it can be used in DCODataRetreiver to get the data. Globals.Instance.SetData(Constants.forLoopString.CURRENTITERATIONDCO, DCO.GetChild(i)); foreach (XmlNode node in loopNode.ChildNodes) { switch (node.Name) { case Constants.NodeTypeString.SE_IF: conditionEvaluator.EvaluateCondition(node); break; case Constants.NodeTypeString.SE_FOREACH: Loops loopEvaluator = new Loops(); loopEvaluator.EvaluateLoop(node, DCO.GetChild(i)); break; case Constants.NodeTypeString.SE_ROWS: if (node.Attributes == null || node.Attributes.Count > 0 || string.IsNullOrEmpty(node.Attributes["tablename"].Value)) { new SmartExportException("Its mandatory to specify the table name when the for-each-rows tag " + "is used within se:for-each tag for tables."); } if (node.Attributes["tablename"].Value == DCO.GetChild(i).ID) { table.FetchTable(node); } break; case Constants.NodeTypeString.SE_DATA: dataElement.EvaluateData(node); break; default: if (node.NodeType == XmlNodeType.Element) { ExportCore.WriteLog("Node type [" + ((XmlElement)node).Name + "] not supported. Will be ignored"); } break; } } //setting it to empty after every iteration. Globals.Instance.SetData(Constants.forLoopString.CURRENTITERATIONDCO, Constants.EMPTYSTRING); } } catch (System.Exception exp) { string message = exp.Message; //if the problem was already caught at the child node level the line number // information would be already present in the exception message if (!message.Contains("Problem found at line number")) { TemplateParser templateParser = (TemplateParser)Globals.Instance.GetData(Constants.GE_TEMPLATE_PARSER); message = "Problem found at line number : " + templateParser.GetLineNumberForNode(loopNode) + "\n" + exp.Message; } //setting it to empty after every iteration. Globals.Instance.SetData(Constants.forLoopString.CURRENTITERATIONDCO, Constants.EMPTYSTRING); throw new SmartExportException(message); } ExportCore.WriteDebugLog(" EvaluateLoop " + loopNode + " completed in " + sw.ElapsedMilliseconds + " ms."); sw.Stop(); }