예제 #1
0
 private void CloseServer()
 {
     if (login_Server != null)
     {
         login_Server = null;
     }
     if (login_Agent != null)
     {
         login_Agent = null;
     }
 }
예제 #2
0
        private void Main_Load(object sender, EventArgs e)
        {
            //로그 디렉토리 없으면 생성
            if (!Directory.Exists("./log"))
            {
                Directory.CreateDirectory("./log");
            }

            if (!File.Exists("Svrinfo.ini"))
            {
                MessageBox.Show("Svrinfo.ini not found!", "Login Agent", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (g_Config.Init(@".\SvrInfo.ini"))
            {
                try
                {
                    lbPortStatus.Text = g_Config.LAPort.ToString();

                    login_Agent                 = new LoginAgent();
                    login_Agent.PrintLogs      += UpdateLogMsg;
                    login_Agent.WriteLogs      += WriteLogs;
                    login_Agent.PrintPCID      += UpdateUidNumber;
                    login_Agent.WriteNewPacket += WriteNewPacket;

                    login_Server               = new LoginServer();
                    login_Server.PrintLogs    += UpdateLogMsg;
                    login_Server.WriteLogs    += WriteLogs;
                    login_Server.PrintPCID    += UpdateUidNumber;
                    login_Server.UpdateStatus += UpdateStatus;

                    //if (new LoginAgent(this).Start() && new LoginServer(this).Start())
                    if (login_Server.Start() && login_Agent.Start())
                    {
                        //DB연결 확인: getdate()
                        SqlClient dbInfo = new SqlClient();
                        if (dbInfo.isConnectable())
                        {
                            UpdateLogMsg(string.Format("{0}:Connected", g_Config.DBinfo.ConnInfo));

                            if (dbInfo.isExistsTable(g_Config.DBinfo.Table))
                            {
                                bool isExists = true;
                                for (int i = 0; i < g_Config.DBinfo.Column.Length; i++)
                                {
                                    if (!dbInfo.isExistsColumn(g_Config.DBinfo.Column[i], g_Config.DBinfo.Table))
                                    {
                                        UpdateLogMsg(string.Format("There is no '{0}' column in the Table", g_Config.DBinfo.Column[i]));
                                        isExists = false;
                                    }
                                }

                                if (isExists)
                                {
                                    UpdateLogMsg("===== LOGIN AGENT START =====");
                                }
                                else
                                {
                                    UpdateLogMsg("===== LOGIN AGENT START ERROR =====");
                                    CloseServer();
                                }
                            }
                            else
                            {
                                UpdateLogMsg(string.Format("There is no '{0}' table in the DB", g_Config.DBinfo.Table));
                                UpdateLogMsg("===== LOGIN AGENT START ERROR =====");
                                CloseServer();
                            }
                        }
                        else
                        {
                            UpdateLogMsg(string.Format("{0}:Disconnected", g_Config.DBinfo.ConnInfo));
                            UpdateLogMsg("===== LOGIN AGENT START ERROR =====");
                            CloseServer();
                        }
                        dbInfo = null;
                    }
                    else
                    {
                        UpdateLogMsg("===== LOGIN AGENT START ERROR =====");
                        CloseServer();
                    }
                }
                catch (Exception ex)
                {
                    UpdateLogMsg("===== LOGIN AGENT START ERROR =====");
                    WriteLogs(string.Format("Agent Start error: {0}" + ex));
                }
            }
            else
            {
                UpdateLogMsg("=== Initialization Error ===");
            }
        }