예제 #1
0
        public void JsonFormaterTest()
        {
            string    str = "[{\"id\":\"1\",\"name\":\"id1\",\"Time\":\"2016-10-10 00:00:00\"},{\"id\":\"2\",\"name\":\"id2\",\"Time\":\"2016-10-10 00:00:00\"}]";
            DataTable dt  = JsonFormater.ConvertToDataTable(str, "Time", "yyyy-MM-dd HH:mm:ss");

            Console.WriteLine(dt.Columns[2].DataType);
            Assert.AreEqual(dt.Columns[2].DataType, typeof(DateTime));
            //if (dt.Columns[2].DataType == typeof(DateTime)
            Assert.AreEqual(dt.Columns.Count, 3, "Column count no match");
            Assert.AreEqual(dt.Rows.Count, 2, "Row count no match");

            string str2 = JsonFormater.ConvertToString(dt);

            Assert.AreEqual <string>(str, str2, "DataTable to string data error.");
        }
예제 #2
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);
        }
예제 #3
0
        public void Input(DataTable srcTb)
        {
            logger.Info("----- FileTarget.Input Start -----");
            string data = "";

            logger.DebugFormat("Target file format : [{0}]", etlSetting.FileFormat);
            if (etlSetting.FileFormat.ToUpper() == "JSON")
            {
                data = JsonFormater.ConvertToString(srcTb);
            }

            logger.DebugFormat("Target IP: [{0}], Port: [{1}], User: [{2}]", etlSetting.IP, etlSetting.Port, etlSetting.UserName);
            if (etlSetting.IP.StartsWith("ftp:"))
            {
                FtpProxy ftpPxy    = new FtpProxy(etlSetting.IP, etlSetting.Port, etlSetting.UserName, etlSetting.Pwd);
                byte[]   databytes = System.Text.Encoding.Default.GetBytes(data);
                logger.InfoFormat("Upload data length : {0}", databytes.Length);
                ftpPxy.Upload(etlSetting.FileLocal, databytes);
            }

            logger.Info("----- FileTarget.Input End -----");
        }
예제 #4
0
        public static Test GetRESTResponse(Models.RESTRequest request, User user)
        {
            var restClient = new RestClientController()
            {
                EndPoint    = request.EndPoint,
                Method      = request.Method,
                PostData    = request.PostData,
                ContentType = request.ContentType
            };
            var response   = restClient.ProcessRequest();
            var resultJson = JsonFormater.FormatJson(response.Item2);
            var testcase   = new Test
            {
                Request        = request.PostData,
                Response       = resultJson,
                ProcessingTime = response.Item1,
                UserId         = user.Id,
                Uri            = request.EndPoint,
                ServiceName    = user.ServiceName
            };

            return(testcase);
        }