Compare commits

..

No commits in common. "6737c17c27d41a71bf83c4e2ae07ef0fb90b2f7f" and "13f25867b830d58ccc8f9afb85be75504c462d2c" have entirely different histories.

3 changed files with 113 additions and 217 deletions

View File

@ -22,7 +22,7 @@ namespace AppServer
private volatile DBsubsOperationManager dbsubsoperManage; private volatile DBsubsOperationManager dbsubsoperManage;
private volatile DBvehiclesManager dbvehs; private volatile DBvehiclesManager dbvehs;
private DBvehiclesManager DBvehInfo; private DBvehiclesManager DBvehInfo;
List<string> blackListAddress = new List<string>();
public static volatile Int32 LocationCheckQueuesCount = 0; public static volatile Int32 LocationCheckQueuesCount = 0;
Int64 count = 0; Int64 count = 0;
@ -185,12 +185,12 @@ namespace AppServer
{ {
Vehicle_Data v_data = (Vehicle_Data)MainForm.VehList[radioID2.ToString()]; Vehicle_Data v_data = (Vehicle_Data)MainForm.VehList[radioID2.ToString()];
Alarm alarm = v_data.alm; Alarm alarm = v_data.alm;
bool zone = false;
bool landMark = false;
bool zone = (alarm.Zone != "") ;
bool landMark = (alarm.Landmark != "") ;
String SpeedProccess = ""; String SpeedProccess = "";
if (alarm.Zone != "") zone = true;
if (alarm.Landmark != "") landMark = true;
if (zone || landMark) if (zone || landMark)
{ {
SpeedProccess = processZoneAlarm(radioID2, dec2.cell, zone, landMark, alarm.Email, !prevGps); SpeedProccess = processZoneAlarm(radioID2, dec2.cell, zone, landMark, alarm.Email, !prevGps);
@ -351,7 +351,7 @@ namespace AppServer
string test2 = "#210#1#Can't write GPS data in DB#"; string test2 = "#210#1#Can't write GPS data in DB#";
if (ex.Message == "AlarmError") test2 = "#210#5#Can't write Alarm data in DB#"; if (ex.Message == "AlarmError") test2 = "#210#5#Can't write Alarm data in DB#";
else if (ex.Message == "StolenError") test2 = "#210#6#Can't write Stolen data in DB#"; else if (ex.Message == "StolenError") test2 = "#210#6#Can't write Stolen data in DB#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0" + test2), Utils.Convert_text_For_multicast("#0.0" + test2).Length); MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test2), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test2).Length);
} }
catch (Exception ex2) catch (Exception ex2)
{ {
@ -397,7 +397,7 @@ namespace AppServer
{ {
// send callout clear // send callout clear
string test = "#178#" + callout.RadioID.ToString() + "#" + callout.Severity + "#"; string test = "#178#" + callout.RadioID.ToString() + "#" + callout.Severity + "#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0" + test), Utils.Convert_text_For_multicast("#0.0" + test).Length); MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
Utils.WriteLine($"Sent CallOut Stop request with Severity [{callout.Severity}] for unit {callout.RadioID.ToString()} "); Utils.WriteLine($"Sent CallOut Stop request with Severity [{callout.Severity}] for unit {callout.RadioID.ToString()} ");
} }
} }
@ -409,13 +409,11 @@ namespace AppServer
private void sendMailGeo(string mes, String subj, string mailAdr) private void sendMailGeo(string mes, String subj, string mailAdr)
{ {
if (Program.cfg.enableEmailService) if (Program.cfg.enableEmailService && !String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr))
{ {
if (!String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr)) if (blackListAddress.Contains(mailAdr))
{ {
if (MainForm.IsBlacklistedAddress(mailAdr)) Utils.WriteLine($" sendMailGeo : The email was not sent. Email address '{mailAdr}' is in blacklist ");
{
Utils.WriteLine($"sendMailGeo : The email was not sent. Email address '{mailAdr}' is in blacklist ");
return; return;
} }
@ -443,32 +441,24 @@ namespace AppServer
catch (Exception ex) catch (Exception ex)
{ {
if (ex.ToString().Contains("timed out")) if (ex.ToString().Contains("timed out"))
MainForm.HandleTimeoutError(mailAdr); blackListAddress.Add(mailAdr);
Utils.WriteLine($"Exception in sendMailGeo: {ex.ToString()}"); Utils.WriteLine($"Exception in sendMailGeo: {ex.ToString()}");
} }
} }
else else
{
Utils.WriteLine($"Missing email address From = {Program.cfg.emailAddress} To = {mailAdr})", ConsoleColor.Cyan);
}
}
else
{ {
Utils.WriteLine("Email Server not Set", ConsoleColor.Cyan); Utils.WriteLine("Email Server not Set", ConsoleColor.Cyan);
} }
} }
private void sendAlarmMail(string title, string mes, string mailAdr) private void sendAlarmMail(string title, string mes, string mailAdr)
{ {
if (Program.cfg.enableEmailService) if (Program.cfg.enableEmailService && !String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr))
{
if (!String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr))
{ {
if (MainForm.IsBlacklistedAddress(mailAdr)) if (blackListAddress.Contains(mailAdr))
{ {
Utils.WriteLine($" sendAlarmMail : The email was not sent. Email address '{mailAdr}' is in blacklist "); Utils.WriteLine($" sendAlarmMail : The email was not sent. Email address '{mailAdr}' is in blacklist ");
return; return;
@ -486,17 +476,12 @@ namespace AppServer
catch (Exception ex) catch (Exception ex)
{ {
if (ex.ToString().Contains("timed out")) if (ex.ToString().Contains("timed out"))
MainForm.HandleTimeoutError(mailAdr); blackListAddress.Add(mailAdr);
Utils.WriteLine("Exception in sendMailAlarm2: {0}" + ex.ToString(), ConsoleColor.Red); Utils.WriteLine("Exception in sendMailAlarm2: {0}" + ex.ToString(), ConsoleColor.Red);
} }
} }
else else
{
Utils.WriteLine($"Missing email address From = {Program.cfg.emailAddress} To = {mailAdr})", ConsoleColor.Cyan);
}
}
else
{ {
Utils.WriteLine("Email Server not Set", ConsoleColor.Cyan); Utils.WriteLine("Email Server not Set", ConsoleColor.Cyan);
} }
@ -576,7 +561,7 @@ namespace AppServer
{ {
//send alarm on message buss //send alarm on message buss
test = "#136#" + radioID.ToString() + "#" + tmpresp + "#"; test = "#136#" + radioID.ToString() + "#" + tmpresp + "#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0" + test), Utils.Convert_text_For_multicast("#0.0" + test).Length); MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
} }
String date = DateTime.Now.ToUniversalTime().DateTo70Format().ToString(); String date = DateTime.Now.ToUniversalTime().DateTo70Format().ToString();
@ -604,7 +589,7 @@ namespace AppServer
tmpX = dbvehs.getSystemPosition(Convert.ToInt32(keyobj)); tmpX = dbvehs.getSystemPosition(Convert.ToInt32(keyobj));
test = "#142#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + (String)tmpHashName[keyobj] + "#" + /*"Message from unit " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " :" +*/ obj2.msgbody + "#" + date + "#"; test = "#142#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + (String)tmpHashName[keyobj] + "#" + /*"Message from unit " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " :" +*/ obj2.msgbody + "#" + date + "#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0." + date + test), Utils.Convert_text_For_multicast("#0." + date + test).Length); MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0." + date + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0." + date + test).Length);
Thread.Sleep(100); Thread.Sleep(100);
Utils.WriteLine($"Zone alert sms request [{obj2.msgbody}] for unit {(String)tmpHashName[keyobj]} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]"); Utils.WriteLine($"Zone alert sms request [{obj2.msgbody}] for unit {(String)tmpHashName[keyobj]} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]");
@ -616,7 +601,7 @@ namespace AppServer
{ {
tmpX = dbvehs.getSystemPositionIMEI(radioID); tmpX = dbvehs.getSystemPositionIMEI(radioID);
test = "#142#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + radioID + "#" + obj2.msgbody2 + "#" + DateTime.Now.ToUniversalTime().DateTo70Format().ToString() + "#"; test = "#142#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + radioID + "#" + obj2.msgbody2 + "#" + DateTime.Now.ToUniversalTime().DateTo70Format().ToString() + "#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0." + date + test), Utils.Convert_text_For_multicast("#0." + date + test).Length); MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0." + date + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0." + date + test).Length);
Utils.WriteLine($"Zone alert sms request [{obj2.msgbody2}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]"); Utils.WriteLine($"Zone alert sms request [{obj2.msgbody2}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]");
} }
@ -626,7 +611,7 @@ namespace AppServer
{ {
tmpX = dbvehs.getSystemPositionIMEI(radioID); tmpX = dbvehs.getSystemPositionIMEI(radioID);
test = "#177#" + radioID.ToString() + "#" + obj2.calloutSeverity + "#" + obj2.name + "#"; test = "#177#" + radioID.ToString() + "#" + obj2.calloutSeverity + "#" + obj2.name + "#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0" + test), Utils.Convert_text_For_multicast("#0.0" + test).Length); MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
callOutQueue.PostItem(new CallOut() { RadioID = radioID, Severity = obj2.calloutSeverity, Time = DateTime.Now}); callOutQueue.PostItem(new CallOut() { RadioID = radioID, Severity = obj2.calloutSeverity, Time = DateTime.Now});
Utils.WriteLine($"Zone CallOut request with Severity [{obj2.calloutSeverity}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]"); Utils.WriteLine($"Zone CallOut request with Severity [{obj2.calloutSeverity}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]");
@ -682,14 +667,14 @@ namespace AppServer
{ {
//send alarm on message buss //send alarm on message buss
string test = "#137#" + radioID.ToString() + "#" + tmpresp + "#"; string test = "#137#" + radioID.ToString() + "#" + tmpresp + "#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0" + test), Utils.Convert_text_For_multicast("#0.0" + test).Length); MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
} }
//send CallOut //send CallOut
if(obj2.callout && tmpresp.ToString().Contains("IN ")) if(obj2.callout && tmpresp.ToString().Contains("IN "))
{ {
string test = "#177#" + radioID + "#" + obj2.calloutSeverity + "#" + obj2.name + "#"; string test = "#177#" + radioID + "#" + obj2.calloutSeverity + "#" + obj2.name + "#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0" + test), Utils.Convert_text_For_multicast("#0.0" + test).Length); MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
callOutQueue.PostItem(new CallOut() { RadioID = radioID, Severity = obj2.calloutSeverity, Time = DateTime.Now }); callOutQueue.PostItem(new CallOut() { RadioID = radioID, Severity = obj2.calloutSeverity, Time = DateTime.Now });
Utils.WriteLine($"Landmark CallOut request with Severity [{obj2.calloutSeverity}] for unit {radioID} "); Utils.WriteLine($"Landmark CallOut request with Severity [{obj2.calloutSeverity}] for unit {radioID} ");
@ -758,7 +743,7 @@ namespace AppServer
//send alarm on message buss //send alarm on message buss
string speed4send = $"{speed}_{speedUnits}"; string speed4send = $"{speed}_{speedUnits}";
string test = "#135#" + radioID.ToString() + "#" + speed4send + "#"; string test = "#135#" + radioID.ToString() + "#" + speed4send + "#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0" + test), Utils.Convert_text_For_multicast("#0.0" + test).Length); MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
} }
} }

View File

@ -96,9 +96,6 @@ namespace AppServer
public static String dbAccess; public static String dbAccess;
private WebsocketThread websocket = null; private WebsocketThread websocket = null;
public static Dictionary<string, int> blackListAddress = new Dictionary<string, int>();
public const int MAX_ATTEMPTS = 100;
public delegate void UpdateLicensesUIInvokeCallBack(); public delegate void UpdateLicensesUIInvokeCallBack();
public MainForm() public MainForm()
@ -341,37 +338,6 @@ namespace AppServer
} }
public static void HandleTimeoutError(string mailAdr)
{
// add address to backlist
if (!blackListAddress.ContainsKey(mailAdr))
blackListAddress.Add(mailAdr, MAX_ATTEMPTS);
}
public static bool IsBlacklistedAddress(string mailAdr)
{
if (!blackListAddress.ContainsKey(mailAdr))
return false;
// avoid to send the email MAX_ATTEMPTS times => give another chance to try to send email when count = 0
int count = blackListAddress[mailAdr];
if (count == 0)
{
blackListAddress.Remove(mailAdr);
return false;
}
blackListAddress[mailAdr] = count - 1;
return true;
}
private void ConfigureWebSocket() private void ConfigureWebSocket()
{ {
if (!checkWebsocketServerStatus.Enabled) if (!checkWebsocketServerStatus.Enabled)

View File

@ -28,6 +28,7 @@ namespace AppServer
private DBvehiclesManager dbvehs; private DBvehiclesManager dbvehs;
internal DBsubsOperationManager dbsubsoperManage; internal DBsubsOperationManager dbsubsoperManage;
private DBcallPatchManager dbCallPatch; private DBcallPatchManager dbCallPatch;
private List<string> blackListAddress = new List<string>();
#region code for zone #region code for zone
private volatile static ArrayList ZoneList = new ArrayList(); private volatile static ArrayList ZoneList = new ArrayList();
@ -2150,13 +2151,9 @@ namespace AppServer
} }
private void sendAlarmMail(string mes, string mailAdr) private void sendAlarmMail(string mes, string mailAdr)
{
if (Program.cfg.enableEmailService)
{ {
if (!String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr)) if (blackListAddress.Contains(mailAdr))
{
if (MainForm.IsBlacklistedAddress(mailAdr))
{ {
Utils.WriteLine($" sendAlarmMail : The email was not sent. Email address '{mailAdr}' is in blacklist "); Utils.WriteLine($" sendAlarmMail : The email was not sent. Email address '{mailAdr}' is in blacklist ");
return; return;
@ -2174,22 +2171,13 @@ namespace AppServer
catch (Exception ex) catch (Exception ex)
{ {
if (ex.ToString().Contains("timed out")) if (ex.ToString().Contains("timed out"))
MainForm.HandleTimeoutError(mailAdr); blackListAddress.Add(mailAdr);
Utils.WriteLine("Exception in sendMailAlarm: " + ex.ToString(), ConsoleColor.Red); Utils.WriteLine("Exception in sendMailAlarm: " + ex.ToString(), ConsoleColor.Red);
//Console.WriteLine(e.ToString()); //Console.WriteLine(e.ToString());
} }
} }
else
{
Utils.WriteLine($"Missing email address From = {Program.cfg.emailAddress} To = {mailAdr})", ConsoleColor.Red);
}
}
else
{
SM.Debug("email disabled");
}
}
public void sendDailyReportMail(String PdfFile, string mailAdr) public void sendDailyReportMail(String PdfFile, string mailAdr)
@ -2374,16 +2362,6 @@ namespace AppServer
{ {
if (Program.cfg.enableEmailService) if (Program.cfg.enableEmailService)
{ {
if (!String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr))
{
if (MainForm.IsBlacklistedAddress(mailAdr))
{
Utils.WriteLine($"sendMailGeo : The email was not sent. Email address '{mailAdr}' is in blacklist ");
return;
}
SM.Debug("Sending mail to " + mailAdr + " from radioId " + radioID.ToString()); SM.Debug("Sending mail to " + mailAdr + " from radioId " + radioID.ToString());
try try
{ {
@ -2401,18 +2379,10 @@ namespace AppServer
} }
catch (Exception ex) catch (Exception ex)
{ {
if (ex.ToString().Contains("timed out"))
MainForm.HandleTimeoutError(mailAdr);
Utils.WriteLine("Exception in sendMail: " + ex.ToString(), ConsoleColor.Red); Utils.WriteLine("Exception in sendMail: " + ex.ToString(), ConsoleColor.Red);
} }
} }
else else
{
Utils.WriteLine($"Missing email address From = {Program.cfg.emailAddress} To = {mailAdr})", ConsoleColor.Red);
}
}
else
{ {
SM.Debug("email disabled"); SM.Debug("email disabled");
} }
@ -2422,19 +2392,7 @@ namespace AppServer
//sms-> email Sierra Wireless //sms-> email Sierra Wireless
private void sendMail_SW(string mailAdr, string mailBody) private void sendMail_SW(string mailAdr, string mailBody)
{ {
if (Program.cfg.enableEmailService)
{
if (!String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr))
{
if (MainForm.IsBlacklistedAddress(mailAdr))
{
Utils.WriteLine($"sendMailGeo : The email was not sent. Email address '{mailAdr}' is in blacklist ");
return;
}
SM.Debug("Sending mail to " + mailAdr); SM.Debug("Sending mail to " + mailAdr);
try try
{ {
MailMessage message = new MailMessage(); MailMessage message = new MailMessage();
@ -2447,20 +2405,7 @@ namespace AppServer
} }
catch (Exception ex) catch (Exception ex)
{ {
if (ex.ToString().Contains("timed out")) Utils.WriteLine("Exception in sendMail Sierra Wireless Gateway: "+ ex.ToString() ,ConsoleColor.Red);
MainForm.HandleTimeoutError(mailAdr);
Utils.WriteLine("Exception in sendMail Sierra Wireless Gateway: " + ex.ToString(), ConsoleColor.Red);
}
}
else
{
Utils.WriteLine($"Missing email address From = {Program.cfg.emailAddress} To = {mailAdr})", ConsoleColor.Red);
}
}
else
{
SM.Debug("email disabled");
} }
} }