public static bool WPArchivePDFsToColumbus(string folderInput, string folderOutput, string reportDir, string columbusFilePrefix, List <ColumbusIndex> documentsToMerge, List <ColumbusIndex> lstHodingIdx)
        {
            try
            {
                if (!WriteConfirmationFile(lstHodingIdx, reportDir))
                {
                    return(false);
                }

                Log.Info(string.Format("{0} welcome packs are ready to merge.", documentsToMerge.Count()));
                int fileNo = 1;
                while (documentsToMerge.Count != 0)
                {
                    var mergePdfName = Path.Combine(folderOutput, string.Format("{0}_{1}.pdf", columbusFilePrefix, fileNo));
                    if (!MergePdfs(folderInput, mergePdfName, ref documentsToMerge))
                    {
                        return(false);
                    }
                    fileNo++;
                }
                Log.Info(string.Format("{0} merged pdfs are ready to archive ", fileNo));

                //Run Columbus Task
                var lstXml = FileProcessHelper.GetFiles(folderOutput, "*.xml");
                var lstPdf = FileProcessHelper.GetFiles(folderOutput, "*.pdf");
                if (!RunColumbus(lstXml, lstPdf))
                {
                    return(false);
                }
                Log.Info("Archive to Columbus Sucessful");

                //Use Confimation report to Update Recon_TackingNumber table and send email back to SE
                //Delete archived Pdfs


                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Failed to merge files in {0} to {1}. ex: {3}", folderInput, folderOutput, ex.Message));
                return(false);
            }
        }
        public static bool ArchivePDFsToColumbus(string folderInput, string folderOutput, string columbusFilePrefix, List <ColumbusIndex> documentsToMerge)
        {
            try
            {
                //Merge Pdfs and create xml control files
                Log.Info(string.Format("{0} pdfs are ready to merge ", documentsToMerge.Count()));
                int fileNo = 1;
                while (documentsToMerge.Count != 0)
                {
                    var mergePdfName = Path.Combine(folderOutput, string.Format("{0}_{1}.pdf", columbusFilePrefix, fileNo));
                    if (!MergePdfs(folderInput, mergePdfName, ref documentsToMerge))
                    {
                        return(false);
                    }
                    fileNo++;
                }


                //Run Columbus Task
                Log.Info("Merged pdfs and control files are ready to archive");
                var lstXml = FileProcessHelper.GetFiles(folderOutput, "*.xml");
                var lstPdf = FileProcessHelper.GetFiles(folderOutput, "*.pdf");
                if (!RunColumbus(lstXml, lstPdf))
                {
                    return(false);
                }
                Log.Info("Archive to Columbus Successfully");


                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Failed to merge files in {0} to {1}. ex: {3}", folderInput, folderOutput, ex.Message));
                return(false);
            }
        }
        public static void CheckDirectoryEmpty(string path)
        {
            bool isSuccess = false;

            try
            {
                int counter1 = FileProcessHelper.GetFolders(path, null).Count();
                int counter2 = FileProcessHelper.GetFiles(path, "*").Count();
                if (counter1 == 0 && counter2 == 0)
                {
                    isSuccess = true;
                }
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Error in method - {0} Ex: {1}", MethodBase.GetCurrentMethod().Name, ex.Message));
                isSuccess = false;
            }

            if (!isSuccess)
            {
                throw new ProcessingException(string.Format("{0} is not empty", path));
            }
        }
        public static bool WPArchivePDFsToColumbus1(string folderInput, string folderOutput, string reportDir, string columbusFilePrefix, List <ColumbusIndex> lstHodingIdx, List <ColumbusIndex> lstHubnetIdx, ref List <ColumbusIndex> archivedDocs)
        {
            try
            {
                //var idxFiles = FileProcessHelper.GetFiles(folderInput, "*.csv");
                //if (idxFiles.Length != 1)
                //    Log.Fatal("There is no index file or more than 1 index files in " + folderInput);
                //if (idxFiles.Length == 1)
                //{
                //    var indexFile = idxFiles.First();
                //    var csv = new CsvReader(new StringReader(File.ReadAllText(indexFile)));
                //    csv.Configuration.RegisterClassMap<ColumbusHelper.WPColumbusRecordMap>();
                //    csv.Configuration.WillThrowOnMissingField = true;
                //    csv.Configuration.HasHeaderRecord = true;
                //    csv.Configuration.Delimiter = "|";
                //    var records = csv.GetRecords<ColumbusHelper.ColumbusIndex>().ToList();

                ////Enrich pdfs in holding directory
                //var pendingPdfs = FileProcessHelper.GetFiles(folderInput, "*.pdf");
                //var lstHoldingData = new List<WPHoldingData>();

                //foreach (var pdf in pendingPdfs)
                //{
                //    var fileName = new FileInfo(pdf).Name;
                //    var trackingNumber = fileName.Split('_')[1]; //File naming convention: Welcomepack_{Document Number or Tracking number}
                //    var holdingData = new WPHoldingData();
                //    holdingData.fileName = fileName;
                //    holdingData.trackingNumber = trackingNumber;
                //    holdingData.result = "No";
                //    lstHoldingData.Add(holdingData);
                //}


                ////Enrich pdfs in holding directory
                //var pendingPdfs = FileProcessHelper.GetFiles(folderInput, "*.pdf");
                //var lstHoldingData = new List<WPHoldingData>();
                //var documentsToMerge = new List<ColumbusIndex>();
                //foreach (var doc in lstColumbusIdx)
                //{
                //    //var fileName = new FileInfo(pdf).Name;
                //    //var trackingNumber = fileName.Split('_')[1]; //File naming convention: Welcomepack_{Document Number or Tracking number}
                //    var holdingData = new WPHoldingData();
                //    holdingData.fileName = doc.;
                //    holdingData.trackingNumber = trackingNumber;
                //    holdingData.result = "No";
                //    lstHoldingData.Add(holdingData);
                //}

                var documentsToMerge = new List <ColumbusIndex>();
                Parallel.ForEach(lstHodingIdx, (currentDoc) =>
                {
                    foreach (var hubnetData in lstHubnetIdx)
                    {
                        if (hubnetData.DocRefNo == currentDoc.DocRefNo)
                        {
                            currentDoc.IssueDate      = hubnetData.IssueDate;
                            currentDoc.AccountNo      = hubnetData.AccountNo;
                            currentDoc.CustomerNo     = hubnetData.CustomerNo;
                            currentDoc.SalesChannelID = hubnetData.SalesChannelID;
                            currentDoc.FileEnriched   = true;
                            documentsToMerge.Add(currentDoc);
                        }
                    }
                });
                archivedDocs = documentsToMerge;
                if (!WriteConfirmationFile(lstHodingIdx, reportDir))
                {
                    return(false);
                }

                Log.Info(string.Format("{0} welcome packs are ready to merge.", documentsToMerge.Count()));
                int fileNo = 1;
                while (documentsToMerge.Count != 0)
                {
                    var mergePdfName = Path.Combine(folderOutput, string.Format("{0}_{1}.pdf", columbusFilePrefix, fileNo));
                    if (!MergePdfs(folderInput, mergePdfName, ref documentsToMerge))
                    {
                        return(false);
                    }
                    fileNo++;
                }
                Log.Info(string.Format("{0} merged pdfs are ready to archive ", fileNo));

                //Run Columbus Task
                var lstXml = FileProcessHelper.GetFiles(folderOutput, "*.xml");
                var lstPdf = FileProcessHelper.GetFiles(folderOutput, "*.pdf");
                if (!RunColumbus(lstXml, lstPdf))
                {
                    return(false);
                }
                Log.Info("Archive to Columbus Sucessful");

                //Use Confimation report to Update Recon_TackingNumber table and send email back to SE
                //Delete archived Pdfs


                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Failed to merge files in {0} to {1}. ex: {3}", folderInput, folderOutput, ex.Message));
                return(false);
            }
        }