using System; using System.Collections.Generic; using System.Text; using Nini.Config; using SafeNetLib; using System.IO; using System.Threading; namespace ConnectPlus_SOC { public class Config { private IConfigSource source = null; private string CFG_FILE = "config.ini"; public string ctrlIP; public int arsPort, locPort, smsPort; public int locPort_r, smsPort_r; public string gw_id; public int rep_inter_default; public int GPS_refresh; public bool gw_restart; public int debug_port; //email service public string smtpServer = ""; public string pop3Server = ""; public string pop3Port = ""; public string smtpPort = ""; public bool sslState = false; public bool enableEmailService = false; public string user, psw; //mysql public string SERVER; public string DATABASE; public string UID; public string PASSWORD; //folder path public static string folder_path = ""; //testMode public bool testActive; public int testFreq; public double testLat; public double testLng; public Config() { LoadConfig(); } private void LoadConfig() { try { string cfg_path = ""; if (folder_path != "") { cfg_path = folder_path + Path.DirectorySeparatorChar + CFG_FILE; } else { cfg_path = CFG_FILE; } if (!File.Exists(cfg_path)) { Utils.ConsWrite(DebugMSG_Type.always, "Application ended!!!! " + cfg_path + " file not found"); Console.WriteLine("Press any key to exit..."); Thread.Sleep(3000); System.Environment.Exit(0); } source = new IniConfigSource(cfg_path); gw_id = source.Configs["GATEWAY"].Get("id"); GPS_refresh = Convert.ToInt32(source.Configs["GATEWAY"].Get("GPS_trig_refresh")); rep_inter_default = Convert.ToInt32(source.Configs["GATEWAY"].Get("report")); gw_restart = Convert.ToBoolean(source.Configs["GATEWAY"].Get("gw_restart")); pop3Server = source.Configs["EmailService"].Get("Pop3Server"); smtpServer = source.Configs["EmailService"].Get("SmtpServer"); pop3Port = source.Configs["EmailService"].Get("Pop3Port"); smtpPort = source.Configs["EmailService"].Get("SmtpPort"); sslState = Convert.ToBoolean(source.Configs["EmailService"].Get("EnableSSL")); enableEmailService = Convert.ToBoolean(source.Configs["EmailService"].Get("Enable")); user = source.Configs["EmailService"].Get("User"); psw = source.Configs["EmailService"].Get("Pass"); //MySQL connection SERVER = source.Configs["MySQL"].Get("SERVER"); DATABASE = source.Configs["MySQL"].Get("DATABASE"); UID = source.Configs["MySQL"].Get("UID"); PASSWORD = source.Configs["MySQL"].Get("PASSWORD"); //debug port is GWID with the first digit replage by 3. ex: 95001 -> 35001 string str_debug_port = "3" + gw_id.Substring(1); //testmode testActive = Convert.ToBoolean(source.Configs["Test"].Get("active")); testFreq = Convert.ToInt32(source.Configs["Test"].Get("freq")); testLat = Convert.ToDouble(source.Configs["Test"].Get("startLat")); testLng = Convert.ToDouble(source.Configs["Test"].Get("startLng")); debug_port = Int32.Parse(str_debug_port); } catch (Exception ex) { Utils.ConsWrite(DebugMSG_Type.always, "LoadSetup() Exception: " + ex.ToString()); } Utils.ConsWrite(DebugMSG_Type.CTRL, "LoadSetup file OK !"); } } }