static void Main(string[] args) { // 读取文件 { StreamReader sr = new StreamReader("data/config.json", System.Text.Encoding.GetEncoding("utf-8")); string config = sr.ReadToEnd().ToString(); sr.Close(); ConfigEntity.getInstance().data = JsonConvert.DeserializeObject <ConfigData>(config); } if (true) { var configData = ConfigEntity.getInstance().data; Socket_S.getInstance().Start("0.0.0.0", configData.server_port); Socket_S.getInstance().m_onSocketEvent_Receive = OnReceive; { // 用API安装事件处理 ConsoleCtrlDelegate newDelegate = new ConsoleCtrlDelegate(HandlerRoutine); bool bRet = SetConsoleCtrlHandler(newDelegate, true); if (bRet == false) { // 安装关闭事件失败 } else { // 安装关闭事件成功 } } // 打开数据库 // MySqlUtil.getInstance().openDatabase(); } Console.ReadKey(); Console.ReadKey(); Console.ReadKey(); Console.ReadKey(); Console.ReadKey(); Console.ReadKey(); Console.ReadKey(); }
// 打开数据库 public void openDatabase() { try { var configData = ConfigEntity.getInstance().data; string conn = string.Format("Data Source= {0}; Port= {1} ; User ID = {2} ; Password = {3} ; DataBase = {4} ; Charset = utf8;", configData.sql_ip, configData.sql_port, configData.user, configData.password, configData.databaseName); m_mySqlConnection = new MySqlConnection(conn); //进行数据库连接 m_mySqlConnection.Open(); CommonUtil.Log("数据库打开成功"); startCmdThread(); // 定时请求数据库,防止断开 //TimerUtil.start(configData.timerReqSql * 1000, startDingShiReq); } catch (Exception ex) { CommonUtil.Log(ex); } }