static void Main(string[] args) { var cmdArgsValidator = new CmdArgsValidator(); cmdArgsValidator.AddRule(@"(-col)\s(\d+)\b"); cmdArgsValidator.AddRule(@"(-row)\s(\d+)\b"); cmdArgsValidator.AddRule(@"(-len)\s(\d+)\b"); cmdArgsValidator.AddRule(@"(-enc)\s[a-zA-Z0-9\-]+\b"); cmdArgsValidator.AddRule(@"(-out)\s[a-zA-Z\\\/:]+\.(csv)\b"); if (!cmdArgsValidator.IsValid(string.Join(" ", args))) { Console.WriteLine("Параметры коммандной строки заданы неверно."); return; } var parser = new CmdArgsParser(args); var cmdArgs = new CmdArgsValues(parser); var csv = new CsvFormatter(); csv.FormatToFile(cmdArgs); Console.WriteLine("Press any key..."); Console.ReadKey(); }
public static void ProcessCsv(string[] args) { var cmdArgsValidator = new CmdArgsValidator(); cmdArgsValidator.AddRule(@"(-in)\s[a-zA-Z0-9\\\/:]+\.(csv)\b"); cmdArgsValidator.AddRule(@"(-out)\s[a-zA-Z0-9\\\/:]+\.(csv)\b"); cmdArgsValidator.AddRule(@"(-enc)\s[a-zA-Z0-9\-]+\b"); cmdArgsValidator.AddRule(@"(-col)\s[a-zA-Z]+\b"); cmdArgsValidator.AddRule(@"(-exp)\s[a-zA-Z0-9\-]+\b"); if (!cmdArgsValidator.IsValid(string.Join(" ", args))) { Console.WriteLine("Параметры коммандной строки заданы неверно."); return; } //Шаблон входной коммандной строки. var columnPattern = @"^(((^|\s)(\w+)\s(\w+)(;|$)){1,})$"; var columnsValidator = new CsvColumnValidator(); columnsValidator.AddRule(columnPattern); var parser = new CmdArgsParser(args); var cmdArgs = new CmdArgs(parser); CsvReader reader; try { reader = new CsvReader(cmdArgs.InFileName, cmdArgs.Encoding, columnsValidator); } catch (FileNotFoundException e) { Console.WriteLine(e.Message); return; } using (var writer = new StreamWriter(cmdArgs.OutFileName, false, cmdArgs.Encoding)) { writer.WriteLine(reader.GetHeader()); writer.Write(reader.GetRowsWith(cmdArgs.ColumnName, cmdArgs.Exp)); } }