Exemple #1
0
        public void Start()
        {
            OdissLogger.Info("Starting Ariba Windows service...");
            OdissLogger.SetExceptionEmailSubject("OPG Ariba Service threw exceptions, please check log file for more details.");

            if (ConfigurationManager.AppSettings["Test_Mode_Process_One_Day_When_Start_Service"].ToLower() == "true")
            {
                string dateStr = ConfigurationManager.AppSettings["Test_Mode_Date_To_Process_When_Start_Service"];
                if (!string.IsNullOrWhiteSpace(dateStr))
                {
                    DateTime aDate;
                    if (DateTime.TryParse(dateStr, out aDate))
                    {
                        AribaServiceDailyProcess(aDate.AddDays(1), false);  //  the service will always process previous date, so add one day
                    }
                }
            }

            // Create a timer with one minute interval.
            aTimer = new System.Timers.Timer(60000);
            // Hook up the Elapsed event for the timer.
            aTimer.Elapsed  += CheckIfItsTimeToProcessExceptions;
            aTimer.AutoReset = true;
            aTimer.Enabled   = true;

            OdissLogger.Info("Ariba Windows service started...");
            OdissLogger.Info($"The service will process Ariba exceptions daily at hour:{aribaSerivceDailyProcessAtHour}, minute:{aribaSerivceDailyProcessAtMinute}, now is:{DateTime.Now.Hour}:{DateTime.Now.Minute}");
        }
Exemple #2
0
        public static int GetSenderFromvwEmail(string pureSourceImage, out string sender, out DateTime?receivedDate)
        {
            sender       = "";
            receivedDate = null;

            pureSourceImage = pureSourceImage.ToUpper();

            try
            {
                using (var db = new OPG_EMAILEntities())
                {
                    db.Database.CommandTimeout = 180;
                    var email = db.vw_Email.SingleOrDefault(x => x.ProcessFileName.ToUpper() == pureSourceImage);

                    if (email == null)
                    {
                        OdissLogger.Info($"No record in vw_email with ProcessFileName = {pureSourceImage}");
                    }
                    else
                    {
                        sender       = email.Sender;
                        receivedDate = email.RecievedDate;
                    }
                }
            }

            catch (Exception ex)
            {
                OdissLogger.Error($"GetSenderFromEmail error:{ex.ToString()}");
                return(-3);
            }

            return(1);
        }
Exemple #3
0
        private static void CheckIfItsTimeToProcessExceptions(Object source, ElapsedEventArgs e)
        {// check every minute to see if it's time to process Ariba process.
            DateTime now = DateTime.Now;

            if (now.Hour == aribaSerivceDailyProcessAtHour && now.Minute == aribaSerivceDailyProcessAtMinute)
            {
                OdissLogger.Info($"It's time to process Ariba exceptions.");

                AribaServiceDailyProcess(now, true);
            }
        }
Exemple #4
0
        public void Stop()
        {
            stopRequested = true;

            OdissLogger.Info("Stopping Ariba Windows service...");
            aTimer.Stop();
            aTimer.Dispose();

            Thread.Sleep(3000);

            OdissLogger.Info("Ariba Windows service stopped...");
        }
Exemple #5
0
        public static void AribaServiceDailyProcess(DateTime triggerTime, bool processDaysTillPreviousDay)
        {// if processDaysTillPreviousDay is true, then process multiple days, otherwise only process one day: previous day
            DateTime processEndDate = triggerTime.AddDays(-1);

            if (!processDaysTillPreviousDay)
            {
                OdissLogger.Info($"Start to process Ariba exceptions: one day only:{processEndDate.ToString("yyyy-MM-dd")}");
            }
            else
            {
                OdissLogger.Info($"Start to process Ariba exceptions: from: {aribaExceptionsStartDate.ToShortDateString()} to:{processEndDate.ToShortDateString()}");
            }

            ProcessAribaDayExceptions(processEndDate, processDaysTillPreviousDay);
        }
Exemple #6
0
        public static int ProcessAribaDayExceptionList(DateTime aDate, List <GetAribaWaitingExceptionList_Result> processList)
        {
            string filename, processMessage;

            foreach (var process1 in processList)
            {
                if (stopRequested)
                {
                    return(0);
                }

                filename = process1.PrimaryFileName;
                try
                {
                    int iret = ProcessPrimaryFile(process1.FinalizationTime.Value, process1.PrimaryFileName, out processMessage);

                    if (iret == 1) // if all right, then move files to backup folder
                    {
                        MoveFilesToBackupFolder(process1.FinalizationTime.Value, process1.PrimaryFileName);
                    }

                    // insert into AribaProcessedException table, so it wont pricess it next time
                    AribaProcessedException processed1 = new AribaProcessedException();
                    processed1.OICSConnectorProcessId = process1.OICSConnectorProcessId;
                    processed1.ProcessedDate          = DateTime.Now;
                    processed1.ServiceState           = iret;
                    processed1.ServiceDetails         = processMessage;

                    using (var db = new Octacom_OICS_Entities())
                    {
                        db.Entry(processed1).State = System.Data.Entity.EntityState.Added;
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    OdissLogger.Error($"Error occurred when process {filename}: {ex.ToString()}");
                }
            }

            OdissLogger.Info($"Ariba service processed {processList.Count} exception records.");

            return(1);
        }
Exemple #7
0
        public static int ProcessAribaDayExceptions(DateTime aDate, bool processDaysTillPreviousDay)
        {
            List <GetAribaWaitingExceptionList_Result> processList;

            int iret = GetDayExceptionList(aDate, processDaysTillPreviousDay, out processList);

            if (iret != 1)
            {
                return(iret);
            }

            if (processList != null && processList.Count > 0)
            {
                if (processDaysTillPreviousDay)
                {
                    OdissLogger.Info($"Found {processList.Count} exception records in OICSConnectorProcess table which FinalizationTime between {aribaExceptionsStartDate.ToString("yyyy-MM-dd")} and {aDate.ToString("yyyy-MM-dd")} and HasErrors is true. Processing started.");
                }
                else
                {
                    OdissLogger.Info($"Found {processList.Count} exception records in OICSConnectorProcess table which FinalizationTime is {aDate.ToString("yyyy-MM-dd")} and HasErrors is true. Processing started.");
                }

                ProcessAribaDayExceptionList(aDate, processList);
            }
            else
            {
                if (processDaysTillPreviousDay)
                {
                    OdissLogger.Info($"There is no unprocessed exception record between {aribaExceptionsStartDate.ToString("yyyy-MM-dd")} and {aDate.ToString("yyyy-MM-dd")}.");
                }
                else
                {
                    OdissLogger.Info($"There is no unprocessed exception record for date:{aDate.ToString("yyyy-MM-dd")}.");
                }
            }

            return(1);
        }
Exemple #8
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 #9
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);
        }