///       <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>
        ///       Returns the document type.
        ///       <returns>The document type</returns>
        ///       </summary>
        public string getDocumentType()
        {
            Stopwatch sw = Stopwatch.StartNew();

            string docType = "";

            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();
                //anything getter related to currentIterationDCO object must be added here or after null check ,
                //if not there is a risk of null pointer exception.
                ExportCore.WriteDebugLog(" Current iterating DCO: " + currentIterationDCO.Type);
            }

            if (Constants.Document == objectType)
            {
                docType = currentIterationDCO == null ? CurrentDCO.Type : currentIterationDCO.Type;
            }
            else if (Constants.Page == objectType)
            {
                docType = currentIterationDCO == null?CurrentDCO.Parent().Type : currentIterationDCO.Parent().Type;
            }
            else if (Constants.Field == objectType)
            {
                docType = currentIterationDCO == null?CurrentDCO.Parent().Parent().Type : currentIterationDCO.Parent().Parent().Type;
            }
            else
            {
                string message = "  Document Type can be determined at document/ page / field level only. " + CurrentDCO.ID
                                 + " is of type " + CurrentDCO.Type + ".";
                if (currentIterationDCO != null)
                {
                    message = "  Document Type can be determined at document/ page / field level only. " + currentIterationDCO.ID
                              + " is of type " + currentIterationDCO.Type + ".";
                }

                ExportCore.WriteErrorLog(message);
                throw new SmartExportException(message);
            }
            ExportCore.WriteDebugLog(" getDocumentType() completed in " + sw.ElapsedMilliseconds + " ms.");
            sw.Stop();

            return(docType);
        }
        ///       <summary>
        ///       Returns the page type.
        ///       <returns>The page type.</returns>
        ///       </summary>
        public string getPageType()
        {
            Stopwatch sw = Stopwatch.StartNew();

            ExportCore.WriteDebugLog("Inside getPageType().");

            string pageType = "";

            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();
            }

            if (Constants.Page == objectType)
            {
                pageType = currentIterationDCO == null ? CurrentDCO.Type : currentIterationDCO.Type;
                ExportCore.WriteDebugLog("pageType is " + pageType);
            }
            else if (Constants.Field == objectType)
            {
                pageType = currentIterationDCO == null?CurrentDCO.Parent().Type : currentIterationDCO.Parent().Type;
            }
            else
            {
                string message = "  Page Type can be determined at   page / field level only. " + CurrentDCO.ID
                                 + " is of type " + CurrentDCO.Type + ".";
                if (currentIterationDCO != null)
                {
                    message = "  Page Type can be determined at   page / field level only. " + currentIterationDCO.ID
                              + " is of type " + currentIterationDCO.Type + ".";
                }
                ExportCore.WriteLog(message);
                throw new SmartExportException(message);
            }
            ExportCore.WriteDebugLog(" getPageType() completed in " + sw.ElapsedMilliseconds + " ms.");
            sw.Stop();

            return(pageType);
        }
Пример #4
0
        ///       <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].[page_type].[field_name]</param>
        ///       <returns>The value corresponding to the DCO field specified, from the current DCO.</returns>
        ///       </summary>
        public override string getDCOValueForField(string DCOTree)
        {
            // DCO reference in the template file should adhere to a 3 part string [DCO].[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;

            string output = "";

            try
            {
                // this is to pick up the field from the right page type
                if (dcoArray[2] == CurrentDCO.ID && dcoArray[1] == 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);
        }