Beispiel #1
0
        private DataTable GetFromFtp()
        {
            DataTable dt = null;

            logger.DebugFormat("IP: [{0}], Port: [{1}], User: [{2}]", etlSetting.IP, etlSetting.Port, etlSetting.UserName);

            FtpProxy ftPxy = new FtpProxy(etlSetting.IP, etlSetting.Port, etlSetting.UserName, etlSetting.Pwd);

            logger.InfoFormat("Download file : {0}", etlSetting.FileLocal);

            byte[] datas = ftPxy.Download(etlSetting.FileLocal);
            logger.DebugFormat("Downloaded file size : {0}", datas.Length);

            string str   = System.Text.Encoding.Default.GetString(datas);
            string fiFor = etlSetting.FileFormat.ToUpper();

            logger.InfoFormat("Source file format : {0}", fiFor);
            try
            {
                if (fiFor == "JSON")
                {
                    dt = JsonFormater.ConvertToDataTable(str, etlSetting.DbTimeColumn);
                }
                else if (fiFor == "CSV")
                {
                    dt = CsvFormater.ConvertToDataTable(str, etlSetting.DbTimeColumn);
                }

                if (dt == null)
                {
                    throw new Exception("Convert the DataTable is null.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Source file convert to DataTable fail.", ex);
            }


            logger.DebugFormat("Convert to DataTable row count : {0}", dt.Rows.Count);

            return(dt);
        }
Beispiel #2
0
 public void TestDownloadFile()
 {
     ftpPxy.Download("/EDSA/Json_UB2GG4200370C01_20161014212733.txt", "Temp/Json_UB2GG4200370C01_20161014212733.txt");
     Assert.IsTrue(File.Exists("Temp/Json_UB2GG4200370C01_20161014212733.txt"));
     File.Delete("Temp/Json_UB2GG4200370C01_20161014212733.txt");
 }