示例#1
0
        /**
         * 수신 된 알람 정보를 데이터베이스에 등록한다.
         * 최신 1건 자료만 입력한다.
         */
        public bool almMessage(string msg, string clientIP)
        {
            bool result = false;

            logMsg("[ almMessage ] received msg : " + msg);

            // Database에 등록한다.
            MySqlCommand oCmd = null;
            string       sql  = "";

            try
            {
                using (MySqlConnection conn = ConnectionPool.Instance.getConnection())
                {
                    char[]   splitData = { ':' };
                    char[]   splitSt   = { '_' };
                    string[] arrMsg    = msg.Split(splitData);
                    string   host      = arrMsg[2];

                    string   st_time = "";
                    string[] arrTime = arrMsg[3].Split(splitSt);
                    st_time = String.Format("{0}/{1}/{2} {3}:{4}:{5}",
                                            arrTime[0], arrTime[1], arrTime[2], arrTime[3], arrTime[4], arrTime[5]
                                            );

                    sql = String.Format("INSERT INTO T_RCV_ALM_INFO (s_code, st_time, content, reg_dt) VALUES ('{0}', '{1}', '{2}', current_timestamp) "
                                        + " ON DUPLICATE KEY UPDATE st_time = '{3}', content = '{4}', reg_dt = current_timestamp ",
                                        arrMsg[1], st_time, arrMsg[4], st_time, arrMsg[4]
                                        );

                    oCmd = new MySqlCommand(sql, conn);
                    oCmd.ExecuteNonQuery();

                    // Client에 전송한다.
                    int localPort = System.Convert.ToInt32(ParamInitInfo.Instance.m_localPort);
                    int sndPort   = System.Convert.ToInt32(ParamInitInfo.Instance.m_clientRcvPort);

                    string sndMsg = "AM:" + arrMsg[1] + ":" + clientIP + ":ok";
                    byte[] buf    = Encoding.ASCII.GetBytes(sndMsg);

                    using (UdpClient c = new UdpClient(localPort))  // source port (로컬 포트에서 상태 포트를 하나 사용하므로 중복이 발생하므로 사용포트 - 1)
                    {
                        c.Send(buf, buf.Length, clientIP, sndPort);
                        logMsg("Send Msg [host : " + host + " : " + sndPort + " : " + sndMsg);
                    }
                }
            }
            catch (MySqlException e)
            {
                logMsg("almMessage error : " + e.Message);
                log.Log("almMessage error : " + e.Message);
            }

            return(result);
        }
示例#2
0
        /**
         * STA파일을 FDP에 전송한다.
         */
        public int sendStaDataToFtpServer()
        {
            // 데이터 날짜 체크
            string ftp_url = ftpUri + ftpHost + ":" + ftpPort + "/site" + m_stCode + "/" + mData.m_year + "/" + mData.m_mon + "/" + mData.m_day;  // + "/" + info.s_hour;

            if (FtpDirectoryExists(ftp_url) == false)
            {
                log.Log("FTP Server : Directory create error......" + ftp_url);
                return(0);
            }

            // sta 파일 전송
            // staFileName : 17_01_00_00.sta  => 13201_20170714010000.sta
            string tmpName1     = mData.staFileName.Replace("_", ""); // => 17010000.sta
            string ftpSaveFile1 = m_stCode + "_" + mData.m_year + mData.m_mon + mData.m_day + tmpName1.Substring(2);
            string ftpPath      = ftp_url + "/" + ftpSaveFile1;       //  mData.staFileName;

            //ftpPath = ftp_url + "/" + mData.staFileName;
            if (sendData(ftpPath, mData.staFullFileName))
            {
                mData.sendCount++;
            }


            // sta 파일 전송
            // string ftpPath = ftp_url + "/" + mData.staFileName;
            // if (sendData(ftpPath, mData.staFullFileName))
            // {
            //     mData.sendCount++;
            // }

            log.Log("[ FtpSend ] FTP URI : " + ftpPath);

            return(mData.sendCount);
        }
示例#3
0
 private void logMessage(ListBox _lstLog, string _msg)
 {
     try
     {
         if (_lstLog.InvokeRequired)     // 해당 컨트롤이 Invoke를 요구한다면
         {
             _lstLog.Invoke(new logMessageDelegate(logMessage), new object[] { _lstLog, _msg });
         }
         else
         {
             string sendTime = " [" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]";
             // lstLog.Items.Insert(0, sendTime + _msg); //  Add(msg);
             if (lstLog.Items.Count == 5000)
             {
                 lstLog.Items.RemoveAt(0);
             }
             lstLog.Items.Add(sendTime + _msg); //  Add(msg);
             lstLog.SelectedIndex = lstLog.Items.Count - 1;
         }
     }catch (Exception ex)
     {
         log.Log("[logMessage] error : " + ex.ToString());
     }
 }
示例#4
0
        /**
         * 데이터베이스 등록된 클라이언트 상태 정보가 주기적으로 데이터를 수신해서
         * 업데이트 되고 있는지 체크한다.
         * 없으면 상태를 0으로 업데이트 및 신규 등록한다.
         */
        public string[] getClientStatusInfo()
        {
            string[]     arrMsg  = new string[3];
            int[]        arrSts  = new int[3];
            string[]     arrCode = new string[3];
            MySqlCommand oCmd    = null;
            string       sql     = "";

            try
            {
                using (MySqlConnection conn = ConnectionPool.Instance.getConnection())
                {
                    sql  = "SELECT a.s_code, a.s_name, IFNULL(b.s_sts, 0) s_sts, DATE_FORMAT(IFNULL(b.reg_dt, now()), '%Y-%m-%d %H:%i:%s') reg_dt, ";
                    sql += "       IFNULL(DATE_FORMAT(b.reg_dt, '%Y-%m-%d %H:%i:%s'), '') as reg_dt2  ";
                    sql += "  FROM T_ST_CODE a LEFT JOIN T_CLI_STS_INFO b ";
                    sql += "    ON a.S_CODE = b.S_CODE";    //  AND b.REG_DT <= date_add(now(), interval - 2 minute) ";

                    oCmd = new MySqlCommand(sql, conn);
                    MySqlDataReader rs = oCmd.ExecuteReader();
                    int             i  = 0;
                    while (rs.Read())
                    {
                        arrCode[i] = rs.GetString("s_code");
                        arrSts[i]  = rs.GetInt32("s_sts");
                        string msg = "ST=" + arrCode[i] + "=" + arrSts[i] + "=" + rs.GetString("reg_dt2");
                        arrMsg[i] = msg;

                        // sts가 1일 경우 날짜 체크
                        DateTime currentDt = DateTime.Now.AddMinutes(-2);   // 2 Minute
                        DateTime dbDt      = DateTime.ParseExact(rs.GetString("reg_dt"), "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

                        int result = DateTime.Compare(dbDt, currentDt);
                        if (result <= 0)        // currentDt가 크다 : 시간내에 데이터가 수신되지 않는다.
                        {
                            arrSts[i] = 0;
                        }
                        else
                        {
                        }                       // currentDt가 작다.: 시간내에 데이터가 수신된다.

                        i++;
                    }
                    rs.Close();
                    rs   = null;
                    oCmd = null;

                    for (i = 0; i < 3; i++)
                    {
                        if (arrSts[i] == 0)
                        {
                            sql = String.Format("INSERT INTO T_CLI_STS_INFO (s_code, s_sts, upt_dt) VALUES ('{0}', '{1}', current_timestamp) "
                                                + " ON DUPLICATE KEY UPDATE s_sts = '{2}', upt_dt = current_timestamp ",
                                                arrCode[i], arrSts[i], arrSts[i]
                                                );
                            oCmd = new MySqlCommand(sql, conn);
                            oCmd.ExecuteNonQuery();
                        }
                    }
                }
            }
            catch (MySqlException e)
            {
                stsLog("StatusProcess::getClientStatusInfo error : " + e.Message);
                stsLog("[SQL] " + sql);
                log.Log("StatusProcess::getClientStatusInfo error : " + e.Message);
                log.Log("[SQL] " + sql);
            }
            return(arrMsg);
        }
示例#5
0
        /**
         * 파일전송 UDP 메시지를 수신한다.
         */
        public bool fileStsUpdate(string msg, string client_ip)
        {
            bool result = false;

            //FT:관측소ID:IP ADDR:시작시각:종료시각:파일개수:INI파일명:RAW파일명:RTD파일명:P1:P2:P3:P4:P5:P6:S  => START
            //FT:관측소ID:IP ADDR:시작시각:종료시각:총개수:파일명:E => END
            logMsg("[ FileProcess::fileStsUpdate ] received msg : " + msg);

            // Database에 등록한다.
            MySqlCommand oCmd = null;
            string       sql  = "";

            try
            {
                using (MySqlConnection conn = ConnectionPool.Instance.getConnection())
                {
                    char[]   splitData = { ':' };
                    string[] arrMsg    = msg.Split(splitData);

                    if (arrMsg[7] == "E")       // End Message
                    {
                        string st_time = "";
                        string et_time = "";
                        char[] splitSt = { '_' };


                        string[] arrTime1 = arrMsg[3].Split(splitSt);
                        st_time = String.Format("{0}-{1}-{2} {3}:{4}:{5}",
                                                arrTime1[0], arrTime1[1], arrTime1[2], arrTime1[3], arrTime1[4], arrTime1[5]
                                                );
                        string[] arrTime2 = arrMsg[4].Split(splitSt);
                        et_time = String.Format("{0}-{1}-{2} {3}:{4}:{5}",
                                                arrTime2[0], arrTime2[1], arrTime2[2], arrTime2[3], arrTime2[4], arrTime2[5]
                                                );

                        if (arrMsg[6] != "" && arrMsg[6].IndexOf("DBS") == -1)
                        {
                            sql = String.Format("UPDATE T_RCV_NOT_DBS_FILE set acc_file_cnt = {0} WHERE s_code = '{1}' and st_time='{2}' and et_time='{3}'",
                                                arrMsg[5], arrMsg[1], st_time, et_time
                                                );
                        }
                        else
                        {
                            sql = String.Format("UPDATE T_RCV_FILE set acc_file_cnt = {0} WHERE s_code = '{1}' and st_time='{2}' and et_time='{3}'",
                                                arrMsg[5], arrMsg[1], st_time, et_time
                                                );
                        }

                        logMsg(sql);
                        oCmd = new MySqlCommand(sql, conn);
                        oCmd.ExecuteNonQuery();

                        udpOkSend(arrMsg[1], arrMsg[2], client_ip);
                    }
                    else
                    {
                        log.Log("start File start...");
                        log.Log("arrMsg.Length : " + arrMsg.Length);

                        if (arrMsg.Length == 16)        // start message
                        {
                            string st_time = "";
                            string et_time = "";
                            char[] splitSt = { '_' };


                            string[] arrTime1 = arrMsg[3].Split(splitSt);
                            st_time = String.Format("{0}-{1}-{2} {3}:{4}:{5}",
                                                    arrTime1[0], arrTime1[1], arrTime1[2], arrTime1[3], arrTime1[4], arrTime1[5]
                                                    );
                            string[] arrTime2 = arrMsg[4].Split(splitSt);
                            et_time = String.Format("{0}-{1}-{2} {3}:{4}:{5}",
                                                    arrTime2[0], arrTime2[1], arrTime2[2], arrTime2[3], arrTime2[4], arrTime2[5]
                                                    );

                            if ((arrMsg[6] != "" && arrMsg[6].IndexOf("DBS") == -1) || (arrMsg[7] != "" && arrMsg[8].IndexOf("DBS") == -1) ||
                                (arrMsg[8] != "" && arrMsg[8].IndexOf("DBS") == -1))
                            {
                                // sts insert
                                sql = String.Format("insert into T_RCV_NOT_DBS_FILE (s_code, st_time, et_time, real_file_cnt, acc_file_cnt, err_chk, s_chk, srv_file_cnt, ini_name, raw_name, rtd_name, reg_dt) values"
                                                    + " ('{0}', '{1}', '{2}', '{3}', '{4}', 'N', 'N', 0,   '{5}', '{6}', '{7}',  current_timestamp ) ",
                                                    arrMsg[1], st_time, et_time, arrMsg[5], 0, arrMsg[6], arrMsg[7], arrMsg[8]
                                                    );
                                oCmd = new MySqlCommand(sql, conn);
                                oCmd.ExecuteNonQuery();
                            }
                            else   // DBS
                            {
                                // FILE insert
                                sql = String.Format("SELECT COUNT(S_CODE) as cnt FROM T_RCV_FILE WHERE S_CODE='{0}' AND ST_TIME='{1}' AND ET_TIME='{2}'",
                                                    arrMsg[1], st_time, et_time
                                                    );
                                oCmd = new MySqlCommand(sql, conn);
                                MySqlDataReader rs  = oCmd.ExecuteReader();
                                int             cnt = 0;
                                if (rs.Read())
                                {
                                    cnt = rs.GetInt32("cnt");
                                }
                                rs.Close();
                                rs   = null;
                                oCmd = null;

                                if (cnt == 0)       // Insert
                                {
                                    sql = String.Format("insert into T_RCV_FILE (s_code, st_time, et_time, real_file_cnt, acc_file_cnt, err_chk, s_chk, srv_file_cnt, ini_name, raw_name, rtd_name, reg_dt) values"
                                                        + " ('{0}', '{1}', '{2}', '{3}', '{4}', 'N', 'N', 0,   '{5}', '{6}', '{7}',  current_timestamp ) ",
                                                        arrMsg[1], st_time, et_time, arrMsg[5], 0, arrMsg[6], arrMsg[7], arrMsg[8]
                                                        );
                                }
                                else
                                {
                                    sql = String.Format("UPDATE T_RCV_FILE set real_file_cnt='{0}', acc_file_cnt='{1}', err_chk='{2}', s_chk='{3}', srv_file_cnt='{4}', ini_name='{5}', raw_name='{6}', rtd_name='{7}'"
                                                        + " WHERE s_code='{8}' and st_time='{9}' and et_time='{10}'",
                                                        arrMsg[5], 0, 'N', 'N', 0, arrMsg[6], arrMsg[7], arrMsg[8], arrMsg[1], st_time, et_time
                                                        );
                                }
                                oCmd = new MySqlCommand(sql, conn);
                                oCmd.ExecuteNonQuery();
                                //log.Log(sql);

                                try
                                {
                                    // 파라미터가 널이 될 수 있다.
                                    // ini insert
                                    sql = String.Format("insert into T_RCV_PARAM_INFO (s_code, st_time, et_time, p_type, p_pam1, p_pam2, p_pam3, p_pam4, avt_tm, reg_dt) values"
                                                        + " ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', current_timestamp ) "
                                                        + " ON DUPLICATE KEY "
                                                        + " UPDATE p_pam1='{9}', p_pam2='{10}', p_pam3='{11}', p_pam4='{12}', avt_tm='{13}'",
                                                        arrMsg[1], st_time, et_time, arrMsg[9], arrMsg[10], arrMsg[11], arrMsg[12], arrMsg[13], arrMsg[14],
                                                        arrMsg[10], arrMsg[11], arrMsg[12], arrMsg[13], arrMsg[14]
                                                        );
                                    oCmd = new MySqlCommand(sql, conn);
                                    oCmd.ExecuteNonQuery();
                                }catch (MySqlException ex)
                                {
                                    log.Log("[FileProcess::fileStsUpdate] inner error : " + ex.Message);
                                    logMsg("[FileProcess::fileStsUpdate] inner error : " + ex.Message);
                                }
                            }

                            udpOkSend(arrMsg[1], arrMsg[2], client_ip);
                        }
                        else
                        {
                            log.Log("[ FileProcess::fileStsUpdate ] received error msg : " + msg);
                            logMsg("[ FileProcess::fileStsUpdate ] received error msg : " + msg);
                            result = false;
                        }
                    }

                    result = true;
                }
            }
            catch (MySqlException e)
            {
                log.Log("[FileProcess::fileStsUpdate] error : " + e.Message);
                logMsg("[FileProcess::fileStsUpdate] error : " + e.Message);
                Console.WriteLine(e.Message);

                result = false;
            }

            return(result);
        }