refactor_AppServer_LocationThread #3

Merged
laurentiu.constantin merged 2 commits from refactor_AppServer_LocationThread into master 2024-06-06 10:43:16 +00:00
Showing only changes of commit 0be7970c63 - Show all commits

View File

@ -418,8 +418,10 @@ namespace AppServer
Boolean skipeFirst = true;
foreach (String obj in address)
{
if (skipeFirst) { skipeFirst = false; }
else message.To.Add(new MailAddress(obj));
if (skipeFirst)
{ skipeFirst = false; }
else
message.To.Add(new MailAddress(obj));
}
}
message.Subject = subj;
@ -666,10 +668,17 @@ namespace AppServer
DBalarmManager DBalarm = new DBalarmManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
int speed = (int)Convert.ToDouble(cell.spd);
int treshold = (int)Convert.ToDouble(speedTreshold);
int speedMiles = (int)Math.Round(speed * 0.621371192);
uint time = DateTo70Format(cell.location_time);
string speed4send = speed.ToString() + "_" + speedUnits;
int treshold = (int)Convert.ToDouble(speedTreshold);
if (speedUnits == "m")
treshold = (int)(treshold * 1.609);
if (speedUnits != "m")
{
if (speed >= treshold)
@ -678,8 +687,10 @@ namespace AppServer
DBalarm.Insert_Speed_Alarm(radioID, time, speed,cell.lat,cell.lng);
Utils.WriteLine("Done inserting speed alarm!");
string speed_km_or_mph = (speedUnits != "m") ? $"{speed} km/h" : $"{speedMiles} mph";
string message = "Speed alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name
+ ". Unit speed " + speed + " km/h at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
+ $". Unit speed {speed_km_or_mph} at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Speed alarm for unit " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "")
{
@ -697,33 +708,6 @@ namespace AppServer
}
}
}
else
{
if (speed >= (treshold * 1.609))
{
DBalarm.Insert_Speed_Alarm(radioID, time, speed, cell.lat, cell.lng);
String speedMiles = Convert.ToString((int)Math.Round(speed * 0.621371192));
SM.Debug("Speed alarm generated!");
string message = "Speed alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name
+ ". Unit speed " + speedMiles + " mph at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Speed alarm for unit " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "Speed alarm")
{
Task.Factory.StartNew(() =>
{
sendAlarmMail(title, message, mailAdr);
});
}
if (sendOnMsgBus)
{
//send alarm on message buss
string test = "#135#" + radioID.ToString() + "#" + speed4send + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
}
}
}
}
#endregion