static void Main(string[] args) { CommandArgs commandArgs = CommandLine.Parse(args); // 遍历,某个目录 Logger Log = LogManager.GetCurrentClassLogger(); //HDF5_Convert(@"D:\test.h5", @"D:\Users\Kan\Documents\GitHub\QuantBox.DataReceiver\bin\Debug\IF1509", Log); //return; string DataPath = ConfigurationManager.AppSettings[KEY_DataPath]; string OutputPath_TradingDay = ConfigurationManager.AppSettings[KEY_OutputPath_TradingDay]; string OutputPath_Instrument = ConfigurationManager.AppSettings[KEY_OutputPath_Instrument]; string DefaultExchange = ConfigurationManager.AppSettings[KEY_DefaultExchange]; string SevenZipExePath = ConfigurationManager.AppSettings[KEY_SevenZipExePath]; bool Clear_DataPath = bool.Parse(commandArgs.ArgPairs.ContainsKey(KEY_Clear_DataPath) ? commandArgs.ArgPairs[KEY_Clear_DataPath] : ConfigurationManager.AppSettings[KEY_Clear_DataPath]); bool Clear_OutputPath_TradingDay = bool.Parse(commandArgs.ArgPairs.ContainsKey(KEY_Clear_OutputPath_TradingDay) ? commandArgs.ArgPairs[KEY_Clear_OutputPath_TradingDay] : ConfigurationManager.AppSettings[KEY_Clear_OutputPath_TradingDay]); //string HDF5_TradingDay = ConfigurationManager.AppSettings[KEY_HDF5_TradingDay]; HashSet <string> Set_TradingDay = new HashSet <string>(); // 遍历源数据目录下的所有文件 var files = new DirectoryInfo(DataPath).GetFiles("*", SearchOption.AllDirectories); foreach (var f in files) { string exchange = string.Empty; string product = string.Empty; string instrument = string.Empty; string symbol = string.Empty; string date = string.Empty; // 解析文件名 if (PathHelper.SplitFileName(f.Name, out exchange, out product, out instrument, out date)) { if (string.IsNullOrEmpty(exchange)) { exchange = DefaultExchange; } DirectoryInfo DI_TradingDay = new DirectoryInfo(Path.Combine(OutputPath_TradingDay, date)); if (!DI_TradingDay.Exists) { DI_TradingDay.Create(); } string Path_TradingDay = Path.Combine(DI_TradingDay.FullName, f.Name); // 将当前目录下内容复制到指定日期目录 File.Copy(f.FullName, Path_TradingDay, true); { DirectoryInfo DI_Instrument = new DirectoryInfo(Path.Combine(OutputPath_Instrument, exchange, product, instrument)); if (!DI_Instrument.Exists) { DI_Instrument.Create(); } string Path_Instrument = Path.Combine(DI_Instrument.FullName, f.Name); // 将当前目录下内容压缩到指定合约目录下 // 文件已经打开的情况下,无法进行压缩,这个地方处理一下 PathHelper.SevenZipFile(SevenZipExePath, Path_Instrument + ".7z", Path_TradingDay); } // 只有备份了一份,才会去删除 if (Clear_DataPath) { File.Delete(f.FullName); } // 记录下处理了哪些交易日 Set_TradingDay.Add(DI_TradingDay.FullName); Log.Info("处理完:{0}", f.FullName); } else { //无法识别,需人工处理 Log.Info("无法识别:{0}", f.FullName); } } // 对交易日进行压缩 foreach (var d in Set_TradingDay) { Log.Info("压缩交易日目录:{0}", d); PathHelper.SevenZipDirectory(SevenZipExePath, d + ".7z", d); Log.Info("转换交易日目录:{0}", d); HDF5_Convert(d + ".h5", d, Log); } // 删除 if (Clear_OutputPath_TradingDay) { foreach (var d in Set_TradingDay) { Log.Info("删除交易日目录:{0}", d); var di = new DirectoryInfo(d); if (di.Exists) { di.Delete(true); } } } }
static void Main(string[] args) { CommandArgs commandArgs = CommandLine.Parse(args); //// output all the argument pairs //Console.WriteLine("Command Line Arguments:"); //foreach (KeyValuePair<string, string> pair in commandArgs.ArgPairs) //{ // Console.WriteLine(string.Format(" {0} = {1}", pair.Key, pair.Value)); //} //// output all the parameters //Console.WriteLine("\nCommand Line Parameters:"); //foreach (string param in commandArgs.Params) //{ // Console.WriteLine(" " + param); //} //return; // 遍历,某个目录 Logger Log = LogManager.GetCurrentClassLogger(); string DataPath = ConfigurationManager.AppSettings[KEY_DataPath]; string OutputPath_TradingDay = ConfigurationManager.AppSettings[KEY_OutputPath_TradingDay]; string OutputPath_Instrument = ConfigurationManager.AppSettings[KEY_OutputPath_Instrument]; string DefaultExchange = ConfigurationManager.AppSettings[KEY_DefaultExchange]; string SevenZipExePath = ConfigurationManager.AppSettings[KEY_SevenZipExePath]; bool Clear_DataPath = bool.Parse(commandArgs.ArgPairs.ContainsKey(KEY_Clear_DataPath) ? commandArgs.ArgPairs[KEY_Clear_DataPath] : ConfigurationManager.AppSettings[KEY_Clear_DataPath]); bool Clear_OutputPath_TradingDay = bool.Parse(commandArgs.ArgPairs.ContainsKey(KEY_Clear_OutputPath_TradingDay) ? commandArgs.ArgPairs[KEY_Clear_OutputPath_TradingDay] : ConfigurationManager.AppSettings[KEY_Clear_OutputPath_TradingDay]); HashSet <string> Set_TradingDay = new HashSet <string>(); var files = new DirectoryInfo(DataPath).GetFiles("*", SearchOption.AllDirectories); foreach (var f in files) { string exchange = string.Empty; string product = string.Empty; string instrument = string.Empty; string symbol = string.Empty; string date = string.Empty; if (PathHelper.SplitFileName(f.Name, out exchange, out product, out instrument, out date)) { if (string.IsNullOrEmpty(exchange)) { exchange = DefaultExchange; } DirectoryInfo DI_TradingDay = new DirectoryInfo(Path.Combine(OutputPath_TradingDay, date)); if (!DI_TradingDay.Exists) { DI_TradingDay.Create(); } string Path_TradingDay = Path.Combine(DI_TradingDay.FullName, f.Name); // 将当前目录下内容复制到指定日期目录 File.Copy(f.FullName, Path_TradingDay, true); { DirectoryInfo DI_Instrument = new DirectoryInfo(Path.Combine(OutputPath_Instrument, exchange, product, instrument)); if (!DI_Instrument.Exists) { DI_Instrument.Create(); } string Path_Instrument = Path.Combine(DI_Instrument.FullName, f.Name); // 将当前目录下内容压缩到指定合约目录下 // 文件已经打开的情况下,无法进行压缩,这个地方处理一下 PathHelper.SevenZipFile(SevenZipExePath, Path_Instrument + ".7z", Path_TradingDay); } // 只有备份了一份,才会去删除 if (Clear_DataPath) { File.Delete(f.FullName); } // 记录下处理了哪些交易日 Set_TradingDay.Add(DI_TradingDay.FullName); Log.Info("处理完:{0}", f.FullName); } else { //无法识别,需人工处理 Log.Info("无法识别:{0}", f.FullName); } } // 对交易日进行压缩 foreach (var d in Set_TradingDay) { Log.Info("压缩交易日目录:{0}", d); PathHelper.SevenZipDirectory(SevenZipExePath, d + ".7z", d); } // 删除 if (Clear_OutputPath_TradingDay) { foreach (var d in Set_TradingDay) { Log.Info("删除交易日目录:{0}", d); var di = new DirectoryInfo(d); if (di.Exists) { di.Delete(true); } } } }
static void Main(string[] args) { // 遍历,某个目录 Logger Log = LogManager.GetCurrentClassLogger(); string DataPath = ConfigurationManager.AppSettings[KEY_DataPath]; string OutputPath_TradingDay = ConfigurationManager.AppSettings[KEY_OutputPath_TradingDay]; string OutputPath_Instrument = ConfigurationManager.AppSettings[KEY_OutputPath_Instrument]; string DefaultExchange = ConfigurationManager.AppSettings[KEY_DefaultExchange]; string SevenZipExePath = ConfigurationManager.AppSettings[KEY_SevenZipExePath]; bool Clear_DataPath = bool.Parse(ConfigurationManager.AppSettings[KEY_Clear_DataPath]); bool Clear_OutputPath_TradingDay = bool.Parse(ConfigurationManager.AppSettings[KEY_Clear_OutputPath_TradingDay]); HashSet <string> Set_TradingDay = new HashSet <string>(); var files = new DirectoryInfo(DataPath).GetFiles("*", SearchOption.AllDirectories); foreach (var f in files) { string exchange = string.Empty; string product = string.Empty; string instrument = string.Empty; string symbol = string.Empty; string date = string.Empty; if (PathHelper.SplitFileName(f.Name, out exchange, out product, out instrument, out date)) { if (string.IsNullOrEmpty(exchange)) { exchange = DefaultExchange; } if (!string.IsNullOrWhiteSpace(OutputPath_Instrument)) { DirectoryInfo DI_Instrument = new DirectoryInfo(Path.Combine(OutputPath_Instrument, exchange, product, instrument)); if (!DI_Instrument.Exists) { DI_Instrument.Create(); } string Path_Instrument = Path.Combine(DI_Instrument.FullName, f.Name); // 将当前目录下内容压缩到指定合约目录下 PathHelper.SevenZipFile(SevenZipExePath, Path_Instrument + ".7z", f.FullName); } if (!string.IsNullOrWhiteSpace(OutputPath_TradingDay)) { DirectoryInfo DI_TradingDay = new DirectoryInfo(Path.Combine(OutputPath_TradingDay, date)); if (!DI_TradingDay.Exists) { DI_TradingDay.Create(); } string Path_TradingDay = Path.Combine(DI_TradingDay.FullName, f.Name); // 将当前目录下内容复制到指定日期目录 File.Copy(f.FullName, Path_TradingDay, true); // 只有备份了一份,才有去删除 if (Clear_DataPath) { File.Delete(f.FullName); } // 记录下处理了哪些交易日 Set_TradingDay.Add(DI_TradingDay.FullName); } Log.Info("处理完:{0}", f.FullName); } else { //无法识别,需人工处理 Log.Info("无法识别:{0}", f.FullName); } } // 对交易日进行压缩 foreach (var d in Set_TradingDay) { Log.Info("压缩交易日目录:{0}", d); PathHelper.SevenZipDirectory(SevenZipExePath, d + ".7z", d); } // 删除 if (Clear_OutputPath_TradingDay) { foreach (var d in Set_TradingDay) { Log.Info("删除交易日目录:{0}", d); var di = new DirectoryInfo(d); if (di.Exists) { di.Delete(true); } } } }