Example #1
0
        /**
         * FTP Server에 데이터를 전송한다.
         */
        public bool ftpSendData(StsInfo info)
        {
            bool result = false;

            sendInfo             = new SndDataInfo();
            sendInfo.mode        = info.mode;
            sendInfo.iniFileName = "";
            sendInfo.rawFileName = "";
            sendInfo.rtdFileName = "";
            Console.WriteLine("ftpSendData mode : " + sendInfo.mode);

            try
            {
                // FTP 전송할 파일을 읽어 들인다.
                bool ok = HasWritePermissionOnDir(info);

                if (ok == true)
                {
                    setSendData(sendInfo);

                    int sendCount = sendDataToFtpServer();      // FTP에 전송하고 전송된 개수를 리턴 받는다.

                    info.srv_file_cnt = sendCount;

                    if (databaseSendUpdate(info) == true)
                    {
                        logMsg("[ftpSendData] The data is successfully updated.[" + info.s_code + "]");

                        if (FileMoveProcess(info) == true)
                        {
                            logMsg("[ftpSendData] The data is successfully moved in the backup directory.[" + info.s_code + "]");
                            result = true;
                        }
                        else
                        {
                            logMsg("[ftpSendData] The job moving to the backup directory is not successed.[" + info.s_code + "]");
                            result = false;
                        }
                    }
                    else
                    {
                        logMsg("[ftpSendData] The update is not successed.[" + info.s_code + "]");

                        result = false;
                    }
                }
                else
                {
                    logMsg("[ftpSendData] File is not exists...[" + info.s_code + "]");
                    result = false;
                }
            }
            catch (Exception ex)
            {
                logMsg("[ftpSendData] " + ex.ToString());
                result = false;
            }
            return(result);
        }
        /**
         * 데이터베이스에 주기적으로 접속해서 데이터를 가져와서
         * FDP전송하고 데이터베이스에 다시 업데이트를 수행한다.
         * 쓰레드 함수
         */
        public void WindLidarDataProcess()
        {
            while (!isShutdown)
            {
                int found = 0;
                if (isShutdown == false)
                {
                    waitHandle.Reset();
                    // 데이터베이스에 접속해서 데이터를 가져온다.
                    try
                    {
                        // 하나의 Row 가져오기
                        StsInfo fileData = ftsProcess.getRcvDataInfo();

                        if (fileData != null)
                        {
                            fileData.mode = 1;
                            // FTP 전송 - need module
                            ftsProcess.setFtpInfo(fileData.s_code, FTP_URI, ParamInitInfo.Instance.m_ftpIP, ParamInitInfo.Instance.m_ftpPort,
                                                  ParamInitInfo.Instance.m_ftpUser, ParamInitInfo.Instance.m_ftpPass);
                            bool sts = ftsProcess.ftpSendData(fileData);

                            if (sts == false)
                            {
                                Console.WriteLine("[WindLidarDataProcess] ftpSendData false...........[" + fileData.s_code + "]");
                                ftsProcess.ftpFailUpdate(fileData);
                                found = 0;
                            }
                            else
                            {
                                found = 1;
                            }
                        }
                        else
                        {
                            Console.WriteLine("[WindLidarDataProcess]The transfer data is not found .......");
                            found = 0;
                        }
                    }
                    catch (MySqlException e)
                    {
                        log("[ ProcessReceiver::WindLidarDataProcess(error) ] Error : " + e.Message);
                    }
                    if (found == 0)
                    {
                        waitHandle.WaitOne(1000 * System.Convert.ToInt16(ParamInitInfo.Instance.m_ftpThreadTime));  // 1 minute ( need setup)
                    }
                    else
                    {
                        waitHandle.WaitOne(1000 * 2);   // 10 seconds
                    }
                }
            }
        }
        public void StaThreadProcess()
        {
            while (!isShutdown)
            {
                int found = 0;
                if (isShutdown == false)
                {
                    staHandle.Reset();
                    // 데이터베이스에 접속해서 데이터를 가져온다.
                    try
                    {
                        StsInfo fileData = atsProcess.getStaRcvDataInfo();
                        if (fileData != null)
                        {
                            fileData.mode = 0;
                            // FTP 전송 - need module
                            atsProcess.setFtpInfo(fileData.s_code, FTP_URI, ParamInitInfo.Instance.m_ftpIP, ParamInitInfo.Instance.m_ftpPort,
                                                  ParamInitInfo.Instance.m_ftpUser, ParamInitInfo.Instance.m_ftpPass);

                            bool sts = atsProcess.ftpStaSendData(fileData);

                            if (sts == false)
                            {
                                Console.WriteLine("[StaThreadProcess] ftpSendData false...........[" + fileData.s_code + "]");
                                log("[StaThreadProcess] ftpSendData false...........[" + fileData.s_code + " : " + fileData.no + "]");
                                atsProcess.ftpFailUpdate(fileData);
                            }
                            found = 1;
                        }
                        else
                        {
                            Console.WriteLine("[StaThreadProcess] The transfer data is not found .......");
                            found = 0;
                        }
                    }
                    catch (MySqlException e)
                    {
                        log("[ ProcessReceiver::StaThreadProcess(error) ] Error : " + e.Message);
                    }
                    if (found == 0)
                    {
                        staHandle.WaitOne(1000 * System.Convert.ToInt16(ParamInitInfo.Instance.m_staThreadTime));       // 1 min
                    }
                    else
                    {
                        // 처리할 데이터가 있을 수 있다.
                        staHandle.WaitOne(1000 * 8);    // 10 seconds
                    }
                }
            }
        }
Example #4
0
        private void refreshWindow()
        {
            try
            {
                for (int i = 0; i < stList.Count(); i++)
                {
                    StsInfo item = stList[i];

                    if (item.s_code == "13211")       // 일산
                    {
                        UpdateRadioStsA(item.s_sts);
                        UpdateLableStaLastTime(item.s_lastDt);
                    }
                    if (item.s_code == "13210")       // 송도
                    {
                        UpdateRadioStsB(item.s_sts);
                        UpdateLableStbLastTime(item.s_lastDt);
                    }
                    if (item.s_code == "13206")       //구로
                    {
                        UpdateRadioStsC(item.s_sts);
                        UpdateLableStcLastTime(item.s_lastDt);
                    }
                }
                for (int i = 0; i < ftList.Count(); i++)
                {
                    FtsInfo ftm = ftList[i];

                    if (ftm.s_code == "13211")       // 일산
                    {
                        UpdateLableFtaLastTime(ftm.s_lastDt);
                    }
                    if (ftm.s_code == "13210")       // 송도
                    {
                        UpdateLableFtbLastTime(ftm.s_lastDt);
                    }
                    if (ftm.s_code == "13206")       //구로
                    {
                        UpdateLableFtcLastTime(ftm.s_lastDt);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Log("[refreshWindow] error : " + ex.ToString());
            }
        }
Example #5
0
        /**
         * 데이터베이스를 조회해서 StsInfo 구조체에 데이터를 담아서 리턴한다.
         */
        public StsInfo getRcvDataInfo()
        {
            MySqlCommand oCmd    = null;
            StsInfo      stsInfo = null;
            string       sql     = "";

            try
            {
                using (MySqlConnection conn = ConnectionPool.Instance.getConnection())
                {
                    // 작업처리하지 않은건(s_chk='N')과 받은 파일 개수가 0개 이상인 건을 조회해서 작업을 수행한다.
                    sql  = "select no, 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 from T_RCV_FILE ";
                    sql += " where s_chk='N' and acc_file_cnt > 0 and err_chk = 'N' order by reg_dt asc limit 0, 1";

                    oCmd = new MySqlCommand(sql, conn);
                    MySqlDataReader rs = oCmd.ExecuteReader();
                    while (rs.Read())
                    {
                        stsInfo               = new StsInfo();
                        stsInfo.no            = rs.GetInt32("no");
                        stsInfo.s_code        = rs.GetString("s_code");
                        stsInfo.st_time       = rs.GetString("st_time");
                        stsInfo.et_time       = rs.GetString("et_time");
                        stsInfo.read_file_cnt = rs.GetInt32("real_file_cnt");
                        stsInfo.acc_file_cnt  = rs.GetInt32("acc_file_cnt");
                        stsInfo.err_chk       = rs.GetString("err_chk");
                        stsInfo.s_chk         = rs.GetString("s_chk");
                        stsInfo.srv_file_cnt  = rs.GetInt32("srv_file_cnt");
                        stsInfo.ini_name      = rs.GetString("ini_name");
                        stsInfo.raw_name      = rs.GetString("raw_name");
                        stsInfo.rtd_name      = rs.GetString("rtd_name");
                        stsInfo.mode          = 1;
                    }
                    rs.Close();
                    rs   = null;
                    oCmd = null;
                }
            }
            catch (MySqlException e)
            {
                log.Log("[FileProcess::getRcvDataInfo] error : " + e.Message);
                logMsg("[FileProcess::getRcvDataInfo] error : " + e.Message);
            }

            return(stsInfo);
        }
Example #6
0
        public void stsDB(string msg)
        {
            try
            {
                if (msg == null)
                {
                    return;
                }
                string[] msgArr = msg.Split(delimiterChar2);

                string  stCode  = msgArr[1];
                string  stSts   = msgArr[2];
                string  rcvTime = msgArr[3];
                StsInfo item    = new StsInfo();
                item.s_code   = stCode;
                item.s_sts    = stSts;
                item.s_lastDt = rcvTime;
                if (stList.Count() == 0)
                {
                    stList.Add(item);
                }
                else
                {
                    int found = 0;
                    for (int i = 0; i < stList.Count(); i++)
                    {
                        if (stList[i].s_code == item.s_code)
                        {
                            stList[i] = item;
                            found     = 1;
                        }
                    }
                    if (found == 0)
                    {
                        stList.Add(item);   // new
                    }
                }

                refreshWindow();
            }
            catch (Exception ex)
            {
                log.Log("[stsDB] error : " + ex.ToString());
            }
        }
Example #7
0
        //private delegate void stsMessageDelegate(ListBox _lstLog, string _msg);

        public void stsMessage(string msg)
        {
            try
            {
                string[] msgArr = msg.Split(delimiterChar);

                string  stCode  = msgArr[1];
                string  stSts   = msgArr[2];
                string  rcvTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                StsInfo item    = new StsInfo();
                item.s_code   = stCode;
                item.s_sts    = stSts;
                item.s_lastDt = rcvTime;
                if (stList.Count() == 0)
                {
                    stList.Add(item);
                }
                else
                {
                    int found = 0;
                    for (int i = 0; i < stList.Count(); i++)
                    {
                        if (stList[i].s_code == item.s_code)
                        {
                            stList[i] = item;
                            found     = 1;
                        }
                    }
                    if (found == 0)
                    {
                        stList.Add(item);   // new
                    }
                }

                refreshWindow();
            }
            catch (Exception ex)
            {
                log.Log("[stsMessage] error : " + ex.ToString());
            }
        }
Example #8
0
        public bool ftpFailUpdate(StsInfo info)
        {
            bool result = false;

            logMsg("[ ftpFailUpdate::databaseSendUpdate ] database updated => " + info.s_code + "[" + info.srv_file_cnt + "]");

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

            try
            {
                using (MySqlConnection conn = ConnectionPool.Instance.getConnection())
                {
                    if (info.mode == 0)
                    {
                        sql = String.Format("update T_RCV_STA set err_chk='Y', upt_dt=current_timestamp where no={0}", info.no);
                    }
                    else if (info.mode == 1)  // DBS
                    {
                        sql = String.Format("update T_RCV_FILE set err_chk='Y', upt_dt=current_timestamp where no={0}", info.no);
                    }
                    else if (info.mode == 2) // NOT DBS
                    {
                        sql = String.Format("update T_RCV_NOT_DBS_FILE set err_chk='Y', upt_dt=current_timestamp where no={0}", info.no);
                    }
                    oCmd = new MySqlCommand(sql, conn);
                    oCmd.ExecuteNonQuery();
                    result = true;
                }
            }
            catch (MySqlException e)
            {
                logMsg("[ftpFailUpdate::databaseSendUpdate] error : " + e.Message);
                logMsg("[SQL] " + sql);
                result = false;
            }

            return(result);
        }
Example #9
0
        /**
         * 파일이 존재하면 이동할 때 삭제를 하고 이동할 것인지를 결정해야 한다.
         */
        public bool FileMoveProcess(StsInfo info)
        {
            var result = false;

            try
            {
                string year = info.st_time.Substring(0, 4);
                string mon  = info.st_time.Substring(5, 2);
                string day  = info.st_time.Substring(8, 2);

                string dataPath   = Path.Combine(m_sourceDir, info.s_code, year, mon, day);
                string backupPath = Path.Combine(m_backupDir, info.s_code, year, mon, day);


                // 디렉토리 내에 파일이 존재하는지 체크한다.
                if (Directory.Exists(backupPath) == false)
                {
                    // directory 생성
                    // 디렉토리 생성
                    string        path = m_backupDir + "\\" + info.s_code;
                    DirectoryInfo dir1 = new DirectoryInfo(path);
                    if (dir1.Exists == false)
                    {
                        dir1.Create();
                    }

                    path = path + "\\" + year;
                    DirectoryInfo dir2 = new DirectoryInfo(path);
                    if (dir2.Exists == false)
                    {
                        dir2.Create();
                    }

                    path = path + "\\" + mon;
                    DirectoryInfo dir3 = new DirectoryInfo(path);
                    if (dir3.Exists == false)
                    {
                        dir3.Create();
                    }

                    path = path + "\\" + day;
                    DirectoryInfo dir4 = new DirectoryInfo(path);
                    if (dir4.Exists == false)
                    {
                        dir4.Create();
                    }
                }
                string destFileName = "";
                if (info.mode == 1)
                {
                    // Ini 파일 이동
                    if (sendInfo.iniFileName != "")
                    {
                        destFileName = Path.Combine(backupPath, sendInfo.iniFileName);
                        if (File.Exists(destFileName))
                        {
                            File.Delete(destFileName);
                        }
                        FileInfo iniFile = new FileInfo(sendInfo.iniFullFileName);
                        iniFile.MoveTo(destFileName);
                    }
                    // rtd 파일 이동
                    if (sendInfo.rtdFileName != "")
                    {
                        destFileName = Path.Combine(backupPath, sendInfo.rtdFileName);
                        if (File.Exists(destFileName))
                        {
                            File.Delete(destFileName);
                        }
                        FileInfo rtdFile = new FileInfo(sendInfo.rtdFullFileName);
                        rtdFile.MoveTo(destFileName);
                    }
                    // raw 파일 이동
                    if (sendInfo.rawFileName != "")
                    {
                        destFileName = Path.Combine(backupPath, sendInfo.rawFileName);
                        if (File.Exists(destFileName))
                        {
                            File.Delete(destFileName);
                        }
                        FileInfo rawFile = new FileInfo(sendInfo.rawFullFileName);
                        rawFile.MoveTo(destFileName);
                    }
                }
                else
                {
                    // sta 파일 이동
                    destFileName = Path.Combine(backupPath, sendInfo.staFileName);
                    if (File.Exists(destFileName))
                    {
                        File.Delete(destFileName);
                    }
                    FileInfo staFile = new FileInfo(sendInfo.staFullFileName);
                    staFile.MoveTo(destFileName);
                }
                result = true;
            }
            catch (IOException ex)
            {
                logMsg("[FileProcess::FileMoveProcess] error : " + ex.ToString());
                Console.WriteLine(ex.ToString());
                result = false;
            }

            return(result);
        }
Example #10
0
        /**
         * FTP Server에 데이터를 업로드 할 수 있는지 체크한다.
         * 라이다에서 데이터를 쓰고 있으면 FTP Server에 데이터를 전송하면 안된다.
         * path : FTP root directory (D:\ftp_user\site_code)
         * SndDataInfo 클래스에 담는다.
         */
        public bool HasWritePermissionOnDir(StsInfo info)
        {
            clear();

            // 구조체에서 파일 정보를 얻는다.
            // 10_08_55_00.sta
            // yyyy-mm-dd
            //public string f_name;
            //public string ini_name;
            //public string raw_name;
            //public string rtd_name;

            string year = info.et_time.Substring(0, 4);
            string mon  = info.et_time.Substring(5, 2);
            string day  = info.et_time.Substring(8, 2);

            string dataPath = Path.Combine(m_sourceDir, info.s_code, year, mon, day);

            sendInfo.path   = dataPath;
            sendInfo.m_year = year;
            sendInfo.m_mon  = mon;
            sendInfo.m_day  = day;

            try
            {
                // 디렉토리 내에 파일이 존재하는지 체크한다.
                if (Directory.Exists(dataPath) == false)
                {
                    Console.WriteLine("Directory not exist.... : {0}", dataPath);
                    logMsg("[FileProcess::HasWritePermissionOnDir] Directory not exist.... : " + dataPath);
                    log.Log("[FileProcess::HasWritePermissionOnDir] Directory not exist.... : " + dataPath);
                    return(false);
                }

                Console.WriteLine("HasWritePermissionOnDir mode => " + info.mode);
                // sta check
                if (info.mode == 0)     // STA
                {
                    string stsFull = Path.Combine(dataPath, info.f_name);

                    if (File.Exists(stsFull))
                    {
                        sendInfo.staFileName     = info.f_name;
                        sendInfo.staFullFileName = stsFull;
                        sendInfo.fileCount++;
                    }
                    else
                    {
                        Console.WriteLine("HasWritePermissionOnDir file not exist [error] : " + stsFull);
                        log.Log("HasWritePermissionOnDir file not exist [error] : " + stsFull);
                        return(false);
                    }
                }
                else
                {
                    // ini check
                    string iniFull = Path.Combine(dataPath, info.ini_name);
                    if (File.Exists(iniFull))
                    {
                        sendInfo.iniFileName     = info.ini_name;
                        sendInfo.iniFullFileName = iniFull;
                        sendInfo.fileCount++;
                    }
                    else
                    {
                        Console.WriteLine("HasWritePermissionOnDir file not exist [error] : " + iniFull);
                        log.Log("HasWritePermissionOnDir file not exist [error] : " + iniFull);
                        //return false;
                    }
                    // raw check
                    string rawFull = Path.Combine(dataPath, info.raw_name);
                    if (File.Exists(rawFull))
                    {
                        sendInfo.rawFileName     = info.raw_name;
                        sendInfo.rawFullFileName = rawFull;
                        sendInfo.fileCount++;
                    }
                    else
                    {
                        Console.WriteLine("HasWritePermissionOnDir file not exist [error] : " + rawFull);
                        log.Log("HasWritePermissionOnDir file not exist [error] : " + rawFull);
                        // return false;
                    }

                    if (info.rtd_name != "")
                    {
                        // rtd check
                        string rtdFull = Path.Combine(dataPath, info.rtd_name);
                        if (File.Exists(rtdFull))
                        {
                            sendInfo.rtdFileName     = info.rtd_name;
                            sendInfo.rtdFullFileName = rtdFull;
                            sendInfo.fileCount++;
                        }
                        else
                        {
                            Console.WriteLine("HasWritePermissionOnDir file not exist [error] : " + rtdFull);
                            log.Log("HasWritePermissionOnDir file not exist [error] : " + rtdFull);
                            //return false;
                        }
                    }
                }
            }catch (Exception ex)
            {
                log.Log("HasWritePermissionOnDir error : " + ex.ToString());
                return(false);
            }
            return(true);
        }