Exemple #1
0
        public static int GeneratePDFFile(string primaryFileName, string originalPdfFileFolder, DateTime finalizationTime, out string directoryId, out string pdfFileName, out string processMessage)
        {
            string targetPDFBaseFolder = GetPDFRootFolder();

            pdfFileName    = "";
            directoryId    = "";
            processMessage = "";

            string pdfStorageFolder;

            int iret = DirLocation.PreparePDFFolderAndDirectoryId(targetPDFBaseFolder, finalizationTime, out directoryId, out pdfStorageFolder);

            if (iret != 1)
            {
                processMessage = $"Could not prepare directoryId and pdf storage folder: {primaryFileName}, {targetPDFBaseFolder}, {finalizationTime}";
                OdissLogger.Error(processMessage);
                return(-1);
            }


            string pdfSourceFileName = primaryFileName.ToUpper().Replace("XML", "pdf");

            pdfFileName = pdfSourceFileName + ".pdf";

            string sourceFullName, storageFullName;

            sourceFullName  = originalPdfFileFolder + pdfSourceFileName;
            storageFullName = pdfStorageFolder + pdfFileName;

            if (!File.Exists(sourceFullName))
            {
                processMessage = $"Source pdf file:{sourceFullName} does not exist, primary file name: {primaryFileName}, finalization time: {finalizationTime.ToString()}";
                OdissLogger.Error(processMessage);
                return(-2);
            }

            try
            {
                File.Copy(sourceFullName, storageFullName);
            }
            catch (Exception ex)
            {
                string details = ex.ToString();
                processMessage = $"Could not copy pdf file, from {sourceFullName} to {storageFullName}. Details:{details}";
                OdissLogger.Error(processMessage);

                if (details.IndexOf("already exists") > 0)
                {
                    processMessage = "Pdf file exists, process continues.";
                    return(0);
                }

                return(-3);
            }

            processMessage = "";
            return(1);
        }
Exemple #2
0
        public void TestPreparePDFFolderAndDirectoryId()
        {
            //Arrange
            string   rootfolder = AribaHelper.GetPDFRootFolder();
            DateTime today = DateTime.Now;
            string   directoryId, pdffolder;

            //Act
            var ret = DirLocation.PreparePDFFolderAndDirectoryId(rootfolder, today, out directoryId, out pdffolder);

            //Assert
            Assert.AreNotEqual(0, ret);
        }
Exemple #3
0
        public static int ProcessOctacomException(DateTime processDate, string xmlFullFileName)
        {
            if (!File.Exists(xmlFullFileName))
            {
                OdissLogger.Error($"Xml source file does not exist: {xmlFullFileName}");
                return(-1);
            }

            string              errorCode, batchType, pureSoureImage;
            tblGroup            aGroup;
            List <tblGroupLine> lines;

            int iret = ParseOctacomExceptionXmlFile(xmlFullFileName, out batchType, out errorCode, out pureSoureImage, out aGroup, out lines);

            if (iret != 1)
            {
                OdissLogger.Error($"Parse {xmlFullFileName} error. Return code:{iret}");
                return(-2);
            }

            if (errorCode == "E000")
            {
                OdissLogger.Info($"Error code is E000, no further process. File path: {xmlFullFileName} ");
                return(1);
            }

            int    ind          = xmlFullFileName.LastIndexOf("\\");
            string sourceFolder = xmlFullFileName.Substring(0, ind + 1); // with back slash at the end
            string xmlFileName  = xmlFullFileName.Substring(ind + 1);


            string pdfFileName = errorCode + "_" + xmlFileName.ToUpper().Replace(".XML", ".PDF");  // error code like: E002

            if (!File.Exists(sourceFolder + pdfFileName))
            {
                OdissLogger.Error($"Pdf file does not exist: {pdfFileName} at folder: {sourceFolder}");
                return(-3);
            }

            string pdfStorageFolder, directoryId;
            string targetPDFBaseFolder = GetPDFRootFolder();

            iret = DirLocation.PreparePDFFolderAndDirectoryId(targetPDFBaseFolder, processDate, out directoryId, out pdfStorageFolder);
            if (iret != 1)
            {
                OdissLogger.Error($"Could not prepare directoryId and pdf storage folder: {xmlFileName}, {targetPDFBaseFolder}, {processDate}");
                return(-4);
            }

            if (batchType == "OPG-EMAIL")
            {
                string   sender;
                DateTime?receivedDate;
                string   shortProcessFileName = xmlFileName.ToUpper().Replace(".XML", "");  //OPG_AP.20181115.000002.03
                iret = GetSenderFromvwEmail(pureSoureImage, out sender, out receivedDate);
                if (iret == 1)
                {
                    aGroup.Sender       = sender;
                    aGroup.ReceivedDate = receivedDate;
                }

                aGroup.Source = "EMAIL";
            }
            else
            {
                aGroup.Source = "SCAN";
            }

            try
            {
                File.Copy(sourceFolder + pdfFileName, pdfStorageFolder + pdfFileName);

                File.Delete(sourceFolder + pdfFileName); // delete pdf file as Yogesh requested
                File.Delete(xmlFullFileName);            // delete xml file

                OdissLogger.Info($"File: {sourceFolder + pdfFileName} and {xmlFullFileName} have been deleted.");
            }
            catch (Exception ex)
            {
                string details = ex.ToString();

                if (details.IndexOf("already exists") < 0)// ignore file exists error
                {
                    OdissLogger.Error($"Copy file error: from {sourceFolder + pdfFileName} to {pdfStorageFolder + pdfFileName}. Info:{details}");
                    return(-5);
                }
                else
                {
                    //File.Delete(sourceFolder + pdfFileName); // delete pdf file as Yogesh requested
                    //File.Delete(xmlFullFileName); // delete xml file

                    OdissLogger.Info($"{xmlFullFileName} has been processed previously.");
                }
            }

            aGroup.OctProcessFilename = pureSoureImage;
            aGroup.DocType            = "Octacom";
            aGroup.Filename           = pdfFileName;
            aGroup.DirectoryID        = directoryId;
            aGroup.GUID          = Guid.NewGuid();
            aGroup.XMLFile       = xmlFileName;
            aGroup.I_CaptureDate = DateTime.Now;

            //check if process file name has been added, if added no more process
            using (var db = new Odiss_OPG_BaseEntities())
            {
                var group1 = db.tblGroups.FirstOrDefault(x => x.XMLFile == xmlFileName);

                if (group1 != null)
                {
                    OdissLogger.Info($"XML file:{xmlFileName} has been processed. The group record will be updated, the original record is: " + JsonConvert.SerializeObject(group1, new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    }));
                    group1.Filename        = pdfFileName;
                    group1.DirectoryID     = directoryId;
                    group1.I_CaptureDate   = DateTime.Now;
                    group1.DocType         = "Octacom";
                    db.Entry(group1).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    TblGroupHelper.AddTblGroup(aGroup);
                }
            }

            return(1);
        }
Exemple #4
0
        public static int ProcessOctacomException(DateTime processDate, string xmlFullFileName)
        {
            if (!File.Exists(xmlFullFileName))
            {
                OdissLogger.Error($"Xml source file does not exist: xmlFullFileName");
                return(-1);
            }

            string              errorCode, batchType;
            tblGroup            aGroup;
            List <tblGroupLine> lines;

            int iret = ParseOctacomExceptionXmlFile(xmlFullFileName, out batchType, out errorCode, out aGroup, out lines);

            if (iret != 1)
            {
                OdissLogger.Error($"Parse {xmlFullFileName} error. Return code:{iret}");
                return(-2);
            }

            if (errorCode == "E000")
            {
                OdissLogger.Info($"Error code is E000, no further process. File path: {xmlFullFileName} ");
                return(1);
            }

            int    ind          = xmlFullFileName.LastIndexOf("\\");
            string sourceFolder = xmlFullFileName.Substring(0, ind + 1); // with back slash at the end
            string xmlFileName  = xmlFullFileName.Substring(ind + 1);


            string pdfFileName = errorCode + "_" + xmlFileName.ToUpper().Replace(".XML", ".PDF");  // error code like: E002

            if (!File.Exists(sourceFolder + pdfFileName))
            {
                OdissLogger.Error($"Pdf file does not exist: {pdfFileName} at folder: {sourceFolder}");
                return(-3);
            }

            string pdfStorageFolder, directoryId;
            string targetPDFBaseFolder = GetPDFRootFolder();

            iret = DirLocation.PreparePDFFolderAndDirectoryId(targetPDFBaseFolder, processDate, out directoryId, out pdfStorageFolder);
            if (iret != 1)
            {
                OdissLogger.Error($"Could not prepare directoryId and pdf storage folder: {xmlFileName}, {targetPDFBaseFolder}, {processDate}");
                return(-4);
            }

            if (batchType == "OPG-EMAIL")
            {
                string   sender;
                DateTime?receivedDate;
                string   shortProcessFileName = xmlFileName.ToUpper().Replace(".XML", "");  //OPG_AP.20181115.000002.03
                iret = GetSenderFromvwEmail(shortProcessFileName, out sender, out receivedDate);
                if (iret == 1)
                {
                    aGroup.Sender       = sender;
                    aGroup.ReceivedDate = receivedDate;
                }

                aGroup.Source = "EMAIL";
            }
            else
            {
                aGroup.Source = "SCAN";
            }

            try
            {
                File.Copy(sourceFolder + pdfFileName, pdfStorageFolder + pdfFileName);
            }
            catch (Exception ex)
            {
                string details = ex.ToString();
                OdissLogger.Error($"Copy file error: from{sourceFolder + pdfFileName} to {pdfStorageFolder + pdfFileName}. Info:{details}");

                if (details.IndexOf("already exists") < 0)// ignore file exists error
                {
                    return(-5);
                }
            }

            aGroup.DocType         = "Octacom";
            aGroup.Filename        = pdfFileName;
            aGroup.DirectoryID     = directoryId;
            aGroup.GUID            = Guid.NewGuid();
            aGroup.ProcessFilename = xmlFileName;
            aGroup.I_CaptureDate   = DateTime.Now;

            TblGroupHelper.AddTblGroup(aGroup);

            return(1);
        }