public void Execute(IJobExecutionContext context) { try { MoveCarsMain moveCarsMain = new MoveCarsMain(); SendEmailandSms sendEmailandSms = new SendEmailandSms(); moveCarsMain.EmailSmsEvent += sendEmailandSms.OnSendtoEmployee; moveCarsMain.EmailSmsEventNoBlocked += sendEmailandSms.OnSendtoEmployeeNoBlocked; moveCarsMain.EmailSmsEventNoBlocker += sendEmailandSms.OnSendtoEmployeeNoBlocker; moveCarsMain.Execute(); } catch (Exception ex) { throw ex; } }
public bool TestOracleConnection() { using (MySqlConnection connection = new MySqlConnection("SERVER = localhost ; DATABASE= Oracledb ; UID= root ; PASSWORD=;")) { try { connection.Open(); return(true); } catch (MySqlException ex) { SendEmailandSms sendemail = new SendEmailandSms(); sendemail.Email("*****@*****.**", $"{ex.Message} {ex.InnerException} {ex.StackTrace}", "Blocked Car App - MySql Database not Accessible "); return(false); } } }
public bool TestMySqlConnection() { MySqldb = new MySQLdb(); DbConnection mySqlconn = MySqldb.Database.Connection; try { mySqlconn.Open(); // check MySql database connection MySqldb.Database.Exists(); var count = MySqldb.car_request.Count(); return(true); } catch (Exception ex) { SendEmailandSms sendemail = new SendEmailandSms(); sendemail.Email("*****@*****.**", $"{ex.Message} {ex.InnerException} {ex.StackTrace}", "Blocked Car App - MySql Database not Accessible "); return(false); } }
public void Execute() { while (_mysqlRep.TestMySqlConnection() == false || _oracleRep.TestOracleConnection() == false) { if (_mysqlRep.TestMySqlConnection() == false) { Logger.Info("Cannot Access MySQL Database"); } else { Logger.Info("Cannot Access Oracle Database"); } Thread.Sleep(5000); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); foreach (car_request req in _mysqlRep.OpenCases()) { try { CAR_USER_VIEW carUserBlocked = _oracleRep.CarUserBlocked(req?.CAR_USERNAME); List <CAR_USER_VIEW> carUserBlockers = _oracleRep.CarUserBlockers(req?.PLATE_NUMBER); _mysqlRep.ChangeStatus(req, "INPROGRESS"); if (carUserBlockers?.Count >= 1 && carUserBlocked?.EMAIL != null) { // Apply the "ChangeUserWorkExtensionToFullPhone" Method for all users found first carUserBlocked.EXTENSION = ChangeUserWorkExtensionToFullPhone(carUserBlocked.EXTENSION); foreach (CAR_USER_VIEW caruserBlocker in carUserBlockers) { if (caruserBlocker.EMAIL != null) { caruserBlocker.EXTENSION = ChangeUserWorkExtensionToFullPhone(caruserBlocker.EXTENSION); OnSendtoEmployee(caruserBlocker, carUserBlocked); Logger.Info($"Request N {req?.ID} Blocked: {carUserBlocked?.EMAIL} Blocker: {caruserBlocker?.EMAIL} "); //Notification(); //add log to Oracle _oracleRep.OracleTransactionLog(carUserBlocked, caruserBlocker, req); } } } else if ((carUserBlockers.Count < 1 || carUserBlockers == null) && carUserBlocked?.EMAIL != null) { carUserBlocked.EXTENSION = ChangeUserWorkExtensionToFullPhone(carUserBlocked?.EXTENSION); OnSendtoEmployeeNoBlocker(carUserBlocked, req); Logger.Info($"Request N {req?.ID} Blocked: {carUserBlocked?.EMAIL} "); } // blocked user not found -- what the hell case !! else if (carUserBlocked?.EMAIL == null && carUserBlockers?.Count >= 1) { SendEmailandSms sendemail = new SendEmailandSms(); // this email is sent to admin, to enform him that there is a blocked user with no database record ! sendemail.Email("*****@*****.**", $"Hi yehia, Case ID is :{req?.ID}", "Blocked Car App - Cannot find the Blocked User - Admin Mail"); foreach (CAR_USER_VIEW caruserBlocker in carUserBlockers) { caruserBlocker.EXTENSION = ChangeUserWorkExtensionToFullPhone(caruserBlocker?.EXTENSION); OnSendtoEmployeeNoBlocked(caruserBlocker, req); Logger.Info($"Request N {req?.ID} Blocker: {caruserBlocker?.EMAIL} "); //Notification(); //add log to Oracle _oracleRep.OracleTransactionLog(null, caruserBlocker, req); } } // Both blocked user and Blockers not found -- what the hell case !! else if ((carUserBlockers.Count < 1 || carUserBlockers == null) && carUserBlocked?.EMAIL == null) { _mysqlRep.ChangeStatus(req, "BlockedandBlockerNF"); return; } // Unknown or unpredictable Case ! else { _mysqlRep.ChangeStatus(req, "BlockedandBlockerNF"); return; } _mysqlRep.ChangeStatus(req, "RESOLVED"); } catch (Exception ex) { Logger.Error($"{req?.ID} {ex?.Message} {ex?.InnerException} {ex?.StackTrace}"); //_mysqlRep.ChangeStatus(req, "OPEN"); SendEmailandSms sendemail = new SendEmailandSms(); sendemail.Email("*****@*****.**", $"{ex.Message} {ex.InnerException} {ex.StackTrace}", "General Exception"); } } stopwatch.Stop(); }