///       <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>
        ///       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 getDCOValueForPage(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
            {
                // Validate DCOTree expression against the current DCO
                // match page type and parent type of page
                if (dcoArray[2] == CurrentDCO.Type &&
                    (dcoArray[1] == CurrentDCO.Parent().Type || CurrentDCO.Parent().ObjectType() == Constants.Batch))
                {
                    output = CurrentDCO.FindChild(dcoArray[3]).Text;
                    ExportCore.WriteDebugLog(" Value of  expression   " + DCOTree + " is   " + output);
                }
                else
                {
                    ExportCore.WriteLog(" The expression   " + DCOTree + " is not valid for page  " + CurrentDCO.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.WriteLog(" Unable to find DCO reference for the page with ID: " + CurrentDCO.ID);
                ExportCore.WriteLog(" Error while reading DCO reference: " + exp.ToString());
            }

            return(output);
        }
Esempio n. 3
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);
        }
        ///       <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);
        }