SafeDispatch/MotoRepeaterCore/QueueManagerThread.cs

148 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace MotoRepeater
{
class QueueManagerThread
{
private bool working = false;
private MessageBus mbus;
public QueueManagerThread(MessageBus mbus)
{
working = true;
this.mbus = mbus;
}
public void Start()
{
try
{
working = true;
}
catch (Exception ex)
{
Utils.WriteLine(ConsoleType.ALL, ex.ToString());
}
}
public void Stop()
{
try
{
working = false;
}
catch (Exception ex)
{
Utils.WriteLine(ConsoleType.ALL, ex.ToString());
}
}
int count = 0;
//for ARS DB thread
public void HandleConnectionARS()
{
Utils.WriteLine(ConsoleType.DB, "ARS DB thread...");
while (working)
{
try
{
//add ARS in DB
ArsMSG ars_msg = SN_Queues.arsMsgQueue.GetItem(10);
while (ars_msg != null)
{
//Utils.ConsWrite(DebugMSG_Type.Debug, "Got ARS updating Server suid:" + ars_msg.imei + "msg:" + ars_msg.msg);
if (ars_msg.imei != "0" && ars_msg.imei != "")
{
//connector.InsertARS(suDBid.ToString(), ars_msg.msg);
//DB.Insert_ARSmsg(suDBid, ars_msg.msg);
//mbus.SendARS(ars_msg.imei, ars_msg.msg);
}
else
{
//Utils.ConsWrite(DebugMSG_Type.Debug, "%%%%% Got ARS invalid suid:" + ars_msg.suid + "msg:" + ars_msg.msg);
}
ars_msg = SN_Queues.arsMsgQueue.GetItem(10);
}
}
catch (ThreadAbortException)
{
}
catch (Exception ex)
{
Utils.WriteLine(ConsoleType.DB, ex.ToString());
}
} // end while (true)
}
//for GPS Server thread
public void HandleConnectionGPS()
{
Utils.WriteLine(ConsoleType.DB, "GPS DB thread...");
while (working)
{
try
{
htCell_t cell = SN_Queues.DBQueueLocation.GetItem(100);
if (cell != null)
{
mbus.SendGPS(cell.suid,(uint) Utils.GetSecondsLocalFromDT(cell.location_time), cell.spd, cell.lat, cell.lng, ((cell.triggered == true) ? 0 : 1));
}
}
catch (ThreadAbortException)
{
}
catch (Exception ex)
{
Utils.WriteLine(ConsoleType.DB, ex.ToString());
}
} // end while (true)
}
/*
//for SMS Server thread
public void HandleConnectionSMS()
{
Utils.ConsWrite(DebugMSG_Type.DB, "SMS DB thread ...");
while (working)
{
//check for new SMS in DB only every 30s
Thread.Sleep(30 * 1000);
//check SMS recv
SMS recv_msg = SM_SMS.recvSMSQueue.GetItem(100);
while (recv_msg != null)
{
Utils.ConsWrite(DebugMSG_Type.DB, "We got new messages.Sending them to server. RadioID:" + recv_msg.RadioID + " msg:" + recv_msg.Msg);
connector.InsertSMS(recv_msg);
recv_msg = SM_SMS.recvSMSQueue.GetItem(100);
}
//check SMS confirmation
SMS msg = SM_SMS.confSMSQueue.GetItem(100);
while (msg != null)
{
Utils.ConsWrite(DebugMSG_Type.DB, "Confirming SMS to server. DBmsgID:" + msg.DBid + " msg:" + msg.Msg);
connector.InsertSMSack(msg);
msg = SM_SMS.confSMSQueue.GetItem(100);
}
} // end while (true)
}
* */
}
}