//MicroService 4 public IActionResult ReadMQ2OPLDNCreateSPNPushTOMQ3() { try { //Read from MQ OPLD opldObject = CommonUtility <OPLD> .PullFromActiveMQ(2); ServicePoint servicePointObject = new ServicePoint(); //CreateServicepoint //Check if opld tracking number matches with dials matching number SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; DIALS dialsObject = context.GetMatchingDialsID(opldObject.TrackingNumber); if (dialsObject != null) { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, dialsObject.ConsigneeName, dialsObject.ClarifiedSignature, true); } else { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, "", "", false); } //Push OPLD in to Active MQ2 CommonUtility <ServicePoint> .PushToActiveMQ(servicePointObject, 3); } catch { return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
public DIALS GetMatchingDialsID(string trackingNumber) { DIALS dialsObject = new DIALS(); try { using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM DialsData WHERE TrackingNumber =", conn); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { if (reader.IsDBNull(0)) { return(null); } else { dialsObject.DialsID = reader.GetInt32("DialsID"); dialsObject.ConsigneeName = reader.GetString("ConsigneeName"); dialsObject.ClarifiedSignature = reader.GetString("ClarifiedSignature"); } } } } } catch (Exception ex) { return(null); } return(dialsObject); }
public IActionResult MicroServiceServicePointGeneration(OPLD opldObject) { try { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Read OPLD message and Start processing."); //CreateServicepoint //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"); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Getting OPLD tracking number matching DIALS record."); //Check if opld tracking number matches with dials matching number DIALS dialsObject = context.GetMatchingDialsID(opldObject.SHIP_SP_NR); ServicePoint servicePointObject = new ServicePoint(); if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { //Match found //Compare OPLD Add1 with SP Add1 and Update timestamp and increase Stop ID ServicePoint servicePoint = context.CompareOPLDAdd1WithSPAddr1(opldObject.SHIP_ADDR_LINE_1_1); if (servicePoint != null && (servicePoint.ServicePointID != 0)) { context.UpdateServicePoint(servicePoint.ServicePointID); } else { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, dialsObject.ConsigneeName, dialsObject.ClarifiedSignature, true); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Writing ServicePoint in to DB."); //Write Servicepoint to DB context.AddNewServicePoint(servicePointObject); } } else { //Create Service Point with Stop ID = 1 servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, opldObject.SHIP_ATTENTION_NAME_1, "", false); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Writing ServicePoint in to DB."); //Write Servicepoint to DB context.AddNewServicePoint(servicePointObject); } //Update OPLD Processing Status context.UpdateOPLDProcessingStatus(opldObject.SHIP_SP_NR); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: " + Convert.ToString(ex.ToString())); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public IActionResult MicroServiceProcessDIALSFile(DIALS dialsObject) { try { SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1"); context.AddNewDIALS(dialsObject); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public IActionResult MicroServiceProcessDIALSFile(DIALS dialsObject) { try { SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewDIALS(dialsObject); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public IActionResult MicroServiceProcessDIALSFile(DIALS dialsObject) { try { SakilaContext context = new SakilaContext("server=techm.cooavdyjxzoz.us-east-1.rds.amazonaws.com;port=3306;database=sakila;user=root;password=Password123"); context.AddNewDIALS(dialsObject); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public bool AddNewDIALS(DIALS newDIALSdata) { int rowsAffected = 0; using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand("INSERT INTO dialsdata VALUES('" + (GetLastDIALSID() + 1) + "','" + newDIALSdata.TrackingNumber + "','" + newDIALSdata.ShiperNumber + "','" + newDIALSdata.ClarifiedSignature + "','" + newDIALSdata.ConsigneeName + "','" + newDIALSdata.Region + "','" + newDIALSdata.District + "','" + newDIALSdata.SLIC + "','" + newDIALSdata.Country + "','" + newDIALSdata.DeliverySLICState + "','" + newDIALSdata.City + "','" + newDIALSdata.StreetNumber + "','" + newDIALSdata.StreetName + "','" + newDIALSdata.StreetType + "','" + newDIALSdata.BuildingFloorNumber + "','" + newDIALSdata.RoomSuiteNumber + "','" + newDIALSdata.PostalCode + "','" + DateTime.Now.ToString() + "')", conn); rowsAffected = cmd.ExecuteNonQuery(); } return(rowsAffected > 0 ? true : false); }
//MicroService 4 public IActionResult ReadMQ2OPLDNCreateSPNPushTOMQ3() { try { //Read from MQ //OPLD opldObject = CommonUtility<OPLD>.PullFromActiveMQ(2); log.Info(DateTime.Now.ToString() + " AMS-POC: Service point genration process started."); ServicePoint servicePointObject = new ServicePoint(); var opldProcString = Request.Headers["opldProcString"]; OPLD opldObject = Newtonsoft.Json.JsonConvert.DeserializeObject <OPLD>(opldProcString); //CreateServicepoint //Check if opld tracking number matches with dials matching number SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; DIALS dialsObject = context.GetMatchingDialsID(opldObject.TrackingNumber); if (dialsObject != null) { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, dialsObject.ConsigneeName, dialsObject.ClarifiedSignature, true); } else { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, "", "", false); } //Push OPLD in to Active MQ2 CommonUtility <ServicePoint> .PushToActiveMQ(servicePointObject, 3); log.Info(DateTime.Now.ToString() + " AMS-POC: Service point Created and Pushed to MQ3."); } 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 IActionResult MicroServiceServicePointGeneration(OPLD opldObject) { try { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Read OPLD message and Start processing."); //CreateServicepoint SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1");//HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Getting OPLD tracking number matching DIALS record."); //Check if opld tracking number matches with dials matching number DIALS dialsObject = context.GetMatchingDialsID(opldObject.TrackingNumber); ServicePoint servicePointObject = new ServicePoint(); if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, dialsObject.ConsigneeName, dialsObject.ClarifiedSignature, true); } else { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, "", "", false); } log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Writing ServicePoint in to DB."); //Write Servicepoint to DB context.AddNewServicePoint(servicePointObject); //Update OPLD Processing Status context.UpdateOPLDProcessingStatus(opldObject.TrackingNumber); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public static DIALS ProcessDIALSData(string dialsString) { DIALS dialsData = new DIALS(); dialsData.TrackingNumber = dialsString.Substring(0, 18).Trim(); dialsData.ShiperNumber = dialsString.Length > 348 ? dialsString.Substring(348, 10).Trim() : ""; dialsData.ClarifiedSignature = dialsString.Length > 295 ? dialsString.Substring(295, 15).Trim() : ""; dialsData.ConsigneeName = dialsString.Length > 270 ? dialsString.Substring(270, 25).Trim() : ""; dialsData.Region = dialsString.Length > 120 ? dialsString.Substring(120, 2).Trim() : ""; dialsData.District = dialsString.Length > 122 ? dialsString.Substring(122, 2).Trim() : ""; dialsData.SLIC = dialsString.Length > 124 ? dialsString.Substring(124, 5).Trim() : ""; dialsData.Country = dialsString.Length > 129 ? dialsString.Substring(129, 2).Trim() : ""; dialsData.DeliverySLICState = dialsString.Length > 131 ? dialsString.Substring(131, 2).Trim() : ""; dialsData.City = dialsString.Length > 139 ? dialsString.Substring(139, 30).Trim() : ""; dialsData.StreetNumber = dialsString.Length > 169 ? dialsString.Substring(169, 11).Trim() : ""; dialsData.StreetName = dialsString.Length > 182 ? dialsString.Substring(182, 30).Trim() : ""; dialsData.StreetType = dialsString.Length > 212 ? dialsString.Substring(212, 4).Trim() : ""; dialsData.BuildingFloorNumber = dialsString.Length > 218 ? dialsString.Substring(218, 3).Trim() : ""; dialsData.RoomSuiteNumber = dialsString.Length > 221 ? dialsString.Substring(221, 8).Trim() : ""; dialsData.PostalCode = dialsString.Length > 229 ? dialsString.Substring(229, 8).Trim() : ""; return(dialsData); }
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)); } }