//MicroService 3 public async Task <IActionResult> ProcessDIALSDataNWriteToDB() { try { string dialsFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "DIALSFiles"); if (Directory.Exists(dialsFolderPath)) { var files = Directory.GetFiles(dialsFolderPath); if (files.Length > 0) { foreach (string fileName in files) { log.Info(DateTime.Now.ToString() + " AMS-POC: DIALS file processing in progress - " + fileName); FileStream fileStream = new FileStream(Path.Combine(dialsFolderPath, fileName), FileMode.Open); using (BufferedStream bufferedStream = new BufferedStream(fileStream)) { using (StreamReader streamReader = new StreamReader(bufferedStream)) { while (!streamReader.EndOfStream) { string dialsString = await streamReader.ReadLineAsync(); //Process DIALS data var dialsObject = DIALSUtility.ProcessDIALSData(dialsString); //Store in to DB if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewDIALS(dialsObject); } else { log.Warn(DateTime.Now.ToString() + " AMS-POC: Tracking number not found in DIALS data."); } } } } log.Info(DateTime.Now.ToString() + " AMS-POC: DIALS file processing completed - " + fileName); } log.Info(DateTime.Now.ToString() + " AMS-POC: Total DIALS files processed - " + files.Length); } } } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-POC: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
public void DIALSFileWatcher() { try { var dialsFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "DIALSFiles"); var files = Directory.GetFiles(dialsFolderPath); if (files.Length > 0) { foreach (string fileName in files) { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: DIALS file Read in Progress."); FileStream fileStream = new FileStream(Path.Combine(dialsFolderPath, fileName), FileMode.Open); using (BufferedStream bufferedStream = new BufferedStream(fileStream)) { using (StreamReader streamReader = new StreamReader(bufferedStream)) { while (!streamReader.EndOfStream) { string dialsString = streamReader.ReadLine(); //Process DIALS data var dialsObject = DIALSUtility.ProcessDIALSData(dialsString); //Store in to DB if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { MicroServiceProcessDIALSFile(dialsObject); } else { log.Warn(DateTime.Now.ToString() + " AMS-POC: Tracking number not found in DIALS data."); } } } } } } log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: DIALS file processed and data inserted into DB."); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); } }
//MicroService 3 public async Task <IActionResult> ProcessDIALSDataNWriteToDB() { try { string dialsFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "DIALSFiles"); if (Directory.Exists(dialsFolderPath)) { var files = Directory.GetFiles(dialsFolderPath); if (files.Length > 0) { foreach (string fileName in files) { FileStream fileStream = new FileStream(Path.Combine(dialsFolderPath, fileName), FileMode.Open); using (BufferedStream bufferedStream = new BufferedStream(fileStream)) { using (StreamReader streamReader = new StreamReader(bufferedStream)) { while (!streamReader.EndOfStream) { string dialsString = await streamReader.ReadLineAsync(); //Process DIALS data var dialsObject = DIALSUtility.ProcessDIALSData(dialsString); //Store in to DB if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewDIALS(dialsObject); } } } } } } } } catch { return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
public void DIALSFileWatcher() { try { var dialsFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "DIALSFiles"); var files = Directory.GetFiles(dialsFolderPath); if (files.Length > 0) { foreach (string fileName in files) { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: DIALS file Read in Progress."); FileStream fileStream = new FileStream(Path.Combine(dialsFolderPath, fileName), FileMode.Open); using (BufferedStream bufferedStream = new BufferedStream(fileStream)) { using (StreamReader streamReader = new StreamReader(bufferedStream)) { while (!streamReader.EndOfStream) { string dialsString = streamReader.ReadLine(); if (!string.IsNullOrEmpty(dialsString.Trim()) && dialsString != "\u001a") { //Process DIALS data var dialsObject = DIALSUtility.ProcessDIALSData(dialsString); //Store in to DB if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { MicroServiceProcessDIALSFile(dialsObject); } else { log.Warn(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: Tracking number not found in DIALS data."); } } } } } fileStream.Close(); 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); } } } log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: DIALS file processed and data inserted into DB."); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); } }
public void DIALSFileWatcher() { try { var dialsFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "DIALSFiles"); var files = Directory.GetFiles(dialsFolderPath); if (files.Length > 0) { foreach (string fileName in files) { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: DIALS file Read in Progress."); FileStream fileStream = new FileStream(Path.Combine(dialsFolderPath, fileName), FileMode.Open); using (BufferedStream bufferedStream = new BufferedStream(fileStream)) { using (StreamReader streamReader = new StreamReader(bufferedStream)) { while (!streamReader.EndOfStream) { string dialsString = streamReader.ReadLine(); if (!string.IsNullOrEmpty(dialsString.Trim()) && dialsString != "\u001a") { //Process DIALS data var dialsObject = DIALSUtility.ProcessDIALSData(dialsString); //SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1"); SakilaContext context = new SakilaContext("server=techm.cooavdyjxzoz.us-east-1.rds.amazonaws.com;port=3306;database=ams;user=root;password=Password123"); DIALS dials = context.GetMatchingDialsID(dialsObject.TrackingNumber); //Store in to DB if (!string.IsNullOrEmpty(dialsObject.TrackingNumber) && (dialsObject.TrackingNumber != dials.TrackingNumber)) { MicroServiceProcessDIALSFile(dialsObject); } else { log.Warn(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: Tracking number already exists."); continue; } } } } } fileStream.Close(); //Move file to archive folder var archiveFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "Archive"); DirectoryInfo directoryInfo = Directory.CreateDirectory(archiveFolderPath); var destFile = Path.Combine(archiveFolderPath, fileName.Substring(fileName.LastIndexOf("/"))); var destAPath = fileName.Substring(0, fileName.LastIndexOf("/")); var destFinalPath = destAPath.Substring(0, destAPath.LastIndexOf("/")) + "/Archive/" + destFile; if (!System.IO.File.Exists(destFinalPath)) { System.IO.File.Move(fileName, destFinalPath); } else { System.IO.File.Delete(fileName); } } } log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: DIALS file processed and data inserted into DB."); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); } }