public void OPLDFileWatcher() { try { var opldFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "OPLDFiles"); var files = Directory.GetFiles(opldFolderPath); if (files.Length > 0) { foreach (string fileName in files) { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD file Read in Progress."); string opldString = System.IO.File.ReadAllText(Path.Combine(opldFolderPath, fileName)); //Process OPLD data var opldObject = OPLDUtility.ProcessOPLD(opldString); //Check is File already Processed SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1"); bool trackResult = context.CheckIsTrackingNumberAlreadyExists(opldObject.TrackingNumber); if (trackResult) { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD file Read already processed."); continue; } log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD file Processed."); //Push OPLD to Queue MicroServiceProcessOPLDFile(opldObject); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD Message Pushed to MQ."); var archiveFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "Archive"); DirectoryInfo directoryInfo = Directory.CreateDirectory(archiveFolderPath); if (!System.IO.File.Exists(archiveFolderPath + fileName.Substring(fileName.LastIndexOf("\\")))) { System.IO.File.Move(fileName, archiveFolderPath + fileName.Substring(fileName.LastIndexOf("\\"))); } else { System.IO.File.Delete(fileName); } } } } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); } }