Example #1
0
        /// <summary>
        /// 다수이 데이터 파일을 생성하는 메소드
        /// </summary>
        /// <param name="datas"></param>
        /// <param name="fileName"></param>
        /// <param name="siteInfo"></param>
        private void MakeFile(List <FileDataStructure> datas, string fileName, SiteInfo siteInfo)
        {
            //1001801_년월일시분_Flux.dat, 1001801_년월일시분_30m.dat
            string ftpFileName = string.Empty;

            try
            {
                List <FileDataStructure> list = datas.OrderBy(data => data.dates).ToList();

                foreach (FileDataStructure data in list)
                {
                    //1001801_년월일시분_Flux.dat, 1001801_년월일시분_30m.dat
                    ftpFileName = _sftpDirectoryPath + siteInfo.SiteCode + "_" + data.dates.ToString("yyyyMMddHHmm") + "_" + data.type + ".dat";

                    using (StreamWriter writer = new StreamWriter(ftpFileName, false))
                    {
                        writer.Write(data.rowData);

                        _logDisplay.Display(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "," + ftpFileName + " 을 생성했습니다.");
                        log.Info(ftpFileName + " created");
                    }

                    Thread.Sleep(1);

                    using (StreamWriter writer = new StreamWriter(_directoryPath + siteInfo.DataFile, false))
                    {
                        writer.Write(siteInfo.SiteName + "," + siteInfo.SiteCode + "," + siteInfo.DataFile + "," + data.dates.ToString("yyyy-MM-dd HH:mm:ss"));
                        log.Info(siteInfo.SiteName + "," + siteInfo.SiteCode + "," + siteInfo.DataFile + "," + data.dates.ToString("yyyy-MM-dd HH:mm:ss") + " updated");
                    }
                    SitesInfoList.UpdateLastedDate(siteInfo.DataFile, data.dates);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                _logDisplay.Display(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "," + ex.Message + " 문제가 발생했습니다.");
            }
        }
        public bool TestConnect()
        {
            bool result = false;

            SftpClient sftp = null;

            //접속하기
            try
            {
                sftp = new SftpClient(FtpDirectoryInfo.SFTPHOST, int.Parse(FtpDirectoryInfo.STFPPORT), FtpDirectoryInfo.SFTPUSERNAME, FtpDirectoryInfo.SFTPPASSWORD);
                sftp.ConnectionInfo.Timeout = TimeSpan.FromSeconds(3);
                // SFTP 서버 연결
                sftp.Connect();

                _logDisplay.Display(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "," + FtpDirectoryInfo.SFTPHOST + " 에 접속했습니다.");
                log.Info(FtpDirectoryInfo.SFTPHOST + " connected");

                sftp.Disconnect();
                _logDisplay.Display(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "," + FtpDirectoryInfo.SFTPHOST + " 접속을 해제했습니다.");
                log.Info(FtpDirectoryInfo.SFTPHOST + " disconnected");
                result = true;
            }
            catch (Exception ex)
            {
                _logDisplay.Display(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "," + ex.Message + " 문제가 발생했습니다.");
                log.Error(ex.Message);
                result = false;
            }
            finally
            {
                if (sftp != null)
                {
                    sftp.Dispose();
                    sftp = null;
                }
            }

            return(result);
        }