Пример #1
0
        ///       <summary>
        ///       The method returns the value corresponding to the DCO expression specified, from the current DCO.
        ///       <param name="DCOTree">DCO Expression in the format [DCO].[page_type].[field_name]</param>
        ///       <returns>The value corresponding to the DCO expression specified, from the current DCO.</returns>
        ///       </summary>
        public override string getDCOValue(string DCOTree)
        {
            Stopwatch sw = Stopwatch.StartNew();

            string output     = "";
            int    objectType = CurrentDCO.ObjectType();

            if (objectType == Constants.Page)
            {
                output = getDCOValueForPage(DCOTree);
            }
            else if (objectType == Constants.Field)
            {
                output = getDCOValueForField(DCOTree);
            }
            //If the call is from ForEach, this will be having a currentIterationDCO object.
            else if (!Globals.Instance.GetData(Constants.forLoopString.CURRENTFILE).Equals(Constants.EMPTYSTRING) && objectType == Constants.Batch)
            {
                output = getDCOValueForFile(DCOTree);
            }
            else
            {
                throw new SmartExportException("The value for expression " + DCOTree + " could not be evaluated.");
            }

            ExportCore.WriteDebugLog(" getDCOValue(" + DCOTree + ") completed in " + sw.ElapsedMilliseconds + " ms.");
            sw.Stop();

            return(output);
        }
Пример #2
0
        ///       <summary>
        ///       The method extracts the data present in the table.
        ///       <param name="tableNode">XML node that contains the specification of table
        ///       from which the data is to be extracted.</param>
        ///       </summary>
        public void FetchTable(XmlNode tableNode)
        {
            Stopwatch sw = Stopwatch.StartNew();

            setContext();

            if (DCO.ObjectType() == Constants.Field)
            {
                initializeTableObjectForField(tableNode);
            }
            else if (DCO.ObjectType() == Constants.Page)
            {
                initializeTableObjectForPage(tableNode);
            }
            else if (DCO.ObjectType() == Constants.Document)
            {
                initializeTableObjectForDocument(tableNode);
            }
            else if (DCO.ObjectType() == Constants.Batch && !projectHasDoc)
            {
                initializeTableObjectForBatch(tableNode);
            }
            else
            {
                throw new SmartExportException("Unable to fetch table.");
            }

            // iterate over rows
            //print rows
            if (tableDCOs.Count > 0)
            {
                foreach (IDCO table in tableDCOs)
                {
                    setTableLimits(tableNode, table);
                    processTableRows(table, tableNode);
                }
            }
            else
            {
                ExportCore.WriteDebugLog("Table not found");
            }

            ExportCore.WriteDebugLog(" FetchTable(" + tableNode + ") completed in " + sw.ElapsedMilliseconds + " ms.");
            sw.Stop();
        }
Пример #3
0
        public void EvaluateLoopForFiles(XmlNode loopNode)
        {
            Stopwatch sw = Stopwatch.StartNew();

            try
            {
                int forEachlevel = getIntValueForEachObjectType(loopNode.Attributes["select"].Value);
                validateForLoop(forEachlevel, CurrentDCO);
                Dictionary <string, List <string> > filePageMap =
                    (Dictionary <string, List <string> >)Globals.Instance.GetData(Constants.FILE_PAGE_MAP);
                foreach (string file in filePageMap.Keys)
                {
                    //setting the current file , so that it can be used in DCODataRetreiver to get the data.
                    Globals.Instance.SetData(Constants.forLoopString.CURRENTFILE, file);
                    processNodes(loopNode, true);
                    if (!templateParser.CollateBatchOutput())
                    {
                        ExportCore.getExportUtil.writeToFile(null);
                    }
                    //setting it to empty after every iteration.
                    Globals.Instance.SetData(Constants.forLoopString.CURRENTFILE, 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"))
                {
                    message = "Problem found at line number : "
                              + templateParser.GetLineNumberForNode(loopNode) + "\n" + exp.Message;
                }
                //setting it to empty after every iteration.
                Globals.Instance.SetData(Constants.forLoopString.CURRENTFILE, Constants.EMPTYSTRING);
                throw new SmartExportException(message);
            }
            ExportCore.WriteDebugLog(" EvaluateLoopForFiles " + loopNode
                                     + "  completed in " + sw.ElapsedMilliseconds + " ms.");
            sw.Stop();
        }
Пример #4
0
        //This method is used to get the innertext if its child node text node or
        // smart parameter value its child node is under smart param node
        private String getNodevalue(XmlNode headerNode)
        {
            StringBuilder nodeValue = new StringBuilder(Constants.EMPTYSTRING);

            foreach (XmlNode node in headerNode.ChildNodes)
            {
                switch (node.Name)
                {
                case Constants.TEXT_NODE_NAME:
                    nodeValue.Append(node.Value.Trim());
                    break;

                case Constants.SE_SMART_PARAM_NODE_NAME:
                    nodeValue.Append(smartNav.MetaWord(Constants.SMARTP_AT + node.InnerText.Trim()));
                    ExportCore.WriteDebugLog("smart param value for '" + node.InnerText.Trim() + "' is " +
                                             smartNav.MetaWord(Constants.SMARTP_AT + node.InnerText.Trim()));
                    break;

                default:
                    throw new SmartExportException("Internal error. " + node.Name + " node is not supported inside " + headerNode.Name + " node ");
                }
            }
            return(nodeValue.ToString());
        }
Пример #5
0
        ///       <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();
        }
        ///       <summary>
        ///       The method returns the value corresponding to the DCO expression specified, from the current DCO.
        ///       <param name="DCOTree">DCO Expression in the format [DCO].[document_type].[page_type].[field_name]</param>
        ///       <returns>The value corresponding to the DCO expression specified, from the current DCO.</returns>
        ///       </summary>
        public virtual string getDCOValue(string DCOTree)
        {
            Stopwatch sw = Stopwatch.StartNew();

            string output = "";

            TDCOLib.IDCO currentIterationDCO = null;
            int          objectType          = CurrentDCO.ObjectType();

            //If the call is from ForEach, this will be having a currentIterationDCO object.
            if (!Globals.Instance.GetData(Constants.forLoopString.CURRENTITERATIONDCO).Equals(Constants.EMPTYSTRING))
            {
                currentIterationDCO = (TDCOLib.IDCO)Globals.Instance.GetData(Constants.forLoopString.CURRENTITERATIONDCO);
                objectType          = currentIterationDCO.ObjectType();
            }

            switch (objectType)
            {
            case Constants.Batch:
                string message = "Unable to find DCO reference at batch level due to ambiguity.";
                ExportCore.WriteLog(message);
                throw new SmartExportException(message);

            case Constants.Document:
                output = currentIterationDCO == null?getDCOValueForDocument(DCOTree) :
                             getDCOValueForDocument(currentIterationDCO, DCOTree);

                break;

            case Constants.Page:
                output = currentIterationDCO == null?getDCOValueForPage(DCOTree) :
                             getDCOValueForPage(DCOTree, currentIterationDCO.ID);

                break;

            case Constants.Field:
                output = currentIterationDCO == null?getDCOValueForField(DCOTree) :
                             getDCOValueForField(currentIterationDCO, DCOTree);

                break;
            }
            ExportCore.WriteDebugLog(" getDCOValue(" + DCOTree + ") completed in " + sw.ElapsedMilliseconds + " ms.");
            sw.Stop();

            return(output);
        }
Пример #7
0
        public void EvaluateCondition(XmlNode ConditionNode)
        {
            Stopwatch sw = Stopwatch.StartNew();

            bool ConditionEvaluated = false;

            try
            {
                //Evaluate the IF
                string CondText = ((XmlElement)ConditionNode).GetAttribute(Constants.SE_ATTRIBUTE_COND_TEST);
                ConditionEvaluation conditionEvaluation = new ConditionEvaluation(CondText);

                if (conditionEvaluation.CanEvaluate())
                {
                    processChildNodes(ConditionNode);
                    ConditionEvaluated = true;
                }

                // Evaluate the ELSIFs if IF has not satisfied
                if (!ConditionEvaluated)
                {
                    XmlNodeList elseIfNodeList = ConditionNode.ChildNodes;
                    foreach (XmlNode elseIfNode in elseIfNodeList)
                    {
                        if (elseIfNode.Name == Constants.NodeTypeString.SE_ELSIF)
                        {
                            CondText            = ((XmlElement)elseIfNode).GetAttribute(Constants.SE_ATTRIBUTE_COND_TEST);
                            conditionEvaluation = new ConditionEvaluation(CondText);
                            if (conditionEvaluation.CanEvaluate())
                            {
                                processChildNodes(elseIfNode);
                                ConditionEvaluated = true;
                                break;
                            }
                            // reaching else node indicates there are no more nodes with node name ELSIF
                            if (elseIfNode.Name == Constants.NodeTypeString.SE_ELSE)
                            {
                                break;
                            }
                        }
                    }
                }

                // Evaluate the Else
                if (!ConditionEvaluated)
                {
                    XmlNodeList elseNodeList = ConditionNode.ChildNodes;
                    foreach (XmlNode elseNode in elseNodeList)
                    {
                        if (elseNode.Name == Constants.NodeTypeString.SE_ELSE)
                        {
                            processChildNodes(elseNode);
                            ConditionEvaluated = true;
                            break;
                        }
                    }
                }
                if (!ConditionEvaluated)
                {
                    ExportCore.WriteLog("None of the conditions evaluated for the Node with test: " + CondText);
                }
            }
            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(ConditionNode) + "\n" + exp.Message;
                }
                throw new SmartExportException(message);
            }
            ExportCore.WriteDebugLog(" EvaluateCondition(" + ConditionNode + ") completed in " + sw.ElapsedMilliseconds + " ms.");

            sw.Stop();
        }
        public void EvaluateData(XmlNode DataNode)
        {
            Stopwatch sw = Stopwatch.StartNew();

            string NodeName = ((XmlElement)DataNode).Name;

            if (DataNode.HasChildNodes)
            {
                StringBuilder text = new StringBuilder(Constants.EMPTYSTRING);
                foreach (XmlNode node in DataNode.ChildNodes)
                {
                    switch (node.Name)
                    {
                    case Constants.TEXT_NODE_NAME:
                        text.Append(node.Value.Trim());
                        break;

                    case Constants.SE_TAB_NODE_NAME:
                        text.Append(Constants.TAB_SPACE);
                        break;

                    case Constants.SE_NEW_LINE_NODE_NAME:
                        text.Append(Constants.NEW_LINE);
                        break;

                    case Constants.SE_COMMA_NODE_NAME:
                        text.Append(Constants.COMMA);
                        break;

                    case Constants.SE_VALUE_NODE_NAME:
                        string value = "";
                        if (isTableColumn)
                        {
                            value = dCODataRetriever.getColumnValueForRow(node.Attributes["select"].Value);
                            text.Append(ExportCore.getExportUtil.escapeString(value, columnSeparator));
                        }
                        else
                        {
                            value = dCODataRetriever.getDCOValue(node.Attributes["select"].Value).Trim();
                            text.Append(ExportCore.getExportUtil.escapeString(value));
                        }
                        break;

                    case Constants.SE_SMART_PARAM_NODE_NAME:
                        text.Append(SmartNav.MetaWord(Constants.SMARTP_AT + node.InnerText.Trim()).Trim());
                        ExportCore.WriteDebugLog("smart param value for '" + node.InnerText.Trim() + "' is " + text);
                        break;

                    default:
                        ExportCore.WriteInfoLog("Node type [" + node.Name + "] is not supported inside data node. Will be ignored ");
                        break;
                    }
                }
                if (text.Length > 0)
                {
                    if (isHeader)
                    {
                        Globals.Instance.SetData(Constants.CSV_HEADERS, text.ToString());
                    }
                    else
                    {
                        ExportCore.getExportUtil.addToOutPutList(text.ToString());
                    }
                }
            }

            ExportCore.WriteDebugLog(" EvaluateData(" + DataNode + ") completed in " + sw.ElapsedMilliseconds + " ms.");

            sw.Stop();
        }