Пример #1
0
 public AnalyzerCommandLine()
 {
     commandLineDefinition = new CommandLineDefinition(false);
     commandLineDefinition.AddOption(InitialQuotedIdentifiersKey, optional, "Quoted identifers enabled at the beginning");
     commandLineDefinition.AddOption(VerboseKey, optional, "Verbose output");
     commandLineDefinition.AddSettingKey(SqlVersionKey, optional, "Sql version to use, e.g. Sql120");
     commandLineDefinition.AddSettingKey(InputFileKey, mandatory, "Input file name");
     commandLineDefinition.AddSettingKey(ConfigFileKey, mandatory, "Config file name");
     commandLineDefinition.AddSettingKey(DisplayHelpKey, optional, "Display help");
 }
Пример #2
0
        static void Main(string[] args)
        {
            var definition = new CommandLineDefinition {
                new CommandLineArgument("i", "input", true, true, "The input file to split."),
                new CommandLineArgument("l", "lines", true, true, "The number of lines to split by."),
                new CommandLineArgument("o", "output", true, true, "")
            };

            var parser = new CommandLineParser();

            try {
                var result = parser.Parse(definition, args);

                var splitCount = int.Parse(result["lines"]);

                using (var reader = new StreamReader(result["input"])) {
                    string       line;
                    var          currentLine   = 0;
                    var          currentFile   = 1;
                    StreamWriter currentStream = null;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (currentStream == null)
                        {
                            currentStream = OpenFile(result["input"], currentFile, result["output"]);
                        }
                        currentLine++;
                        currentStream.WriteLine(line);
                        if (currentLine >= splitCount)
                        {
                            currentLine = 0;
                            currentFile++;
                            currentStream.Flush();
                            currentStream.Dispose();
                            currentStream = null;
                        }
                    }
                    if (currentStream != null)
                    {
                        currentStream.Flush();
                    }
                }
            } catch (CommandLineArgumentException) {
                var helpText = parser.GenerateHelpText(definition, "SplitFile", "Splits files into user-defined chunks.");
                Console.WriteLine(helpText);
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                Console.WriteLine(ex.StackTrace);
            }
        }