protected override void OnStop() { try { ConfigSettings.SetRules(); string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); try { //if ( DinnerMonitorTimer != null ) //{ // DinnerMonitorTimer.Stop(); // DinnerMonitorTimer = null; //} //Fire an E - mail for RED ALERT List <string> receivers = new List <string> { "*****@*****.**" }; EmailModel mail = new EmailModel() { Recipients = receivers, Body = "<p>THE <b>ACT MONITOR (Windows Service)</b> HAS BEEN STOPPED! PLEASE RECTIFY IMMEDIATELY...</p><p>You can safely ignore this e-mail but you'll be held responsible for customer unsatisfictory!</p><p>Best Regards<br /> ACT Team</p>", From = "*****@*****.**", Subject = "ACT MONITOR HAS BEEN STOPPED!" }; bool sent = Mail.Send(mail); mail.Dispose(); } catch (Exception ex) { BaseMonitor.Error(Writer, ex, "OnStop - Email"); } Writer.WriteLine(); Writer.WriteLine(string.Format("======================== SERVICE STOPPED @ {0} ========================", DateTime.Now)); Writer.Flush(); } catch (Exception ex) { BaseMonitor.Error(Writer, ex, "OnStop - Main"); } }
/// <summary> /// Exports FAMOUS BRANDS Campaign Purchases to Clientele using SFTP /// </summary> /// <param name="writer"></param> /// <returns></returns> public static bool CheckClientContracts(StreamWriter writer) { try { if (!ConfigSettings.SystemRules.ClientMonitorEnabled) { Info(writer, $" Checking of Client Contracts is disabled by Admin. RETURNING @{DateTime.Now}"); return(true); } using (ClientService cservice = new ClientService()) { Info(writer, $" BEGIN: Checking of Client Contracts... @{DateTime.Now}"); List <ClientCustomModel> list = cservice.List1(new PagingModel() { Take = int.MaxValue }, new CustomSearchModel() { PSPClientStatus = PSPClientStatus.Verified }); int months = ConfigSettings.SystemRules.ClientContractRenewalReminderMonths ?? 3; List <ClientCustomModel> due = list.Where(c => c.ContractRenewalDate.HasValue && (DateTime.Now - c.ContractRenewalDate.Value).Days >= (months * 30)).ToList(); Info(writer, $" - There are {list.Count} Active Clients... @{DateTime.Now}"); Info(writer, $" - There are {due.Count} Active Clients with contracts expiring in {months} months or less... @{DateTime.Now}"); if (due.Any()) { return(true); } foreach (ClientCustomModel item in due) { List <string> receivers = new List <string> { ConfigSettings.SystemRules.SystemContactEmail, ConfigSettings.SystemRules.FinancialContactEmail }; EmailModel mail = new EmailModel() { Recipients = receivers, Body = $"<p>The contract between ACT and <b>{item.CompanyName}</b> will be expiring on {item.ContractRenewalDate?.ToString( "yyyy-MM-dd" )} (in {( DateTime.Now - item.ContractRenewalDate.Value ).Days} days). Please rectify accordingly to stop receiving this daily email notification.</p><p>You can safely ignore this e-mail but you'll be held responsible for customer unsatisfictory!</p><p>Best Regards<br /> ACT Team</p>", From = ConfigSettings.SystemRules.SystemContactEmail, Subject = $"{item.CompanyName} - Client Contract Expiry Notice" }; bool sent = Mail.Send(mail); mail.Dispose(); } Info(writer, $" END: Checking of Client Contracts... @{DateTime.Now}"); } } catch (Exception ex) { Error(writer, ex, "CheckClientContracts"); return(false); } return(true); }