///       <summary>
        ///       The method returns the value corresponding to the field specified from the current DCO.
        ///       <param name="currentIterationDCO">It is the DCO which is currently iterated in for loop.</param>
        ///       <returns>The value corresponding to the DCO expression specified from the current DCO.</returns>
        ///       </summary>
        public string getDCOValueForField(TDCOLib.IDCO currentIterationDCO, string DCOTree)
        {
            // DCO reference in the template file should adhere to a 4 part string [DCO.<doc_type>.<page_type>.<field_name>]
            // Parse the DCO reference and extract the page_type and field_name which can then be used to look up in the
            // current document that is being processed
            DCOTree = DCOTree.Replace("[", "").Replace("]", "");
            char[]   sep      = { '.' };
            string[] dcoArray = DCOTree.Split(sep, 4, StringSplitOptions.None);

            string output = "";

            try
            {
                TDCOLib.DCO page = DCO.FindChild(currentIterationDCO.Parent().ID);
                if (dcoArray.Length == 2 && DCOTree == "field.name")
                {
                    output = currentIterationDCO.ID;
                }
                else if (dcoArray[3] == currentIterationDCO.ID)
                {
                    output = page.FindChild(currentIterationDCO.ID).Text;
                }
                else
                {
                    ExportCore.WriteLog(" Looking for field  " + DCOTree + ", where as the current field is" + currentIterationDCO.ID);
                }
            }
            catch (Exception exp)
            {
                ExportCore.WriteErrorLog(" Unable to find field reference for the page with ID: " + currentIterationDCO.Parent().ID);
                ExportCore.WriteErrorLog(" Error while reading field reference: " + exp.ToString());
            }

            return(output);
        }
        ///       <summary>
        ///       Fetches the column value for a row of a table.
        ///       <param name="columnName">Column name</param>
        ///       <param name="pageID">Page ID from where the value needs to be extracted</param>
        ///       <returns>The value of the column for the current row of a table.</returns>
        public string getColumnValueForRow(string columnName)
        {
            ExportCore.WriteLog("inside getColumnValueForRow " + columnName);

            string columnValue = "";

            TDCOLib.IDCO row = null;
            Stopwatch    sw  = Stopwatch.StartNew();

            // the current iternation DCO would point to a row of a table
            if (!Globals.Instance.GetData(Constants.forLoopString.CURRENTITERATIONDCO).Equals(Constants.EMPTYSTRING))
            {
                row = (TDCOLib.IDCO)Globals.Instance.GetData(Constants.forLoopString.CURRENTITERATIONDCO);
                for (int k = 0; k < row.NumOfChildren(); k++)
                {
                    TDCOLib.DCO column = row.GetChild(k);
                    if (column.ObjectType() == Constants.Field && columnName == column.ID)
                    {
                        ExportCore.WriteLog(columnName + " = " + column.Text);
                        columnValue = column.Text;
                        break;
                    }
                }
            }
            else
            {
                string message = "  Error occured while fetching value for column " + columnName;
                ExportCore.WriteLog(message);
                throw new SmartExportException(message);
            }
            ExportCore.WriteDebugLog(" getColumnValueForRow(" + columnName + ") completed in " + sw.ElapsedMilliseconds + " ms.");
            sw.Stop();
            return(columnValue);
        }
        ///       <summary>
        ///       The method returns the page ID of the specified page type in the specified document.
        ///       <param name="DCOTree">DCO Expression in the format [DCO].[document_type].[page_type].[field_name]</param>
        ///       <param name="DocumentID">Docuemnt ID</param>
        ///       <param name="pageType">Page tyep</param>
        ///       <returns>The page ID of the specified page typs in the specified document.</returns>
        ///       </summary>
        public List <string> getPageIDsOfTypeInDocument(string DCOTree, string documentID, string pageType)
        {
            TDCOLib.IDCO currentIterationDCO = null;
            if (!Globals.Instance.GetData(Constants.forLoopString.CURRENTITERATIONDCO).Equals(Constants.EMPTYSTRING))
            {
                currentIterationDCO = (TDCOLib.IDCO)Globals.Instance.GetData(Constants.forLoopString.CURRENTITERATIONDCO);
            }

            List <string> pageIDs      = new List <string>();
            int           noOfChildren = currentIterationDCO == null?CurrentDCO.NumOfChildren() : currentIterationDCO.NumOfChildren();

            for (int i = 0; i < noOfChildren; i++)
            {
                TDCOLib.DCO child = currentIterationDCO == null?CurrentDCO.GetChild(i) : child = currentIterationDCO.GetChild(i);;
                //If the call is from ForEach, this will be having a currentIterationDCO object.

                if (child.Type == pageType)
                {
                    pageIDs.Add(child.ID);
                }
                if (1 < pageIDs.Count)
                {
                    string message = " There is more than one page of type " + pageType + " in the document " + documentID;
                    ExportCore.WriteLog(message);
                }
            }

            if (0 == pageIDs.Count)
            {
                string message = " There is no page of type " + pageType + " in the document " + documentID;
                ExportCore.WriteLog(message);
            }

            return(pageIDs);
        }
        private void processTableRows(IDCO table, XmlNode tableNode)
        {
            // iterate over rows
            // print rows
            int i = rowStart;

            do
            {
                TDCOLib.DCO row = table.GetChild(i);
                if (row.ObjectType() == Constants.Field)
                {
                    i++;
                    Globals.Instance.SetData(Constants.forLoopString.CURRENTITERATIONDCO, row);
                    XmlNode dataNode = tableNode.ChildNodes.Item(0);
                    {
                        if (dataNode.Name == Constants.NodeTypeString.SE_DATA)
                        {
                            dataElement.setIsTableColumn(true);
                            dataElement.EvaluateData(dataNode);
                        }
                    }
                }
                Globals.Instance.SetData(Constants.forLoopString.CURRENTITERATIONDCO, Constants.EMPTYSTRING);
            } while (i < rowEnd);
        }
        ///       <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>
        ///       <param name="documentID">ID of the document from where the value needs to be extracted</param>
        ///       <returns>The value corresponding to the DCO expression specified from the current DCO.</returns>
        ///       </summary>
        public string getDCOValueForDocument(TDCOLib.IDCO currentIterationDCO, string DCOTree)
        {
            // DCO reference in the template file should adhere to a 4 part string [DCO.<doc_type>.<page_type>.<field_name>]
            // Parse the DCO reference and extract the page_type and field_name which can then be used to look up in the
            // current document that is being processed
            DCOTree = DCOTree.Replace("[", "").Replace("]", "");
            char[]   sep      = { '.' };
            string[] dcoArray = DCOTree.Split(sep, 4, StringSplitOptions.None);

            // get the value of the DCO reference using the page ID and the field name
            string output = "";

            try
            {
                TDCOLib.DCO document = DCO.FindChild(currentIterationDCO.ID);
                if (dcoArray.Length == 2 && DCOTree == "document.name")
                {
                    output = currentIterationDCO.ID + " - " + currentIterationDCO.Type;
                }
                else if (dcoArray[1] == document.Type)
                {
                    List <string> pageIDs = getPageIDsOfTypeInDocument(DCOTree, currentIterationDCO.ID, dcoArray[2]);
                    foreach (string pageID in pageIDs)
                    {
                        output = currentIterationDCO.FindChild(pageID).FindChild(dcoArray[3]).Text;
                        if (!string.IsNullOrEmpty(output))
                        {
                            break;
                        }
                    }
                }
                else
                {
                    ExportCore.WriteLog(" The expression   " + DCOTree + " is not valid for document  " + currentIterationDCO.ID);
                }
            }
            catch (Exception exp)
            {
                // There could be reference in the template for the documents that are not processed in the current batch
                // Template in TravelDocs can have reference to a field under Flight but the current batch doesn't have
                // any flight related input. Alternatively, Flight and Car Rental gets processed but for the Car Rental
                // data output, there cannot be any Flight reference
                ExportCore.WriteErrorLog(" Unable to find DCO reference for the document with ID: " + currentIterationDCO.ID);
                ExportCore.WriteErrorLog(" Error while reading DCO reference: " + exp.ToString());
            }

            return(output);
        }
        ///       <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>
        ///       <param name="pageID">Page ID from where the value needs to be extracted</param>
        ///       <returns>The value corresponding to the DCO expression specified from the current DCO.</returns>
        ///       </summary>
        public string getDCOValueForPage(string DCOTree, string pageID)
        {
            // DCO reference in the template file should adhere to a 4 part string [DCO.<doc_type>.<page_type>.<field_name>]
            // Parse the DCO reference and extract the page_type and field_name which can then be used to look up in the
            // current document that is being processed
            DCOTree = DCOTree.Replace("[", "").Replace("]", "");
            char[]   sep      = { '.' };
            string[] dcoArray = DCOTree.Split(sep, 4, StringSplitOptions.None);

            string output = "";

            try
            {
                TDCOLib.DCO page = DCO.FindChild(pageID);
                if (dcoArray.Length == 2 && DCOTree == "page.name")
                {
                    output = page.ID + " - " + page.Type;
                }
                // Validate DCOTree expression against the current DCO
                // match page type and parent type of page
                else if ((dcoArray[1] == page.Parent().Type || page.Parent().ObjectType() == Constants.Batch) &&
                         dcoArray[2] == page.Type)
                {
                    output = page.FindChild(dcoArray[3]).Text;
                }
                else
                {
                    ExportCore.WriteLog(" The expression   " + DCOTree + " is not valid for page  " + pageID);
                }
            }
            catch (Exception exp)
            {
                // There could be reference in the template for the documents that are not processed in the current batch
                // Template in TravelDocs can have reference to a field under Flight but the current batch doesn't have
                // any flight related input. Alternatively, Flight and Car Rental gets processed but for the Car Rental
                // data output, there cannot be any Flight reference
                ExportCore.WriteErrorLog(" Unable to find DCO reference for the page with ID: " + pageID);
                ExportCore.WriteErrorLog(" Error while reading DCO reference: " + exp.ToString());
            }

            return(output);
        }
        ///       <summary>
        ///       The method returns the value corresponding to the DCO field specified, from the current DCO for the field.
        ///       <param name="DCOTree">DCO Expression in the format [DCO].[document_type].[page_type].[field_name]</param>
        ///       <returns>The value corresponding to the DCO field specified, from the current DCO.</returns>
        ///       </summary>
        public virtual string getDCOValueForField(string DCOTree)
        {
            // DCO reference in the template file should adhere to a 4 part string [DCO].[document_type].[page_type].[field_name]
            // Parse the DCO reference and extract the page_type and field_name which can then be used to look up in the
            // current document that is being processed
            DCOTree = DCOTree.Replace("[", "").Replace("]", "");
            char[]      sep      = { '.' };
            string[]    dcoArray = DCOTree.Split(sep, 4, StringSplitOptions.None);
            TDCOLib.DCO page     = CurrentDCO.Parent();
            string      pageID   = page.ID;

            TDCOLib.DCO document   = page.Parent();
            string      documentID = document.ID;
            string      output     = "";

            try
            {
                // this is to pick up the field from the right page type
                if ((dcoArray[3] == CurrentDCO.ID &&
                     (dcoArray[1] == document.Type || page.Parent().ObjectType() == Constants.Batch) &&
                     dcoArray[2] == page.Type))
                {
                    output = CurrentDCO.Text;
                }
                else
                {
                    ExportCore.WriteLog(" Current field " + CurrentDCO.ID +
                                        " is  different from required field which is" + DCOTree);
                }
            }
            catch (Exception exp)
            {
                // There could be reference in the template for the documents that are not processed in the current batch
                // Template in TravelDocs can have reference to a field under Flight but the current batch doesn't have
                // any flight related input. Alternatively, Flight and Car Rental gets processed but for the Car Rental
                // data output, there cannot be any Flight reference
                ExportCore.WriteErrorLog(" Unable to find DCO reference for the field : " + DCOTree);
                ExportCore.WriteErrorLog(" Error while reading DCO reference: " + exp.ToString());
            }

            return(output);
        }
        ///       <summary>
        ///       Checks if the DCO object is a table.
        ///       <param name="table">DCO object</param>
        ///       <returns>True if the DCO object is a table</returns>
        ///       </summary>
        public bool isObjectTable(TDCOLib.IDCO table)
        {
            bool isTable = false;

            for (int j = 0; j < table.NumOfChildren(); j++)
            {
                TDCOLib.DCO row = table.GetChild(j);
                if (row.ObjectType() == Constants.Field)
                {
                    for (int k = 0; k < row.NumOfChildren(); k++)
                    {
                        TDCOLib.DCO column = row.GetChild(k);

                        if (column.ObjectType() == Constants.Field)
                        {
                            isTable = true;
                            break;
                        }
                    }
                }
            }
            return(isTable);
        }
Exemple #9
0
        ///       <summary>
        ///       The method value of the DCO expression from the current file.
        ///       <param  name="DCOTree" >DCO expression that refers to a field in the file.</param>
        ///       </summary>
        public string getDCOValueForFile(string DCOTree)
        {
            string filename = (string)Globals.Instance.GetData(Constants.forLoopString.CURRENTFILE);
            Dictionary <string, List <string> > filePageMap = (Dictionary <string, List <string> >)Globals.Instance.GetData(Constants.FILE_PAGE_MAP);
            List <string> pages  = (List <string>)filePageMap[filename];
            string        output = "";

            DCOTree = DCOTree.Replace("[", "").Replace("]", "");
            char[]   sep      = { '.' };
            string[] dcoArray = DCOTree.Split(sep);

            if (CurrentDCO.ObjectType() != Constants.Batch)
            {
                throw new SmartExportException("getDCOValueForFile(" + DCOTree + ") can be used at batch level only. ");
            }

            foreach (string pageID in pages)
            {
                TDCOLib.DCO page = CurrentDCO.FindChild(pageID);
                // Validate DCOTree expression against the current DCO
                // match page type and parent type of page
                if (page.Parent().ObjectType() == Constants.Batch &&
                    dcoArray[1] == page.Type)
                {
                    output += page.FindChild(dcoArray[2]).Text;
                    if (!string.IsNullOrEmpty(output))
                    {
                        break;
                    }
                }
                else
                {
                    ExportCore.WriteLog(" The expression   " + DCOTree + " is not valid for page  " + pageID);
                }
            }
            return(output);
        }