refactor_AppServer_LocationThread
This commit is contained in:
parent
a67b7cc0cd
commit
0be7970c63
@ -418,8 +418,10 @@ namespace AppServer
|
|||||||
Boolean skipeFirst = true;
|
Boolean skipeFirst = true;
|
||||||
foreach (String obj in address)
|
foreach (String obj in address)
|
||||||
{
|
{
|
||||||
if (skipeFirst) { skipeFirst = false; }
|
if (skipeFirst)
|
||||||
else message.To.Add(new MailAddress(obj));
|
{ skipeFirst = false; }
|
||||||
|
else
|
||||||
|
message.To.Add(new MailAddress(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
message.Subject = subj;
|
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);
|
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 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);
|
uint time = DateTo70Format(cell.location_time);
|
||||||
string speed4send = speed.ToString() + "_" + speedUnits;
|
string speed4send = speed.ToString() + "_" + speedUnits;
|
||||||
|
|
||||||
|
|
||||||
|
int treshold = (int)Convert.ToDouble(speedTreshold);
|
||||||
|
if (speedUnits == "m")
|
||||||
|
treshold = (int)(treshold * 1.609);
|
||||||
|
|
||||||
if (speedUnits != "m")
|
if (speedUnits != "m")
|
||||||
{
|
{
|
||||||
if (speed >= treshold)
|
if (speed >= treshold)
|
||||||
@ -678,8 +687,10 @@ namespace AppServer
|
|||||||
DBalarm.Insert_Speed_Alarm(radioID, time, speed,cell.lat,cell.lng);
|
DBalarm.Insert_Speed_Alarm(radioID, time, speed,cell.lat,cell.lng);
|
||||||
Utils.WriteLine("Done inserting speed alarm!");
|
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
|
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;
|
string title = "Speed alarm for unit " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
|
||||||
if (mailAdr != "")
|
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
|
#endregion
|
||||||
|
Loading…
Reference in New Issue
Block a user