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 a67b7cc0cd - Show all commits

View File

@ -123,7 +123,7 @@ namespace AppServer
while (line != default(string)) while (line != default(string))
{ {
BeforeWriteDB = true; BeforeWriteDB = true;
string[] tempArr = line.Split('#'); string[] tempArr = line.Split("#".ToCharArray());
//imei //imei
try try
{ {
@ -200,7 +200,7 @@ namespace AppServer
if (SpeedProccess != "") if (SpeedProccess != "")
{ {
string[] temp = SpeedProccess.Split('_'); string[] temp = SpeedProccess.Split("_".ToCharArray());
int speedT = (int)Convert.ToDouble(temp[0]); int speedT = (int)Convert.ToDouble(temp[0]);
string speedU = temp[1]; string speedU = temp[1];
processSpeedAlarm(radioID2, dec2.cell, speedT, speedU, alarm.Email, !prevGps); processSpeedAlarm(radioID2, dec2.cell, speedT, speedU, alarm.Email, !prevGps);
@ -288,37 +288,40 @@ namespace AppServer
//Calculate status //Calculate status
if (MainForm.VehicleHashStat.ContainsKey(radioID2.ToString()) && !prevGps) if (MainForm.VehicleHashStat.ContainsKey(radioID2.ToString()) && !prevGps)
{ {
VehicleStatus vehicleStatus = (VehicleStatus)MainForm.VehicleHashStat[radioID2];
//MADE ON status when is the case //MADE ON status when is the case
if ((((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus == Status_for_tab.MADEOFF) if ((vehicleStatus.curentStatus == Status_for_tab.MADEOFF)
|| (((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus == Status_for_tab.OFF)) || (vehicleStatus.curentStatus == Status_for_tab.OFF))
{ {
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus = Status_for_tab.MADEON; vehicleStatus.curentStatus = Status_for_tab.MADEON;
PushStatus(radioID2, Status_for_tab.MADEON); PushStatus(radioID2, Status_for_tab.MADEON);
} }
// update last status location and position time // update last status location and position time
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).lastPositionTime = DateTime.Now; vehicleStatus.lastPositionTime = DateTime.Now;
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).lat = dec2.cell.d_lat; vehicleStatus.lat = dec2.cell.d_lat;
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).lng = dec2.cell.d_lng; vehicleStatus.lng = dec2.cell.d_lng;
// do not push any status update if the current status is emergency // do not push any status update if the current status is emergency
if (((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus != Status_for_tab.EMERG) if (vehicleStatus.curentStatus != Status_for_tab.EMERG)
{ {
if (dec2.cell.lat != "0" && dec2.cell.lat != "0.00000") if (dec2.cell.lat != "0" && dec2.cell.lat != "0.00000")
{ {
if (((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus != Status_for_tab.GPS_ON) if (vehicleStatus.curentStatus != Status_for_tab.GPS_ON)
{ {
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus = Status_for_tab.GPS_ON; vehicleStatus.curentStatus = Status_for_tab.GPS_ON;
//SM.Debug("Push Status GPS ON for radio:"+radioID2); //SM.Debug("Push Status GPS ON for radio:"+radioID2);
PushStatus(radioID2, Status_for_tab.GPS_ON); PushStatus(radioID2, Status_for_tab.GPS_ON);
} }
} }
else else
{ {
if (((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus != Status_for_tab.NOGPSFIX) if (vehicleStatus.curentStatus != Status_for_tab.NOGPSFIX)
{ {
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus = Status_for_tab.NOGPSFIX; vehicleStatus.curentStatus = Status_for_tab.NOGPSFIX;
PushStatus(radioID2, Status_for_tab.NOGPSFIX); PushStatus(radioID2, Status_for_tab.NOGPSFIX);
} }
} }
@ -407,7 +410,7 @@ namespace AppServer
try try
{ {
MailAddress from = new MailAddress(Program.cfg.emailAddress); MailAddress from = new MailAddress(Program.cfg.emailAddress);
String[] address = mailAdr.Split(';'); String[] address = mailAdr.Split(";".ToCharArray());
MailAddress to = new MailAddress(address[0]); MailAddress to = new MailAddress(address[0]);
MailMessage message = new MailMessage(from, to); MailMessage message = new MailMessage(from, to);
if (address.Count() > 1) if (address.Count() > 1)
@ -497,42 +500,29 @@ namespace AppServer
else if ((obj2.AlarmType == 1) && (position == 2)) validAlarm = true; else if ((obj2.AlarmType == 1) && (position == 2)) validAlarm = true;
else if ((obj2.AlarmType == 2) && (position == 1)) validAlarm = true; else if ((obj2.AlarmType == 2) && (position == 1)) validAlarm = true;
else if (obj2.AlarmType == 4) validAlarm = false; else if (obj2.AlarmType == 4) validAlarm = false;
if (validAlarm) if (validAlarm)
{ {
Utils.WriteLine("Add new zone alarm"); Utils.WriteLine("Add new zone alarm");
DBalarm.Insert_Zone_Alarm(((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id, time, obj2.zone_id, obj2.action, true); DBalarm.Insert_Zone_Alarm(((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id, time, obj2.zone_id, obj2.action, true);
Utils.WriteLine("Done Add new zone alarm"); Utils.WriteLine("Done Add new zone alarm");
if (obj2.speedUnit.Equals("k"))
string speed_km_or_mph = obj2.speedUnit.Equals("k") ? $"{speed} km/h" : $"{speedMiles} mph";
string message = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp
+ $". Unit speed {speed_km_or_mph} at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "")
{ {
string message = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp Task.Factory.StartNew(() =>
+ ". Unit speed " + speed + " km/h at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "")
{ {
Task.Factory.StartNew(() => sendAlarmMail(title, message, mailAdr);
{ });
sendAlarmMail(title, message, mailAdr);
});
}
}
else
{
string message = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp
+ ". Unit speed " + speedMiles + " mph at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "")
{
Task.Factory.StartNew(() =>
{
sendAlarmMail(title, message, mailAdr);
});
}
} }
String test = ""; String test = "";
if (sendOnMsgBus) if (sendOnMsgBus)
@ -548,14 +538,15 @@ namespace AppServer
{ {
String listOfUnits = obj2.unitids; String listOfUnits = obj2.unitids;
String listOfImeis = obj2.imeilist; String listOfImeis = obj2.imeilist;
String[] tmpunits = listOfUnits.Split(','); String[] tmpunits = listOfUnits.Split(",".ToCharArray());
String[] tmpimeis = listOfImeis.Split(','); String[] tmpimeis = listOfImeis.Split(",".ToCharArray());
Hashtable tmpHashName = new Hashtable(); Hashtable tmpHashName = new Hashtable();
if (tmpunits.Count() > 1) if (tmpunits.Count() > 1)
{ {
for (Int32 i = 0; i < tmpunits.Count() - 1; i++) for (Int32 i = 0; i < tmpunits.Count() - 1; i++)
tmpHashName.Add((String)tmpunits[i], (String)tmpimeis[i]); tmpHashName.Add((String)tmpunits[i], (String)tmpimeis[i]);
} }
foreach (String keyobj in tmpHashName.Keys) foreach (String keyobj in tmpHashName.Keys)
{ {
int obj = -1; int obj = -1;
@ -572,6 +563,7 @@ namespace AppServer
} }
} }
} }
if (obj2.sentmsg2 && sendOnMsgBus) if (obj2.sentmsg2 && sendOnMsgBus)
{ {
tmpX = dbvehs.getSystemPositionIMEI(radioID); tmpX = dbvehs.getSystemPositionIMEI(radioID);
@ -580,6 +572,7 @@ namespace AppServer
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)}]");
} }
//send Callout //send Callout
if(obj2.callout && tmpresp.ToString().Contains("IN ")) if(obj2.callout && tmpresp.ToString().Contains("IN "))
{ {
@ -590,6 +583,7 @@ namespace AppServer
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)}]");
} }
///send email ///send email
if (obj2.sentemail) if (obj2.sentemail)
{ {
@ -613,32 +607,21 @@ namespace AppServer
{ {
Utils.WriteLine("Insert Landmarks Alarm " + radioID.ToString() + " " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id); Utils.WriteLine("Insert Landmarks Alarm " + radioID.ToString() + " " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id);
DBalarm.Insert_Zone_Alarm(((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id, time, obj2.land_id, obj2.action, false); DBalarm.Insert_Zone_Alarm(((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id, time, obj2.land_id, obj2.action, false);
if (obj2.speedUnit.Equals("k"))
string speed_km_or_mph = obj2.speedUnit.Equals("k") ? $"{speed} km/h" : $"{speedMiles} mph";
string message = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp
+ $". Unit speed {speed_km_or_mph} at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "")
{ {
string message = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp Task.Factory.StartNew(() =>
+ ". Unit speed " + speed + " km/h at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "")
{ {
Task.Factory.StartNew(() => sendAlarmMail(title, message, mailAdr);
{ });
sendAlarmMail(title, message, mailAdr);
});
}
}
else
{
string message = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp
+ ". Unit speed " + speedMiles + " mph at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "")
{
Task.Factory.StartNew(() =>
{
sendAlarmMail(title, message, mailAdr);
});
}
} }
if (sendOnMsgBus) if (sendOnMsgBus)
{ {
@ -694,6 +677,7 @@ namespace AppServer
Utils.WriteLine("Speed alarm detected!"); Utils.WriteLine("Speed alarm detected!");
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 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/h 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;
@ -720,6 +704,7 @@ namespace AppServer
DBalarm.Insert_Speed_Alarm(radioID, time, speed, cell.lat, cell.lng); DBalarm.Insert_Speed_Alarm(radioID, time, speed, cell.lat, cell.lng);
String speedMiles = Convert.ToString((int)Math.Round(speed * 0.621371192)); String speedMiles = Convert.ToString((int)Math.Round(speed * 0.621371192));
SM.Debug("Speed alarm generated!"); SM.Debug("Speed alarm generated!");
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 " + speedMiles + " mph at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]"; + ". 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; string title = "Speed alarm for unit " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;