///       <summary>
        ///       The method returns true if the project contains a document and false otherwise.
        ///       </summary>
        private bool doesProjectHaveDocument()
        {
            List <bool> docStatus     = new List <bool>();
            bool        projectHasDoc = false;

            // if there is a document type in the DCO hierarchy
            if (CurrentDCO.ObjectType() == Constants.Document ||
                (CurrentDCO.ObjectType() == Constants.Page && CurrentDCO.Parent().ObjectType() == Constants.Document) ||
                (CurrentDCO.ObjectType() == Constants.Field && CurrentDCO.Parent().ObjectType() == Constants.Page &&
                 CurrentDCO.Parent().Parent().ObjectType() == Constants.Document)
                )
            {
                projectHasDoc = true;
            }
            //check if the children of batch are not  document
            else if (CurrentDCO.ObjectType() == Constants.Batch)
            {
                for (int i = 0; i < CurrentDCO.NumOfChildren(); i++)
                {
                    TDCOLib.IDCO childDCO = CurrentDCO.GetChild(i);
                    if (childDCO.ObjectType() != Constants.Document)
                    {
                        docStatus.Add(false);
                    }
                    else
                    {
                        docStatus.Add(true);
                    }
                }
                projectHasDoc = docStatus.Contains(true);
            }
            return(projectHasDoc);
        }
Exemple #2
0
 ///       <summary>
 ///       The method validates for loop expression.
 ///       <param name="forEachlevel">integer value of the level</param>
 ///       </summary>
 protected void validateForLoop(int forEachlevel, TDCOLib.IDCO DCO)
 {
     if (DCO == null)
     {
         throw new SmartExportException(" DCO associated with the for-each loop cannot be determined.");
     }
     if (forEachlevel == 4 || forEachlevel == Constants.Batch)
     {
         throw new SmartExportException(" Assigned level of ForEach loop is wrong");
     }
     if (forEachlevel == DCO.ObjectType())
     {
         throw new SmartExportException(" ForEach loop level must not be same to the Datacap assigned level");
     }
     if (!(forEachlevel == (DCO.ObjectType() + 1)))
     {
         throw new SmartExportException(" ForEach loop must be one level lower from the Datacap assigned level ");
     }
 }
Exemple #3
0
        ///       <summary>
        ///       The method Evaluates for loop.
        ///       <param name="loopNode">XML node of Foreach</param>
        ///       </summary>
        public void EvaluateLoop(XmlNode loopNode)
        {
            int forEachlevel = getIntValueForEachObjectType(loopNode.Attributes["select"].Value);

            if (forEachlevel == Constants.Document && CurrentDCO.ObjectType() == Constants.Batch)
            {
                EvaluateLoopForFiles(loopNode);
            }
            else if (forEachlevel == Constants.Field && CurrentDCO.ObjectType() == Constants.Page &&
                     loopNode.Attributes["select"].Value.ToUpper() == Constants.forLoopString.TABLE)
            {
                base.EvaluateLoop(loopNode);
            }
            else
            {
                TemplateParser templateParser = (TemplateParser)Globals.Instance.GetData(Constants.GE_TEMPLATE_PARSER);
                string         message        = "Problem found at line number : " + templateParser.GetLineNumberForNode(loopNode) + "\n" + "Invalid usage of loops.";
                throw new SmartExportException(message);
            }
        }
        public void processNodes()
        {
            DCODataRetrieverWithoutDoc dCODataRetriever = new DCODataRetrieverWithoutDoc();

            if (CurrentDCO.ObjectType() == Constants.Batch)
            {
                dCODataRetriever.createFilePageMap();
            }
            // Loop through the template and accumulate the output
            while (templateParser.HasNextNode())
            {
                XmlNode currentNode = templateParser.GetNextNode();
                switch (templateParser.GetNodeType(currentNode))
                {
                case NodeType.Header:
                    dataElement.setIsHeader(true);
                    dataElement.EvaluateData(currentNode);
                    dataElement.setIsHeader(false);
                    break;

                case NodeType.Data:
                    dataElement.EvaluateData(currentNode);
                    break;

                case NodeType.If:
                    conditionEvaluator.EvaluateCondition(currentNode);
                    break;

                case NodeType.ForEach:
                    loopEvaluator.EvaluateLoop(currentNode);
                    break;

                case NodeType.ForEachRows:
                    table.FetchTable(currentNode);
                    break;

                default:
                    if (currentNode.NodeType == XmlNodeType.Element)
                    {
                        ExportCore.WriteLog("Node type [" + ((XmlElement)currentNode).Name + "] not supported. Will be ignored");
                    }
                    break;
                }
            }
        }
        public bool FormattedDataOutput(string TemplateFilePath)
        {
            bool returnValue = true;

            try
            {
                Stopwatch sw = Stopwatch.StartNew();
                smartNav = new dcSmart.SmartNav(this);

                //set thread locals
                SetGlobals();
                //TODO: Validate template
                //Initialize the parser
                TemplateParser templateParser = new TemplateParser(TemplateFilePath);
                templateParser.Parse();

                exportUtil.setContext(templateParser);

                if (templateParser.AppendToFile() && !singleOutputFileNameMap.ContainsKey(templateParser.GetOutputFileName()))
                {
                    singleOutputFileNameMap.Add(templateParser.GetOutputFileName(), templateParser.GetOutputFileName() + "_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fffffff"));
                }
                string locale = templateParser.GetLocale();
                Globals.Instance.SetData(Constants.LOCALE, locale);
                bool projectHasDocument = doesProjectHaveDocument();
                Globals.Instance.SetData(Constants.PROJECT_HAS_DOC, projectHasDocument);
                if (projectHasDocument)
                {
                    ContentProcessorWithDoc ContentProcessor = new ContentProcessorWithDoc(templateParser);
                    DCOPatterns.AddRange(ContentProcessor.createDCOPatternList(getDCODefinitionFile()));
                    ValidateExpressions(TemplateFilePath, Constants.DCO_REF_PATTERN);
                    ContentProcessor.processNodes();
                }
                else
                {
                    ContentProcessorWithoutDoc ContentProcessor = new ContentProcessorWithoutDoc(templateParser);
                    DCOPatterns.AddRange(ContentProcessor.createDCOPatternList(getDCODefinitionFile()));
                    ValidateExpressions(TemplateFilePath, Constants.DCO_REF_PATTERN_NO_DOC);
                    ContentProcessor.processNodes();
                }
                //if project has document
                //or when project doesn't have document and action is attached at page/field level
                //or when collate batch output flag is true when action is attached at batch level and project doesn't have
                //document
                if (projectHasDocument ||
                    (CurrentDCO.ObjectType() != Constants.Batch && !projectHasDocument) ||
                    (CurrentDCO.ObjectType() == Constants.Batch && !projectHasDocument &&
                     templateParser.CollateBatchOutput()))
                {
                    exportUtil.writeToFile(singleOutputFileNameMap);
                }

                WriteInfoLog(" Smart export WriteLog completed in " + sw.ElapsedMilliseconds + " ms.");

                sw.Stop();
            }
            catch (System.Exception exp)
            {
                returnValue = false;
                WriteErrorLog("Error while processing the template file: " + exp.Message);
                WriteErrorLog(exp.StackTrace);
            }

            // TODO: Catch the important exceptions here...
            return(returnValue);
        }