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 DBvehiclesManager dbvehs;
private DBvehiclesManager DBvehInfo;
List<string> blackListAddress = new List<string>();
public static volatile Int32 LocationCheckQueuesCount = 0;
Int64 count = 0;
@ -185,12 +185,12 @@ namespace AppServer
{
Vehicle_Data v_data = (Vehicle_Data)MainForm.VehList[radioID2.ToString()];
Alarm alarm = v_data.alm;
bool zone = (alarm.Zone != "") ;
bool landMark = (alarm.Landmark != "") ;
bool zone = false;
bool landMark = false;
String SpeedProccess = "";
if (alarm.Zone != "") zone = true;
if (alarm.Landmark != "") landMark = true;
if (zone || landMark)
{
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#";
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#";
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)
{
@ -397,7 +397,7 @@ namespace AppServer
{
// send callout clear
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()} ");
}
}
@ -409,13 +409,11 @@ namespace AppServer
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;
}
@ -443,32 +441,24 @@ namespace AppServer
catch (Exception ex)
{
if (ex.ToString().Contains("timed out"))
MainForm.HandleTimeoutError(mailAdr);
blackListAddress.Add(mailAdr);
Utils.WriteLine($"Exception in sendMailGeo: {ex.ToString()}");
}
}
else
{
Utils.WriteLine($"Missing email address From = {Program.cfg.emailAddress} To = {mailAdr})", ConsoleColor.Cyan);
}
}
else
{
Utils.WriteLine("Email Server not Set", ConsoleColor.Cyan);
}
}
private void sendAlarmMail(string title, string mes, string mailAdr)
{
if (Program.cfg.enableEmailService)
{
if (!String.IsNullOrEmpty(Program.cfg.emailAddress) && !String.IsNullOrEmpty(mailAdr))
if (Program.cfg.enableEmailService && !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 ");
return;
@ -486,17 +476,12 @@ namespace AppServer
catch (Exception ex)
{
if (ex.ToString().Contains("timed out"))
MainForm.HandleTimeoutError(mailAdr);
blackListAddress.Add(mailAdr);
Utils.WriteLine("Exception in sendMailAlarm2: {0}" + ex.ToString(), ConsoleColor.Red);
}
}
else
{
Utils.WriteLine($"Missing email address From = {Program.cfg.emailAddress} To = {mailAdr})", ConsoleColor.Cyan);
}
}
else
{
Utils.WriteLine("Email Server not Set", ConsoleColor.Cyan);
}
@ -576,7 +561,7 @@ namespace AppServer
{
//send alarm on message buss
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();
@ -604,7 +589,7 @@ namespace AppServer
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 + "#";
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);
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);
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)}]");
}
@ -626,7 +611,7 @@ namespace AppServer
{
tmpX = dbvehs.getSystemPositionIMEI(radioID);
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});
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
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
if(obj2.callout && tmpresp.ToString().Contains("IN "))
{
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 });
Utils.WriteLine($"Landmark CallOut request with Severity [{obj2.calloutSeverity}] for unit {radioID} ");
@ -758,7 +743,7 @@ namespace AppServer
//send alarm on message buss
string speed4send = $"{speed}_{speedUnits}";
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;
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 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()
{
if (!checkWebsocketServerStatus.Enabled)

View File

@ -28,6 +28,7 @@ namespace AppServer
private DBvehiclesManager dbvehs;
internal DBsubsOperationManager dbsubsoperManage;
private DBcallPatchManager dbCallPatch;
private List<string> blackListAddress = new List<string>();
#region code for zone
private volatile static ArrayList ZoneList = new ArrayList();
@ -2150,13 +2151,9 @@ namespace AppServer
}
private void sendAlarmMail(string mes, string mailAdr)
{
if (Program.cfg.enableEmailService)
{
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 ");
return;
@ -2174,22 +2171,13 @@ namespace AppServer
catch (Exception ex)
{
if (ex.ToString().Contains("timed out"))
MainForm.HandleTimeoutError(mailAdr);
blackListAddress.Add(mailAdr);
Utils.WriteLine("Exception in sendMailAlarm: " + ex.ToString(), ConsoleColor.Red);
//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)
@ -2374,16 +2362,6 @@ namespace AppServer
{
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());
try
{
@ -2401,18 +2379,10 @@ namespace AppServer
}
catch (Exception ex)
{
if (ex.ToString().Contains("timed out"))
MainForm.HandleTimeoutError(mailAdr);
Utils.WriteLine("Exception in sendMail: " + ex.ToString(), ConsoleColor.Red);
}
}
else
{
Utils.WriteLine($"Missing email address From = {Program.cfg.emailAddress} To = {mailAdr})", ConsoleColor.Red);
}
}
else
{
SM.Debug("email disabled");
}
@ -2422,19 +2392,7 @@ namespace AppServer
//sms-> email Sierra Wireless
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);
try
{
MailMessage message = new MailMessage();
@ -2447,20 +2405,7 @@ namespace AppServer
}
catch (Exception ex)
{
if (ex.ToString().Contains("timed out"))
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");
Utils.WriteLine("Exception in sendMail Sierra Wireless Gateway: "+ ex.ToString() ,ConsoleColor.Red);
}
}