Compare commits

...

15 Commits

Author SHA1 Message Date
74fa47daa6 Merge pull request 'add_scripts_for_messages_partitioning' (#15) from add_scripts_for_messages_partitiong into master
Reviewed-on: #15
2024-07-05 15:40:32 +00:00
93bfc46d85 add_scripts_for_messages_partitioning 2024-07-05 18:39:46 +03:00
16647ca6c4 Merge pull request 'fix_BatchHistory_report' (#14) from fix_BatchHistory_report into master
Reviewed-on: #14
2024-07-05 15:37:56 +00:00
f70027424c fix_BatchHistory_report 2024-07-05 18:37:18 +03:00
8e1e233826 Merge pull request 'fix Format command twice to get its length' (#13) from refactor_code3 into master
Reviewed-on: #13
2024-07-01 14:39:43 +00:00
df1dc2bf15 fix Format command twice to get its length 2024-07-01 17:39:01 +03:00
7bb4a6dc66 Merge pull request 'refactor code' (#12) from refactor_code2 into master
Reviewed-on: #12
2024-06-27 10:18:13 +00:00
2e5267b6f7 refactor code 2024-06-27 13:17:09 +03:00
6273746693 Merge pull request 'pop server could not connect => add it to black list' (#11) from blacklist_popServer into master
Reviewed-on: #11
2024-06-25 11:01:33 +00:00
377c21c338 pop server could not connect => add it to black list 2024-06-25 14:00:32 +03:00
65a08de6d8 Merge pull request 'give_one_more_chance_to_send_email' (#10) from give_one_more_chance_to_send_email into master
Reviewed-on: #10
2024-06-21 13:27:50 +00:00
44e89bfb87 give_one_more_chance_to_send_email 2024-06-21 16:27:20 +03:00
ccaa256960 Merge pull request 'refactor code' (#9) from refactor_code1 into master
Reviewed-on: #9
2024-06-20 16:05:21 +00:00
126aba5ee5 refactor code 2024-06-20 19:03:35 +03:00
5291e2cb5b Merge pull request 'take gateway from localhost' (#8) from fix_Take_gateway_from_localhost into master
Reviewed-on: #8
2024-06-17 14:59:12 +00:00
14 changed files with 436 additions and 263 deletions

View File

@ -262,6 +262,7 @@ namespace AppServer
{
continue;
}
//get unit system position
int unitSC_ID = ((Vehicle_Data)MainForm.VehList[radioID2]).sc_id;
UnitSysPosition sysPos = DBvehInfo.getSystemPosition(unitSC_ID);
@ -271,7 +272,8 @@ namespace AppServer
//send radio disable to GW
Utils.WriteLine("Radio disable was sent on " + sysPos.Gw_id + "." + sysPos.R_gw_id + " gateway", ConsoleColor.Cyan);
string test2 = $"#{(int)MessageBusCmds.RadioEnableDisableRequest}#" + dest + "#0#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0" + test2), Utils.Convert_text_For_multicast("#0.0" + test2).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + test2);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
catch (Exception ex)
{
@ -349,9 +351,13 @@ namespace AppServer
try
{
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);
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#";
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + test2);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
catch (Exception ex2)
{
@ -397,7 +403,10 @@ 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);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
Utils.WriteLine($"Sent CallOut Stop request with Severity [{callout.Severity}] for unit {callout.RadioID.ToString()} ");
}
}
@ -415,7 +424,7 @@ namespace AppServer
{
if (MainForm.IsBlacklistedAddress(mailAdr))
{
Utils.WriteLine($"sendMailGeo : The email was not sent. Email address '{mailAdr}' is in blacklist ");
Utils.WriteLine($"sendMailGeo : The email '{subj}' was not sent. Email address '{mailAdr}' is in blacklist count = {MainForm.blackListAddress[mailAdr]}");
return;
}
@ -442,7 +451,8 @@ namespace AppServer
}
catch (Exception ex)
{
if (ex.ToString().Contains("timed out"))
if (ex.ToString().Contains("timed out") ||
ex.ToString().Contains("the client was not authenticated"))
MainForm.HandleTimeoutError(mailAdr);
Utils.WriteLine($"Exception in sendMailGeo: {ex.ToString()}");
@ -470,7 +480,7 @@ namespace AppServer
if (MainForm.IsBlacklistedAddress(mailAdr))
{
Utils.WriteLine($" sendAlarmMail : The email was not sent. Email address '{mailAdr}' is in blacklist ");
Utils.WriteLine($" sendAlarmMail : The email '{title}' was not sent. Email address '{mailAdr}' is in blacklist count = {MainForm.blackListAddress[mailAdr]}");
return;
}
@ -485,7 +495,8 @@ namespace AppServer
}
catch (Exception ex)
{
if (ex.ToString().Contains("timed out"))
if ( ex.ToString().Contains("timed out") ||
ex.ToString().Contains("the client was not authenticated"))
MainForm.HandleTimeoutError(mailAdr);
Utils.WriteLine("Exception in sendMailAlarm2: {0}" + ex.ToString(), ConsoleColor.Red);
@ -576,7 +587,8 @@ 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);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
String date = DateTime.Now.ToUniversalTime().DateTo70Format().ToString();
@ -604,7 +616,10 @@ 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);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0." + date + test);
MainForm.udp.Send(dataToSend, dataToSend.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 +631,8 @@ 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);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0." + date + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
Utils.WriteLine($"Zone alert sms request [{obj2.msgbody2}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]");
}
@ -626,7 +642,8 @@ 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);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0." + test);
MainForm.udp.Send(dataToSend, dataToSend.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 +699,16 @@ 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);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + test);
MainForm.udp.Send(dataToSend, dataToSend.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);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + test);
MainForm.udp.Send(dataToSend, dataToSend.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,6 +777,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);
}
}

View File

@ -1058,7 +1058,8 @@ namespace AppServer
{
try
{
udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#4#AppServer stoped#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#4#AppServer stoped#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#210#4#AppServer stoped#");
udp.Send(dataToSend, dataToSend.Length);
}
catch (Exception ex2)
{
@ -1106,7 +1107,8 @@ namespace AppServer
error = true;
try
{
udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#2#Dongle missing Application server stopped#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#2#Dongle missing Application server stopped#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#210#2#Dongle missing Application server stopped#");
udp.Send(dataToSend, dataToSend.Length);
}
catch (Exception ex2)
{
@ -1226,8 +1228,10 @@ namespace AppServer
MainForm.websocketLocationQueue.PostItem(data);
if(!sendWebsocketTimer.Enabled)
if (!sendWebsocketTimer.Enabled)
sendWebsocketTimer.Enabled = true;
if (!checkWebsocketServerStatus.Enabled)
checkWebsocketServerStatus.Enabled = true;
}
@ -1279,10 +1283,12 @@ namespace AppServer
}
try
{
udp.Send(Utils.Convert_text_For_multicast($"#0.0#{Utils.enumConvertToString(MessageBusCmds.WebsocketStatusToMsgBus)}#offline#"),
Utils.Convert_text_For_multicast($"#0.0#{Utils.enumConvertToString(MessageBusCmds.WebsocketStatusToMsgBus)}#offline#").Length);
udp.Send(Utils.Convert_text_For_multicast("#0.0#210#4#Application server stopped#"),
Utils.Convert_text_For_multicast("#0.0#210#4#Application server stopped#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast($"#0.0#{Utils.enumConvertToString(MessageBusCmds.WebsocketStatusToMsgBus)}#offline#");
udp.Send(dataToSend, dataToSend.Length);
dataToSend = Utils.Convert_text_For_multicast("#0.0#210#4#Application server stopped#");
udp.Send(dataToSend, dataToSend.Length);
}
catch (Exception ex2)
{
@ -1298,7 +1304,8 @@ namespace AppServer
{
try
{
udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#5#Application server restart#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#5#Application server restart#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#210#5#Application server restart#");
udp.Send(dataToSend, dataToSend.Length);
}
catch (Exception ex2)
{

View File

@ -606,7 +606,8 @@ namespace AppServer
Utils.WriteLine("Radio disable was sent on " + sysPos.Gw_id + "." + sysPos.R_gw_id + " gateway", ConsoleColor.Cyan);
//send radio disable to GW
string test2 = "#150#" + dest + "#0#";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0" + test2), Utils.Convert_text_For_multicast("#0.0" + test2).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + test2);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
catch (Exception ex)
{
@ -727,7 +728,9 @@ namespace AppServer
UnitSysPosition sysPos = DBvehInfo.getSystemPosition(unitSC_ID);
string message = string.Format("Ticket no. {0} is no longer active!", dec3.delete_ticket_id);
string test1 = "#143#" + sysPos.Gw_id + "." + sysPos.R_gw_id + "." + radioID3 + "#" + message + "#" + 0 + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0"+test1), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0"+test1).Length);
byte[] cmd = Utils.Convert_text_For_multicast("#0.0" + test1);
MainForm.udp.Send(cmd, cmd.Length);
}
//send to email if was sms->email type
if (dec3.isEmail)
@ -735,12 +738,11 @@ namespace AppServer
sendMail(dec3.emailAddr, dec3.messBody, radioID3);
}
//send ACK back to GW
test = "";
if (dec3.sqlResp == sqlResponse.done)
test = "#232#1#";
else
test = "#232#0#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + seqID3 + test), SafeMobileLib.Utils.Convert_text_For_multicast("#" + seqID3 + test).Length);
test = (dec3.sqlResp == sqlResponse.done) ? "#232#1#" : "#232#0#";
byte[] dataToSend = Utils.Convert_text_For_multicast("#" + seqID3 + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
if (MainForm.SendPOLLafterSMS)
{
@ -750,7 +752,8 @@ namespace AppServer
string dest = $"0.0.{radioID3}";
if (sysPos != null) dest = $"{sysPos.Gw_id}.{sysPos.R_gw_id}.{radioID3}";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#154#" + dest + "#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#154#" + dest + "#").Length);
dataToSend = Utils.Convert_text_For_multicast("#0.0#154#" + dest + "#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
catch (Exception ex)
@ -928,7 +931,9 @@ namespace AppServer
System.Threading.Thread.Sleep(100);
SM.Debug("Sending telemetry alarm to SD; digital:" + tObj.DigitalNr);
test = $"#140#{radioID}#{tObj.Name}#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0"+test).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
else
{
@ -939,7 +944,8 @@ namespace AppServer
}
if (IhaveData)
{
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#154#" + dest + "#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#154#" + dest + "#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#154#" + dest + "#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
catch (Exception ex)
@ -1033,7 +1039,8 @@ namespace AppServer
bgWorkerDBbackup.RunWorkerAsync(param);
//send ACK back to SUM
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#71#1#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#71#1#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#71#1#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
catch (Exception ex)
{
@ -1061,12 +1068,14 @@ namespace AppServer
object[] param2 = { completeFileName, posgresPath };
bgWorkerDBrestore.RunWorkerAsync(param2);
//send ACK back to SUM
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#72#1#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#72#1#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#72#1#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
else
{
SM.Debug("DB restored failed !!!" + "File " + completeFileName + " missing!!!");
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#62#0#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#62#0#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#62#0#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
catch (Exception ex)
@ -1138,7 +1147,9 @@ namespace AppServer
//send broadcast messages I'm back in business
Utils.WriteLine(string.Format("receive 500 from radio: Gateway {0} is ON", ((RadioGateway)MainForm.RadioGWHash[key]).Name), ConsoleColor.Green);
string test1 = "#501#" + tempArr[4] + "#" + tempArr[5] + "#" + "ON#" + ((RadioGateway)MainForm.RadioGWHash[key]).Name + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + seqID4 + test1), SafeMobileLib.Utils.Convert_text_For_multicast("#" + seqID4 + test1).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#" + seqID4 + test1);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
((RadioGateway)MainForm.RadioGWHash[key]).Alive = true;
((RadioGateway)MainForm.RadioGWHash[key]).LastUpdate = DateTime.UtcNow;
@ -1165,7 +1176,9 @@ namespace AppServer
string status = ((RadioGateway)(entry.Value)).Alive ? "ON" : "OFF";
Utils.WriteLine(string.Format("Response for SD request: Gateway {0} is {1}", ((RadioGateway)(entry.Value)).Name, status), status == "ON" ? ConsoleColor.Green : ConsoleColor.Red);
string test1 = "#501#" + ((RadioGateway)(entry.Value)).Gw_id + "#" + ((RadioGateway)(entry.Value)).Id + "#" + status + "#" + ((RadioGateway)(entry.Value)).Name + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + "0.0" + test1), SafeMobileLib.Utils.Convert_text_For_multicast("#" + "0.0" + test1).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#" + "0.0" + test1);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
break;
@ -1288,11 +1301,14 @@ namespace AppServer
if (sysPos != null) dest = sysPos.Gw_id + "." + sysPos.R_gw_id + "." + radioID.ToString();
String test = "#154#" + dest + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + seqId + test), SafeMobileLib.Utils.Convert_text_For_multicast("#" + seqId + test).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#" + seqId + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
//send emergency alarm to SD
test = "#134#" + radioID.ToString() + "#" + emergencyType;
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + seqId + test), SafeMobileLib.Utils.Convert_text_For_multicast("#" + seqId + test).Length);
dataToSend = Utils.Convert_text_For_multicast("#" + seqId + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
((VehicleStatus)MainForm.VehicleHashStat[radioID]).curentStatus = Status_for_tab.EMERG;
((VehicleStatus)MainForm.VehicleHashStat[radioID]).lastArsTime = DateTime.Now;
@ -1373,7 +1389,9 @@ namespace AppServer
UnitSysPosition tmpX = dbvehs.getSystemPosition(msg.sc_id_dest);
//string test = "#143#" + tmpX.Gw_id + "." + tmpX.R_gw_id+"."+msg.imei_dest + "#" + msg.mess + "#" + msg.sched_timeGMT + "#";
string test = "#143#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + msg.imei_dest + "#" + msg.mess + "#" + msg.sched_timeGMT + "#" + msg.dispatcherID + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + msg.seq_id + test), SafeMobileLib.Utils.Convert_text_For_multicast("#" + msg.seq_id + test).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#" + msg.seq_id + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
else
SM.Debug("message will be sent at a later time - schedule: " + msg.sched_timeGMT + " current:" + DateTime.Now.ToUniversalTime().DateTo70Format());
@ -1405,6 +1423,7 @@ namespace AppServer
string test = "";
String cmdok = "";
var subsBlackList = new List<int> { (int)Status_for_tab.OFF, (int)Status_for_tab.DISABLE, (int)Status_for_tab.MADEOFF };
byte[] dataToSend = null;
foreach (smsmessage msg in smss)
{
@ -1417,7 +1436,9 @@ namespace AppServer
if (SysPosList[sc_id]!=null)
test = "#143#" + ((UnitSysPosition)SysPosList[sc_id]).Gw_id + "." + ((UnitSysPosition)SysPosList[sc_id]).R_gw_id + "." + msg.imei_dest + "#" + msg.mess + "#" + msg.sched_timeGMT + "#" + msg.dispatcherID + "#";
else test = "#143#" + "0.0" + "." + msg.imei_dest + "#" + msg.mess + "#" + msg.sched_timeGMT + "#" + msg.dispatcherID + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + msg.seq_id + test), SafeMobileLib.Utils.Convert_text_For_multicast("#" + msg.seq_id + test).Length);
dataToSend = Utils.Convert_text_For_multicast("#" + msg.seq_id + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
else
SM.Debug("message will be sent at a later time - schedule: " + msg.sched_timeGMT + " current:" + DateTime.Now.ToUniversalTime().DateTo70Format());
@ -1430,7 +1451,8 @@ namespace AppServer
UnitSysPosition tmpX = dbvehs.getSystemPosition_for_group(msg.imei_dest);
test = "#145#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + msg.sc_id_dest + "#" + msg.mess + "#" + msg.sched_timeGMT + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + msg.seq_id + test), SafeMobileLib.Utils.Convert_text_For_multicast("#" + msg.seq_id + test).Length);
dataToSend = Utils.Convert_text_For_multicast("#" + msg.seq_id + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
Utils.WriteLine($"Undelivered {undeliveredSMS} private messages and {smss.Count} group messages", ConsoleColor.White);
@ -1446,19 +1468,19 @@ namespace AppServer
{
//Check4ExpiredTickets
List<JobTickets> jtlist = new List<JobTickets>();
string list_of_id_text = "";
try
{
DBTicketingManager DBT = new DBTicketingManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
List<Int32> ExpiredTicketsIdList = DBT.updateTicketExpireDate(DateTo70Format(DateTime.UtcNow));
if(ExpiredTicketsIdList.Count>0)
{
foreach(Int32 id in ExpiredTicketsIdList)
{
list_of_id_text += id + ",";
}
list_of_id_text = list_of_id_text.Substring(0, list_of_id_text.Length - 1);
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#251#" + list_of_id_text + "#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#251#" + list_of_id_text + "#").Length);
// get comma separated list
string list_of_id_text = string.Join<string>(",", ExpiredTicketsIdList.Select(x => $"{x}"));
byte[] dataToSend = Utils.Convert_text_For_multicast($"#0.0#251#{list_of_id_text}#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
catch (Exception ex)
@ -1496,7 +1518,10 @@ namespace AppServer
string head = "#143#0.0." + ticket.Imei + "#";
if (SysPosList[ticket.sc_id] != null) head = "#143#" + ((UnitSysPosition)SysPosList[ticket.sc_id]).Gw_id + "." + ((UnitSysPosition)SysPosList[ticket.sc_id]).R_gw_id + "." + ticket.Imei + "#";
string test = head + message + "#" + 0 + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + ticket.seq_id + test), SafeMobileLib.Utils.Convert_text_For_multicast("#" + ticket.seq_id + test).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#" + ticket.seq_id + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
}
@ -1522,7 +1547,8 @@ namespace AppServer
if (SysPosList[ticket.sc_id] != null) head = "#143#" + ((UnitSysPosition)SysPosList[ticket.sc_id]).Gw_id + "." + ((UnitSysPosition)SysPosList[ticket.sc_id]).R_gw_id + "." + ticket.Imei + "#";
string test = head + ticket.Name + "#" + 0 + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + ticket.seq_id + test), SafeMobileLib.Utils.Convert_text_For_multicast("#" + ticket.seq_id + test).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#" + ticket.seq_id + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
else
SM.Debug("ticket will be sent at a later time - schedule: " + ticket.sched_timegmt + " current:" + DateTime.Now.ToUniversalTime().DateTo70Format());
@ -1554,7 +1580,9 @@ namespace AppServer
if (DateTime.Now.ToUniversalTime() > item.Timegmt.AddSeconds(item.ArsInterval + 10))// added 10 seconds; marja erroare
{
SM.Debug("Unit:" + item.Imei + " ARS interval expired. Marking unit as OFF");
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#130#" + item.Imei + "#OFF#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#130#" + item.Imei + "#OFF#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#130#" + item.Imei + "#OFF#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
}
@ -1600,7 +1628,9 @@ namespace AppServer
string test = "#501#" + ((RadioGateway)(entry.Value)).Gw_id + "#" + ((RadioGateway)(entry.Value)).Id + "#" + "OFF" + "#" + ((RadioGateway)(entry.Value)).Name + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#" + "0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#" + "0.0" + test).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#" + "0.0" + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
((RadioGateway)(entry.Value)).Alive = false;
}
}
@ -1685,7 +1715,9 @@ namespace AppServer
public static void PushStatus(String IMEI,Status_for_tab stat)
{
Utils.WriteLine("Send PushStatus:" + stat+" Imei:"+IMEI,ConsoleColor.Yellow);
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#153#" + IMEI + "#" + (Int32)stat + "#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#153#" + IMEI + "#" + (Int32)stat + "#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#153#" + IMEI + "#" + (Int32)stat + "#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
@ -2084,7 +2116,8 @@ namespace AppServer
messageOnScreen = true;
try
{
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#Application server database connection failed#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#3#Application server database connection failed#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#Application server database connection failed#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
catch (Exception ex2)
{
@ -2265,11 +2298,20 @@ namespace AppServer
if (Program.cfg.enableEmailService)
{
SM.Debug(new string[] { "Checking mail at:" + DateTime.Now.ToString(), "For " + Program.cfg.emailAddress.ToString() + " on " + Program.cfg.pop3Server.ToString() });
emailHT = dbsubsoperManage.getAll_imei_sc_id("ByMail");
if (emailHT.Count > 0)
{
SM.Debug("Load " + emailHT.Count + " subscribers emails from DB ...");
}
if (sslServer == null)
{
SM.Debug("sslServer is null");
return;
}
Int64 latestEmailTime = sslServer.getLastEmailTime();
ArrayList EmailList = sslServer.getEmails();
@ -2280,19 +2322,23 @@ namespace AppServer
DB.SetLastEmailTime(sslServer.getLastEmailTime());
}
DBsmsManager DBsms = new DBsmsManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
DBvehiclesManager dbvehs = new DBvehiclesManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
foreach (EmailtoSMS obj in EmailList)
{
String seqID = "0." + (DateTime.Now.GetSecondsLocalFromDT()) + DateTime.Now.Millisecond.ToString();
SM.Debug(new string[] {"-----START OK----",
"From: " + obj.from,
"ID: " + obj.id,
"Text: " + obj.text});
SM.Debug(new string[] { "-----START OK----",
"From: " + obj.from,
"ID: " + obj.id,
"Text: " + obj.text});
try
{
// app server idx =0
DBsmsManager DB = new DBsmsManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
//bigu code remove # from text and also replace "'"
try
{
@ -2303,13 +2349,15 @@ namespace AppServer
{
SM.Debug("Error on converting email:" + ex.ToString());
}
//end bigu code
if (!obj.is_group) DB.insert_sms_received(obj.id, obj.text, 7, obj.from, seqID);
if (!obj.is_group) DBsms.insert_sms_received(obj.id, obj.text, 7, obj.from, seqID);
if (obj.is_sierra)
{
if (emailHT.Contains(obj.from))
{
SM.Debug("Email received <<" + obj.text + ">> from address: " + obj.from);
seqID = "1." + Utils.GetSecondsLocalFromDT(DateTime.Now).ToString() + DateTime.Now.Millisecond.ToString();
string test = "#132#" + ((SW_Subscriber)emailHT[obj.from]).imei + "#" + obj.text + "#hyt#";
String cmdok = "#" + seqID + test; Int32 tmp = cmdok.Length + 1; tmp += tmp.ToString().Length; cmdok = "#" + tmp.ToString() + cmdok;
@ -2317,6 +2365,7 @@ namespace AppServer
byte[] buf = enc.GetBytes(cmdok);
//send to messagebus
MainForm.udp.Send(buf, buf.Length);
SM.Debug("Email thread successfully sent data to message bus");
}
}
@ -2331,26 +2380,36 @@ namespace AppServer
obj.text = obj.text.Remove(140 - 3 - obj.from.Length) + " [" + obj.from + "]";
else
obj.text = obj.text + " [" + obj.from + "]";
//send SMS on message buss
if (!obj.is_sierra)
{
UnitSysPosition tmpX = dbvehs.getSystemPosition(dbvehs.getSCID(obj.id));
string msg = "#143#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + obj.id + "#" + obj.text + "#" + (DateTime.Now.GetSecondsLocalFromDT()) + "#";
if (obj.is_group) msg = "#144#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + obj.id + "#" + obj.text + "#" + (DateTime.Now.GetSecondsLocalFromDT()) + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + msg), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + msg).Length);
if (obj.is_group)
if (dbvehs != null)
{
Int32 oldgatewayID = 0;
foreach (RadioGateway obj2 in RadioListIP)
UnitSysPosition tmpX = dbvehs.getSystemPosition(dbvehs.getSCID(obj.id));
string cmd = $"{tmpX.Gw_id}.{tmpX.R_gw_id}.{obj.id}#{obj.text}#{DateTime.Now.GetSecondsLocalFromDT()}#";
string code = (obj.is_group) ? "#144#" : "#143#" ;
byte[] msg = Utils.Convert_text_For_multicast("#0.0" + code + cmd);
if (msg != null && msg.Length > 0)
MainForm.udp.Send(msg, msg.Length);
if (obj.is_group)
{
if (oldgatewayID != obj2.Gw_id)
Int32 oldgatewayID = 0;
foreach (RadioGateway obj2 in RadioListIP)
{
oldgatewayID = (Int32)obj2.Gw_id;
string msg2 = "#144#" + obj2.Gw_id + "." + obj2.Id + "." + obj.id + "#" + obj.text + "#" + (DateTime.Now.GetSecondsLocalFromDT()) + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#1." + (DateTime.Now.GetSecondsLocalFromDT()) + DateTime.Now.Ticks.ToString() + msg2), SafeMobileLib.Utils.Convert_text_For_multicast("#1." + (DateTime.Now.GetSecondsLocalFromDT()) + DateTime.Now.Ticks.ToString() + msg2).Length);
if (oldgatewayID != obj2.Gw_id)
{
oldgatewayID = (Int32)obj2.Gw_id;
cmd = $"#144#{obj2.Gw_id}.{obj2.Id}.{obj.id}#{obj.text}#{DateTime.Now.GetSecondsLocalFromDT()}#";
byte[] msg2 = Utils.Convert_text_For_multicast("#1." + (DateTime.Now.GetSecondsLocalFromDT()) + DateTime.Now.Ticks.ToString() + cmd);
if( msg2 != null && msg2.Length > 0)
MainForm.udp.Send(msg2, msg2.Length);
}
}
}
}
@ -2379,7 +2438,7 @@ namespace AppServer
if (MainForm.IsBlacklistedAddress(mailAdr))
{
Utils.WriteLine($"sendMailGeo : The email was not sent. Email address '{mailAdr}' is in blacklist ");
Utils.WriteLine($"sendMail : The email was not sent. Email address '{mailAdr}' is in blacklist count = {MainForm.blackListAddress[mailAdr]}");
return;
}
@ -2401,7 +2460,8 @@ namespace AppServer
}
catch (Exception ex)
{
if (ex.ToString().Contains("timed out"))
if (ex.ToString().Contains("timed out") ||
ex.ToString().Contains("the client was not authenticated"))
MainForm.HandleTimeoutError(mailAdr);
Utils.WriteLine("Exception in sendMail: " + ex.ToString(), ConsoleColor.Red);
@ -2429,7 +2489,7 @@ namespace AppServer
if (MainForm.IsBlacklistedAddress(mailAdr))
{
Utils.WriteLine($"sendMailGeo : The email was not sent. Email address '{mailAdr}' is in blacklist ");
Utils.WriteLine($"sendMail_SW : The email was not sent. Email address '{mailAdr}' is in blacklist count = {MainForm.blackListAddress[mailAdr]}");
return;
}
@ -2447,7 +2507,8 @@ namespace AppServer
}
catch (Exception ex)
{
if (ex.ToString().Contains("timed out"))
if (ex.ToString().Contains("timed out") ||
ex.ToString().Contains("the client was not authenticated"))
MainForm.HandleTimeoutError(mailAdr);
Utils.WriteLine("Exception in sendMail Sierra Wireless Gateway: " + ex.ToString(), ConsoleColor.Red);
@ -2492,8 +2553,9 @@ namespace AppServer
{
//send emergency alarm to SD
//send ACK back to GW
string test = (backupDOne == true) ? "#61#1#" : "#61#0#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
string code = (backupDOne == true) ? "#61#1#" : "#61#0#";
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + code);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
#endregion
@ -2520,8 +2582,10 @@ namespace AppServer
{
//send emergency alarm to SD
//send ACK back to GW
string test = (restoreDOne == true) ? "#62#1#" : "#252#0#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
string code = (restoreDOne == true) ? "#62#1#" : "#252#0#";
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + code);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
#endregion

View File

@ -215,8 +215,8 @@ namespace AppServer
Thread.Sleep(2000);
try
{
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#4#Application server stopped#"),
Utils.Convert_text_For_multicast("#0.0#210#4#Application server stopped#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#210#4#Application server stopped#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
// save all unhandled gps positions
MainForm.DumpLocationQueueToFile();
@ -241,7 +241,9 @@ namespace AppServer
Thread.Sleep(2000);
try
{
MainForm.udp?.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#4#Application server stopped#"), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0#210#4#Application server stopped#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#210#4#Application server stopped#");
MainForm.udp?.Send(dataToSend, dataToSend.Length);
// save all unhandled gps positions
MainForm.DumpLocationQueueToFile();

View File

@ -108,8 +108,9 @@ namespace AppServer
+ Program.cfg.DB_schema + ";" + Program.cfg.DB_user + ";" + Program.cfg.DB_passwd
+ ";" + Program.cfg.DB_port + ";" + Program.cfg.VoicePort + ";"
+ audibleAlerts.ToString() + ";" + MainForm.dbAccess.ToString() + ";";
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0#156#" + command[1].Trim() + "#"), Utils.Convert_text_For_multicast("#0.0#156#"
+ command[1].Trim() + "#").Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#156#" + command[1].Trim() + "#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
MainForm.RegistrationAnswer = false;
Int32 countWait = 0; //maxim 30 = 3 seconds

View File

@ -172,7 +172,9 @@ namespace AppServer
test = $"#155#{rec.id}#{rec.hddLocation}#{rec.gwID}#{rec.radioGWID}#{rec.group_cpsId}#{rec.subs_imei}#{rec.startTime}#{rec.endTime}#{rec.typeSD}#{rec.calltype}#{rec.dispatcher_id}#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0" + test);
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
catch (Exception ex)

View File

@ -452,32 +452,34 @@ namespace SafeMobileLib
BatchHistoryData batchHistObj = null;
try
{
lat = Convert.ToDouble(dr["lat"]);
lng = Convert.ToDouble(dr["lng"]);
timegmt = Convert.ToInt32(dr["timegmt"]);
batchHistObj = new BatchHistoryData
{
batchHistObj = new BatchHistoryData
{
Department = dr["department"].ToString(),
Unit = dr["unit"].ToString(),
Location = ((getAddress && dr["address"] != DBNull.Value) ? dr["address"].ToString() : "LAT:" + Math.Round(lat, 5).ToString() + " , LNG:" + Math.Round(lat, 5).ToString()),
Speed = (isInMile) ? ((int)(Convert.ToInt32(dr["speed"]) * 0.621371192)).ToString() : Convert.ToInt32(dr["speed"]).ToString(),
Lat = lat,
Lng = lng,
Address = dr["address"].ToString(),
Address = string.Empty,
Time = timegmt.TimeOfDayHHMMSSLocal(!is24hours),
Date = timegmt.GetDTLocalFromSeconds().Date.ToShortDateString()
};
if (getAddress)
{
batchHistObj.Location = dr["address"].ToString();
batchHistObj.Address = dr["address"].ToString();
}
else
batchHistObj.Location = "LAT:" + Math.Round(lat, 5).ToString() + " , LNG:" + Math.Round(lat, 5).ToString();
}

View File

@ -25,6 +25,8 @@ namespace SafeMobileLib
private bool isSSL = true;
private Int64 lastEmailTime = 0;
private Int64 startEmailServiceTime = 0;
public static Dictionary<string, int> blackList = new Dictionary<string, int>();
public const int MAX_ATTEMPTS = 100;
// blank constructor in order to be used in Email Checking
public EmailServerSSL()
@ -378,11 +380,46 @@ namespace SafeMobileLib
return ret;
}
public static void HandleBlacklist(string key)
{
// add key to backlist
if (!blackList.ContainsKey(key))
blackList.Add(key, MAX_ATTEMPTS);
}
public static bool IsBlacklisted(string key)
{
if (!blackList.ContainsKey(key))
return false;
// avoid to connect to pop3 MAX_ATTEMPTS times => give another chance to try to connect to pop 3 when count = 0
int count = blackList[key];
if (count == 0)
{
blackList.Remove(key);
return false;
}
blackList[key] = count - 1;
return true;
}
/// <summary>
/// Connect to the Pop Server in order to be used to get the emails
/// </summary>
private void ConnectEmailPopServer()
{
if (IsBlacklisted(serverIP))
{
Utils.WriteLine($"ConnectEmailPopServer : Could not conenct to the pop server '{serverIP}'. The pop server '{serverIP}' is in blacklist count = {blackList[serverIP]}");
return;
}
Thread t = new Thread(() =>
{
ConnectAsync();
@ -393,8 +430,17 @@ namespace SafeMobileLib
private void ConnectAsync()
{
if (popClient != null && popClient.Connected)
popClient.Disconnect();
try
{
if (popClient != null && popClient.Connected)
popClient.Disconnect();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
popClient = null;
popClient = new Pop3Client();
@ -412,18 +458,25 @@ namespace SafeMobileLib
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("PopServerNotFoundException -> " + ee.ToString());
Console.ForegroundColor = ConsoleColor.Gray;
HandleBlacklist(serverIP);
}
catch (InvalidLoginException e)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("InvalidLoginException -> " + e.ToString());
Console.ForegroundColor = ConsoleColor.Gray;
HandleBlacklist(serverIP);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("ConnectEmailPopServer -> " + ex.ToString());
Console.ForegroundColor = ConsoleColor.Gray;
HandleBlacklist(serverIP);
}
}

View File

@ -91,7 +91,8 @@ namespace SafeMobileLib
{
if (udpMulticast != null)
{
udpMulticast.Send(Utils.Convert_text_For_multicast("#" + seqID + test), Utils.Convert_text_For_multicast("#" + seqID + test).Length);
byte[] dataToSend = Utils.Convert_text_For_multicast("#" + seqID + test);
udpMulticast.Send(dataToSend, dataToSend.Length);
}
else
{

View File

@ -42,36 +42,28 @@ namespace SafeMobileLib
recv = s.Receive(b);
else
break;//break if socket == null
if (recv == 0)
continue;//continue if return nr bytes == 0
byte[] tmp = new byte[recv];
for (int i = 0; i < recv; i++)
{
tmp[i] = b[i];
}
byte[] decByte = Encrypted ? Encryption.Decrypt(tmp, EncryptionAlgorithm.Des64) : tmp;
// trigger event
if (OnNewDataRecv != null)
{
byte[] tmp = new byte[recv];
for (int i = 0; i < recv; i++)
{
tmp[i] = b[i];
}
byte[] decByte = Encrypted ? Encryption.Decrypt(tmp, EncryptionAlgorithm.Des64) : tmp;
// trigger event
OnNewDataRecv(decByte, decByte.Length);
}
// trigger event
if (OnNewDataReceived != null)
{
byte[] tmp = new byte[recv];
for (int i = 0; i < recv; i++)
{
tmp[i] = b[i];
}
byte[] decByte = Encrypted ? Encryption.Decrypt(tmp, EncryptionAlgorithm.Des64) : tmp;
// trigger event
OnNewDataReceived(mcastGroup, decByte, decByte.Length);
}
if (s == null)
@ -108,27 +100,19 @@ namespace SafeMobileLib
byte[] b = new byte[65507];
Thread.Sleep(1);
int recv = s.Receive(b);
if (OnNewDataRecv != null)
byte[] tmp = new byte[recv];
for (int i = 0; i < recv; i++)
{
byte[] tmp = new byte[recv];
for (int i = 0; i < recv; i++)
{
tmp[i] = b[i];
}
if (this.OnNewDataRecv != null)
this.OnNewDataRecv(tmp, tmp.Length);
tmp[i] = b[i];
}
if (OnNewDataReceived != null)
{
byte[] tmp = new byte[recv];
for (int i = 0; i < recv; i++)
{
tmp[i] = b[i];
}
if (this.OnNewDataReceived != null)
this.OnNewDataReceived(mcastGroup, tmp, tmp.Length);
}
if (this.OnNewDataRecv != null)
this.OnNewDataRecv(tmp, tmp.Length);
if (this.OnNewDataReceived != null)
this.OnNewDataReceived(mcastGroup, tmp, tmp.Length);
if (s == null)
{
@ -217,16 +201,17 @@ namespace SafeMobileLib
IPEndPoint ipep = new IPEndPoint(myIP, port);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
s.Bind(ipep);
IPAddress ip = IPAddress.Parse(mcastGroup);
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, myIP));
s.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastTimeToLive, int.Parse("1"));
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, int.Parse("1"));
listenThread = new Thread(new ThreadStart(Listen));
listenThread.IsBackground = true;
}
if (listenThread != null)
listenThread.Start();
ret = true;
Utils.WriteLine($"++++++++++++++++++++++++++++++++++++++++++\nUdpMulticast bind on {mcastGroup}:{port} Ethernet: {myIP}\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
@ -243,12 +228,14 @@ namespace SafeMobileLib
bool ret = false;
working = true;
useThreadPool = true;
try
{
if (s == null)
{
s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
}
if (s != null)
{
Utils.WriteLine(String.Format("[### {0:H:mm:ss} ###] Port multi cast {1}", DateTime.Now, port));
@ -257,8 +244,7 @@ namespace SafeMobileLib
s.Bind(ipep);
IPAddress ip = IPAddress.Parse(mcastGroup);
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any));
s.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastTimeToLive, int.Parse("1"));
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, int.Parse("1"));
ThreadPool.QueueUserWorkItem(new WaitCallback(Listen_pool));
@ -282,6 +268,7 @@ namespace SafeMobileLib
{
s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
}
if (s != null)
{
Utils.WriteLine(String.Format("[### {0:H:mm:ss} ###] Port multi cast {1}", DateTime.Now, port));
@ -290,13 +277,14 @@ namespace SafeMobileLib
s.Bind(ipep);
IPAddress ip = IPAddress.Parse(mcastGroup);
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any));
s.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastTimeToLive, int.Parse("1"));
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, int.Parse("1"));
listenThread = new Thread(new ThreadStart(Listen_Decoded));
listenThread.IsBackground = true;
}
if (listenThread != null)
listenThread.Start();
ret = true;
}
catch (Exception ex)

View File

@ -441,8 +441,10 @@ namespace SafeMobileLib
Int32 tmp = cmdok.Length + 1;
tmp += tmp.ToString().Length;
String TMPcmdok = "#" + tmp.ToString() + cmdok;
if (tmp != TMPcmdok.Length) cmdok = "#" + TMPcmdok.Length + cmdok;
else cmdok = TMPcmdok;
if (tmp != TMPcmdok.Length)
cmdok = "#" + TMPcmdok.Length + cmdok;
else
cmdok = TMPcmdok;
System.Text.Encoding enc = System.Text.Encoding.ASCII;
byte[] buf = enc.GetBytes(cmdok);

View File

@ -263,19 +263,24 @@ namespace SipComponent
}
else
_localIPaddress = localIPAddress;
_sipDomainPort = sipDomainPort;
_sipClient = CreateSipClientClass(sipDomain, _sipDomainPort, _localIPaddress, localSipPort, userName, password, requestTimeout);
_bufferMiliseconds = bufferMiliseconds;
// Registration Timer
_registrationInterval = registrationInterval;
_registrationData = new RegistrationData(userName, _registrationInterval + 2);
System.Timers.Timer registrationTimer = new System.Timers.Timer();
// Set up the registration timer
registrationTimer.Interval = _registrationInterval * 1000;
registrationTimer.Elapsed += _registrationTimer_Elapsed;
_sipID_regTimer_regStatus_Dict.Add(userName,
new Tuple<System.Timers.Timer, RegistrationStatus>(registrationTimer, RegistrationStatus.RegistrationNotStarted
));
_IDsregisteredList.Add(userName);
StartRegistrationTimer();
@ -304,6 +309,7 @@ namespace SipComponent
throw new ObjectDisposedException("SipClientClass");
if (idToInvite == null)
throw new ArgumentNullException("idToInvite");
lock (_lockerSipDialog)
{
if (!_IDsentInviteDict.ContainsKey(idToInvite) && !_IDreceivedInviteDict.ContainsKey(idToInvite)
@ -324,6 +330,7 @@ namespace SipComponent
throw new ObjectDisposedException("SipClientClass");
if (groupIDtoInvite == null)
throw new ArgumentNullException("groupIDtoInvite");
// Check if registered to the group id
lock (_lockerSipDialog)
{
@ -342,6 +349,7 @@ namespace SipComponent
{
if (_sipClassClosed)
throw new ObjectDisposedException("SipClientClass");
Task t = null;
CancelInvite_private(idToCancel, out t);
}
@ -370,6 +378,7 @@ namespace SipComponent
{
return dialog.CallID == _IDsentInviteDict[idToCancel].CallID;
});
if (d != null)
{
//Send Cancel Request
@ -387,6 +396,7 @@ namespace SipComponent
}
}, d);
}
// Remove from dict
_IDsentInviteDict.Remove(idToCancel);
_IDsCalledByMeList.Remove(idToCancel);
@ -585,6 +595,7 @@ namespace SipComponent
{
if (_sipClassClosed)
throw new ObjectDisposedException("SipClientClass");
lock (_lockerSipDialog)
{
if (_IDdialogTuple.ContainsKey(idToSendVoice))
@ -603,29 +614,29 @@ namespace SipComponent
{
if (_sipClassClosed)
throw new ObjectDisposedException("SipClientClass");
if (idToRequestGps != null)
{
// Send Gps request for Linx
// [#msgLen]#seqID#154#
string cmdText = string.Format("#{0}#154#", seqID);
string cmd = AddMsgLenForMBus(cmdText);
Message pollRequestForLinx = GenerateSipMessage(idToRequestGps, UserName, _sipClient.Domain, _sipDomainPort, cmd);
pollRequestForLinx.Header.Add("Ais-Service", "mbus");
Task.Factory.StartNew(() =>
{
try
{
_sipClient.SendRequest(pollRequestForLinx);
}
catch (Exception)
{
; // Probably timeout exception, do not do anything
}
});
}
else
if (idToRequestGps == null)
throw new ArgumentNullException("idToRequestGps");
// Send Gps request for Linx
// [#msgLen]#seqID#154#
string cmdText = string.Format("#{0}#154#", seqID);
string cmd = AddMsgLenForMBus(cmdText);
Message pollRequestForLinx = GenerateSipMessage(idToRequestGps, UserName, _sipClient.Domain, _sipDomainPort, cmd);
pollRequestForLinx.Header.Add("Ais-Service", "mbus");
Task.Factory.StartNew(() =>
{
try
{
_sipClient.SendRequest(pollRequestForLinx);
}
catch (Exception)
{
; // Probably timeout exception, do not do anything
}
});
}
/// <summary>
@ -636,26 +647,26 @@ namespace SipComponent
{
if (_sipClassClosed)
throw new ObjectDisposedException("SipClientClass");
if (linxID != null)
{
// Send [#msgLen]#seqID#238#
string textToSend = string.Format("#{0}#238#", _rand.Next().ToString());
string cmdToSend = AddMsgLenForMBus(textToSend);
Message sipMessage = GenerateSipMessage(linxID, UserName, _sipClient.Domain, _sipDomainPort, cmdToSend);
Task.Factory.StartNew(() =>
{
try
{
_sipClient.SendRequest(sipMessage);
}
catch (Exception)
{
// Do nothing
}
});
}
else
if (linxID == null)
throw new ArgumentNullException("linxID");
// Send [#msgLen]#seqID#238#
string textToSend = string.Format("#{0}#238#", _rand.Next().ToString());
string cmdToSend = AddMsgLenForMBus(textToSend);
Message sipMessage = GenerateSipMessage(linxID, UserName, _sipClient.Domain, _sipDomainPort, cmdToSend);
Task.Factory.StartNew(() =>
{
try
{
_sipClient.SendRequest(sipMessage);
}
catch (Exception)
{
// Do nothing
}
});
}
/// <summary>
@ -669,10 +680,12 @@ namespace SipComponent
{
if (_sipClassClosed)
throw new ObjectDisposedException("SipClientClass");
if (idToSendSMS != null && text != null)
{
bool sendSipMessage = true;
string unconfirmedSmsKey = null;
if (_smsConfirmationFromServer)
{
unconfirmedSmsKey = idToSendSMS + text.GetHashCode();
@ -691,6 +704,7 @@ namespace SipComponent
}
}
}
if (sendSipMessage)
{
// Create a new thread on which:
@ -743,15 +757,16 @@ namespace SipComponent
throw new ArgumentNullException("text");
}
private Message GenerateSipMessage(string destinationID, string senderID, string sipServer,
int sipServerPort, string text)
private Message GenerateSipMessage(string destinationID, string senderID, string sipServer, int sipServerPort, string text)
{
Message sipMessage = new Message();
sipMessage.Uri = "sip:" + destinationID + "@" + sipServer + ":" + sipServerPort;
sipMessage.From = new ContactInfo(string.Format("sip:{0}@{1}", senderID, sipServer));
sipMessage.To = new ContactInfo(string.Format("sip:{0}@{1}", destinationID, sipServer));
sipMessage.ContentType = "text/plain;charset=UTF-8";
sipMessage.Body = text;
Message sipMessage = new Message()
{
Uri = $"sip:{destinationID}@{sipServer}:{sipServerPort}",
From = new ContactInfo($"sip:{senderID}@{sipServer}"),
To = new ContactInfo($"sip:{destinationID}@{sipServer}"),
ContentType = "text/plain;charset=UTF-8",
Body = text
};
return sipMessage;
}
@ -833,10 +848,12 @@ namespace SipComponent
if (!_sipClassClosed)
{
_sipClassClosed = true;
// Send ARS OFF and disconnect from socket IO
if (_sendArsOnOff)
_socketIOClass.SendArs(new ArsInfo(false, "0", UserName));
_socketIOClass.Disconect();
//
List<string> sipIDs = new List<string>();
Task task = null;
@ -892,6 +909,7 @@ namespace SipComponent
// Stop sip class
_sipClient.Disconnect();
});
if (!async)
t.Wait();
}
@ -911,6 +929,8 @@ namespace SipComponent
zeroRegistrationData = new RegistrationData(id, 0, true);
else
zeroRegistrationData = new RegistrationData(id, 0);
_sipID_regTimer_regStatus_Dict[id].Item1.Stop();
SendSipRegister(zeroRegistrationData);
}
@ -1398,10 +1418,11 @@ namespace SipComponent
string lastWord = source.Substring(source.LastIndexOf(' ') + 1);
if (lastWord.Contains("delivered"))
return true;
else if (lastWord.Contains("failed"))
if (lastWord.Contains("failed"))
return false;
else
throw new ApplicationException("Error on parsing the sms confirmation from sip server");
throw new ApplicationException("Error on parsing the sms confirmation from sip server");
}
#endregion
@ -1418,11 +1439,13 @@ namespace SipComponent
// Extract ip and port where to send voice to simoco
IPAddress ipToSendAudio = null;
int portToSendAudio;
if (IPAddress.TryParse(receivedSDP.Connection.Address, out ipToSendAudio))
{
portToSendAudio = receivedSDP.Media[0].Port;
}
else throw new ApplicationException("Canot determine ip where to send audio");
else
throw new ApplicationException("Canot determine ip where to send audio");
// Creez clientul de UDP conectat la portul pe care voi primi voce
UdpClient udpClient = new UdpClient(localRTPport);
@ -1563,9 +1586,9 @@ namespace SipComponent
private SipClient CreateSipClientClass(string sipDomain, int sipDomainPort, string localIPaddress, int localSipPort, string userName, string password, int requestTimeout)
{
SipClient sipClient;
// Set up the master SIP class
sipClient = new SipClient(sipDomain, sipDomainPort, Independentsoft.Sip.ProtocolType.Udp, userName, password);
SipClient sipClient = new SipClient(sipDomain, sipDomainPort, Independentsoft.Sip.ProtocolType.Udp, userName, password);
sipClient.LocalIPEndPoint = new IPEndPoint(IPAddress.Parse(localIPaddress), localSipPort);
// Turn on logging
//sipClient.Logger = new Logger(AppDomain.CurrentDomain.BaseDirectory + "\\sipLog.txt");
@ -1590,6 +1613,7 @@ namespace SipComponent
int rtpPort = ReturnAvailablePort();
SessionDescription sdp = CreateSDP(rtpPort);
Invite inv = new Invite();
inv.Uri = "sip:" + idToCall + "@" + sipServerIP;
inv.From = new ContactInfo("sip:" + sipID.ToString() + "@" + sipServerIP);
@ -1650,20 +1674,17 @@ namespace SipComponent
private void SendSipRegister(object registrationDataObj)
{
string sipServerIP = _sipClient.Domain;
RegistrationData regData = (RegistrationData)registrationDataObj;
string sipIDfrom = _sipClient.Username;
string sipIDto = regData.SipID;
string sipIDto = regData.SipID;
int expiresValue = regData.Expires;
bool isUnregisterRequest = (expiresValue == 0);
Register reg = new Register();
reg.Uri = "sip:" + sipServerIP;
reg.From = new ContactInfo(
sipIDfrom.ToString(),
"sip:" + sipIDfrom + "@" + sipServerIP);
reg.To = new ContactInfo(
sipIDto.ToString(),
"sip:" + sipIDto.ToString() + "@" + sipServerIP);
reg.From = new ContactInfo( sipIDfrom.ToString(), $"sip:{sipIDfrom}@{sipServerIP}");
reg.To = new ContactInfo( sipIDto.ToString(), $"sip:{sipIDto}@{sipServerIP}");
reg.Contact = new Contact("sip:" + sipIDfrom.ToString() + "@" + _sipClient.LocalIPEndPoint.ToString());
reg.Expires = expiresValue;
@ -1763,6 +1784,7 @@ namespace SipComponent
{
SendSipRegister(state);
}, _registrationData);
// Start registration timer
_sipID_regTimer_regStatus_Dict[UserName].Item1.Start();
}
@ -1807,10 +1829,12 @@ namespace SipComponent
{
rtpPort += 2;
}
if (rtpPort < MaxRtpPortNumber)
return rtpPort;
else
throw new SipClassException(
throw new SipClassException(
string.Format("Nu gasesc port liber in range-ul {0} - {1}", MinRtpPortNumber, MaxRtpPortNumber));
}
}
@ -1821,10 +1845,8 @@ namespace SipComponent
{
return invite.SessionDescription.Media[0].Port == portNb;
});
if (inv != null)
return true;
else
return false;
return (inv != null);
}
private bool IsPortAllreadyInUse(int portNumber)
@ -1843,15 +1865,12 @@ namespace SipComponent
public static bool ValidRtpPort(int rtpPort)
{
if (rtpPort < 1024 || rtpPort > 65534)
{
return false;
}
else if (rtpPort % 2 == 1)
{
if (rtpPort % 2 == 1)
return false;
}
else
return true;
return true;
}
/// <summary>
@ -1870,11 +1889,6 @@ namespace SipComponent
private bool IsInSameSubnet(IPAddress address2, IPAddress address, IPAddress subnetMask)
{
IPAddress network1 = GetNetworkAddress(address, subnetMask);

View File

@ -836,18 +836,27 @@ namespace SubscriberAndUserManager
private void SendBackupListRequest()
{
if(MainForm.udp != null)
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0#53#1#"), Utils.Convert_text_For_multicast("#0.0#53#1#").Length);
if (MainForm.udp != null)
{
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#53#1#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
private void SendBackupRequest()
{
if (MainForm.udp != null)
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0#51#1#"), Utils.Convert_text_For_multicast("#0.0#51#1#").Length);
{
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#51#1#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
private void SendRestoreRequest(string filename)
{
if (MainForm.udp != null)
MainForm.udp.Send(Utils.Convert_text_For_multicast("#0.0#52#" + filename + "#"), Utils.Convert_text_For_multicast("#0.0#52#" + filename + "#").Length);
{
byte[] dataToSend = Utils.Convert_text_For_multicast("#0.0#52#" + filename + "#");
MainForm.udp.Send(dataToSend, dataToSend.Length);
}
}
delegate void UpdateList(string fileNames);

View File

@ -112,7 +112,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="prebuild.sh" />
<None Include="RunMessagesPartitioning.bat" />
<None Include="RunMessagesPartitioning.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
@ -144,7 +146,9 @@
<Content Include="7toLatest7.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="call_messages_partitioning.sql" />
<Content Include="call_messages_partitioning.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="CreateMissingForeignKeys.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
@ -154,8 +158,12 @@
<Content Include="CreateMissingPrimaryKeys.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="generate_partitioning_of_an_existing_table_by_date_unix_time.sql" />
<Content Include="get_query_partitioning_of_an_existing_table_by_date_unix_time.sql" />
<Content Include="generate_partitioning_of_an_existing_table_by_date_unix_time.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="get_query_partitioning_of_an_existing_table_by_date_unix_time.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="NewFields.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>