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))
{
BeforeWriteDB = true;
string[] tempArr = line.Split('#');
string[] tempArr = line.Split("#".ToCharArray());
//imei
try
{
@ -200,7 +200,7 @@ namespace AppServer
if (SpeedProccess != "")
{
string[] temp = SpeedProccess.Split('_');
string[] temp = SpeedProccess.Split("_".ToCharArray());
int speedT = (int)Convert.ToDouble(temp[0]);
string speedU = temp[1];
processSpeedAlarm(radioID2, dec2.cell, speedT, speedU, alarm.Email, !prevGps);
@ -288,37 +288,40 @@ namespace AppServer
//Calculate status
if (MainForm.VehicleHashStat.ContainsKey(radioID2.ToString()) && !prevGps)
{
VehicleStatus vehicleStatus = (VehicleStatus)MainForm.VehicleHashStat[radioID2];
//MADE ON status when is the case
if ((((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus == Status_for_tab.MADEOFF)
|| (((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus == Status_for_tab.OFF))
if ((vehicleStatus.curentStatus == Status_for_tab.MADEOFF)
|| (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);
}
// update last status location and position time
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).lastPositionTime = DateTime.Now;
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).lat = dec2.cell.d_lat;
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).lng = dec2.cell.d_lng;
vehicleStatus.lastPositionTime = DateTime.Now;
vehicleStatus.lat = dec2.cell.d_lat;
vehicleStatus.lng = dec2.cell.d_lng;
// 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 (((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);
PushStatus(radioID2, Status_for_tab.GPS_ON);
}
}
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);
}
}
@ -407,7 +410,7 @@ namespace AppServer
try
{
MailAddress from = new MailAddress(Program.cfg.emailAddress);
String[] address = mailAdr.Split(';');
String[] address = mailAdr.Split(";".ToCharArray());
MailAddress to = new MailAddress(address[0]);
MailMessage message = new MailMessage(from, to);
if (address.Count() > 1)
@ -497,42 +500,29 @@ namespace AppServer
else if ((obj2.AlarmType == 1) && (position == 2)) validAlarm = true;
else if ((obj2.AlarmType == 2) && (position == 1)) validAlarm = true;
else if (obj2.AlarmType == 4) validAlarm = false;
if (validAlarm)
{
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);
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
+ ". 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(() =>
{
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 = "";
if (sendOnMsgBus)
@ -548,14 +538,15 @@ namespace AppServer
{
String listOfUnits = obj2.unitids;
String listOfImeis = obj2.imeilist;
String[] tmpunits = listOfUnits.Split(',');
String[] tmpimeis = listOfImeis.Split(',');
String[] tmpunits = listOfUnits.Split(",".ToCharArray());
String[] tmpimeis = listOfImeis.Split(",".ToCharArray());
Hashtable tmpHashName = new Hashtable();
if (tmpunits.Count() > 1)
{
for (Int32 i = 0; i < tmpunits.Count() - 1; i++)
tmpHashName.Add((String)tmpunits[i], (String)tmpimeis[i]);
}
foreach (String keyobj in tmpHashName.Keys)
{
int obj = -1;
@ -572,6 +563,7 @@ namespace AppServer
}
}
}
if (obj2.sentmsg2 && sendOnMsgBus)
{
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)}]");
}
//send Callout
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});
Utils.WriteLine($"Zone CallOut request with Severity [{obj2.calloutSeverity}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]");
}
///send email
if (obj2.sentemail)
{
@ -613,33 +607,22 @@ namespace AppServer
{
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);
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
+ ". 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(() =>
{
Task.Factory.StartNew(() =>
{
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);
});
}
sendAlarmMail(title, message, mailAdr);
});
}
if (sendOnMsgBus)
{
//send alarm on message buss
@ -694,6 +677,7 @@ namespace AppServer
Utils.WriteLine("Speed alarm detected!");
DBalarm.Insert_Speed_Alarm(radioID, time, speed,cell.lat,cell.lng);
Utils.WriteLine("Done inserting speed alarm!");
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 + "]";
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);
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;