using SafeNetLib; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading; namespace LMdirect_SOC { class Program { public static Config cfg; public static bool unitsLoaded = false; public static bool addressLoaded = false; public static DateTime startTime; //public static LOGS hLOG; //LocationThread LocationConnection = null; // the threads for the 5 services we handle DBconnThread DBConnection = null; Thread LocationThreadobj = null; Thread DBThreadobjGPS = null; Thread DBThreadobjAddr = null; Thread DBThreadobjAux = null; //alerts //private static AlertHandler alertHandler; static void Main(string[] args) { Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Console.WriteLine("Safemobile LMDirect Gateway v1.0, Copyright " + DateTime.Today.Year); Console.WriteLine(" (www.Safemobile.com) "); Console.WriteLine("-----------------------------------\n"); Console.WriteLine("Version: " + v.ToString()); LOGS.LOG(DateTime.Now.ToString() + " : Application started!!!!"); startTime = DateTime.Now; //creat PID file Process currentProcess = Process.GetCurrentProcess(); int procid = currentProcess.Id; if (File.Exists("pid.pid")) { File.Delete("pid.pid"); } System.IO.File.WriteAllText("pid.pid", procid.ToString()); Program p = new Program(); //load config if (!p.LoadConfig()) { Utils.ConsWrite(DebugMSG_Type.always, "EERROR loading configs!!!!\nPlease fix configs in DB/cfg file and restart the GW!!!"); LOGS.LOG(DateTime.Now.ToString() + " : EERROR loading configs!!!!\nPlease fix configs in DB/cfg file and restart the GW!!!"); return; } p.StartDBService(); Gateway g = new Gateway(); } private bool LoadConfig() { bool ret = false; cfg = new Config(); ret = true; return ret; } void StartDBService() { try { //SOC_connection sc = new SOC_connection(Server_IP, Server_Port, gatewayID); string MyConString = "SERVER=" + cfg.SERVER + ";" + "DATABASE=" + cfg.DATABASE + ";" + "UID=" + cfg.UID + ";" + "PASSWORD=" + cfg.PASSWORD + ";Pooling=false;"; DBConnection = new DBconnThread(MyConString, cfg.gatewayID); //Start GPS DB thread DBThreadobjGPS = new Thread(new ThreadStart(DBConnection.HandleConnectionGPS)); DBThreadobjGPS.IsBackground = true; DBThreadobjGPS.Start(); //Start Units DB thread DBThreadobjAux = new Thread(new ThreadStart(DBConnection.HandleConnectionAux)); DBThreadobjAux.IsBackground = true; DBThreadobjAux.Start(); //Start Addres insert thread DBThreadobjAddr = new Thread(new ThreadStart(DBConnection.HandleConnectionAddr)); DBThreadobjAddr.IsBackground = true; DBThreadobjAddr.Start(); } catch (Exception e) { Utils.ConsWrite(DebugMSG_Type.always, "Could not intialize the connection with location server!\r\n" + e.Message + "\r\nPlease check your internet connection !!"); LOGS.LOG(DateTime.Now.ToString() + " : Could not intialize the connection with location server!\r\n" + e.Message + "\r\nPlease check your internet connection !!"); //System.Environment.Exit(1); } } } }