private static void RunProcess() { Config config = Config.Get(); delay = config?.Timer ?? 1.0; if (config != null) { /* config db */ Database db = new Database(config); /* config server */ Server server = new Server(config); if (db.IsConnected() && server.IsConnected()) /* check ftp server */ { DataTable dt = db.GetData(); if (dt != null) { string csvText = dt.ConvertDataTableToCSVText(); /* get data from sql server */ string localFileName = FileFunction.WriteCSVFile(csvText, config.FileName); /* create tmp csv file */ bool isUploaded = server.Upload(localFileName); /* upload csv file to ftp server */ if (isUploaded) { FileFunction.DeleteCSVFile(localFileName); /* delete tmp file */ } } } } }
public static Config Get() { Config config = new Config(); /* read config */ string configPath = Path.Combine(Environment.CurrentDirectory, Constants.CONFIG_FILENAME); config = FileFunction.LoadJsonFile<Config>(configPath); /* config error */ if (config == null) Message.Show("Unable to read config file.", Constants.EMessage.ERROR); if (string.IsNullOrEmpty(config.FileName)) config.FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff"); if (config.Timer < 0.01) config.Timer = 1; /* config success */ Message.Show("Readed config file.", Constants.EMessage.INFO); return config; }