From f765fe48b978663ed86ce619afc0d853eda6beb3 Mon Sep 17 00:00:00 2001 From: Laurentiu Date: Wed, 12 Jun 2024 18:18:20 +0300 Subject: [PATCH] avoid flooding logs if the email sending failed --- AppServer/LocationThread.cs | 26 +++++++++++++++++++++++--- AppServer/MulticastListener.cs | 18 ++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/AppServer/LocationThread.cs b/AppServer/LocationThread.cs index 6e51c4e..5fa07b8 100644 --- a/AppServer/LocationThread.cs +++ b/AppServer/LocationThread.cs @@ -22,6 +22,7 @@ namespace AppServer private volatile DBsubsOperationManager dbsubsoperManage; private volatile DBvehiclesManager dbvehs; private DBvehiclesManager DBvehInfo; + List blackListAddress = new List(); public static volatile Int32 LocationCheckQueuesCount = 0; Int64 count = 0; @@ -410,6 +411,12 @@ namespace AppServer if (Program.cfg.enableEmailService && !String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr)) { + if (blackListAddress.Contains(mailAdr)) + { + Utils.WriteLine($" sendMailGeo : The email was not sent. Email address '{mailAdr}' is in blacklist "); + return; + } + try { MailAddress from = new MailAddress(Program.cfg.emailAddress); @@ -433,7 +440,10 @@ namespace AppServer } catch (Exception ex) { - Console.WriteLine("Exception in sendMailGeo: ", ex.ToString()); + if (ex.ToString().Contains("timed out")) + blackListAddress.Add(mailAdr); + + Utils.WriteLine($"Exception in sendMailGeo: {ex.ToString()}"); } } else @@ -447,6 +457,13 @@ namespace AppServer { if (Program.cfg.enableEmailService && !String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr)) { + + if (blackListAddress.Contains(mailAdr)) + { + Utils.WriteLine($" sendAlarmMail : The email was not sent. Email address '{mailAdr}' is in blacklist "); + return; + } + try { MailAddress from = new MailAddress(Program.cfg.emailAddress); @@ -458,14 +475,17 @@ namespace AppServer } catch (Exception ex) { + if (ex.ToString().Contains("timed out")) + blackListAddress.Add(mailAdr); + Utils.WriteLine("Exception in sendMailAlarm2: {0}" + ex.ToString(), ConsoleColor.Red); } } else { - Utils.WriteLine("Email Server not Set",ConsoleColor.Cyan); + Utils.WriteLine("Email Server not Set", ConsoleColor.Cyan); } - } + } private String processZoneAlarm(string radioID, htCell_t cell, bool zone, bool landMArk, string mailAdr, bool sendOnMsgBus) { diff --git a/AppServer/MulticastListener.cs b/AppServer/MulticastListener.cs index cd1b174..d3f0e23 100644 --- a/AppServer/MulticastListener.cs +++ b/AppServer/MulticastListener.cs @@ -28,6 +28,8 @@ namespace AppServer private DBvehiclesManager dbvehs; internal DBsubsOperationManager dbsubsoperManage; private DBcallPatchManager dbCallPatch; + private List blackListAddress = new List(); + #region code for zone private volatile static ArrayList ZoneList = new ArrayList(); private volatile static ArrayList LandList = new ArrayList(); @@ -2150,6 +2152,13 @@ namespace AppServer private void sendAlarmMail(string mes, string mailAdr) { + + if (blackListAddress.Contains(mailAdr)) + { + Utils.WriteLine($" sendAlarmMail : The email was not sent. Email address '{mailAdr}' is in blacklist "); + return; + } + try { MailAddress from = new MailAddress(Program.cfg.emailAddress); @@ -2161,12 +2170,17 @@ namespace AppServer } catch (Exception ex) { + if (ex.ToString().Contains("timed out")) + blackListAddress.Add(mailAdr); + Utils.WriteLine("Exception in sendMailAlarm: " + ex.ToString(), ConsoleColor.Red); //Console.WriteLine(e.ToString()); } - } + } - public void sendDailyReportMail(String PdfFile, string mailAdr) + + + public void sendDailyReportMail(String PdfFile, string mailAdr) { try {