コード例 #1
0
        private static bool OutputForCountMode(PgnQueryCommandLineParser parser, string value)
        {
            if (parser.CountMode)
            {
                Writer.Write(value);
            }

            return(parser.CountMode);
        }
コード例 #2
0
        private static PgnGameFinderService.FindOptions CreateOptions(PgnQueryCommandLineParser parser)
        {
            var opts = new PgnGameFinderService.FindOptions(
                parser.FileSources,
                parser.Event,
                parser.Site,
                parser.Date,
                parser.Round,
                parser.White, parser.Black, parser.Result, parser.CountMode, parser.Debug);

            return(opts);
        }
コード例 #3
0
        static int Main(string[] args)
        {
            var parser = new PgnQueryCommandLineParser(args);
            var opts   = CreateOptions(parser);


            if (parser.HasErrors)
            {
                OutputParserErrors(parser);
                return(-1);
            }

            ConsoleHeaderForCountMode(parser);


            var worker = new PgnGameFinderService();

            worker.OnFileRead += (sender, filename, games) =>
            {
                OutputForCountMode(parser, $" {games.Count()} Games read from: {filename}\n");
            };

            worker.OnMatchesFound += (sender, matched) =>
            {
                var pgnGames = matched.ToList();
                if (!OutputForCountMode(parser, $" {pgnGames.Count()} games matched.\n"))
                {
                    OutputPgnFiles(pgnGames);
                }
            };

            var totalMatches = worker.Find(opts);

            OutputForCountMode(parser, $"Total Matches found: {totalMatches.Count()}\n");

            return(0);
        }
コード例 #4
0
 private static void ConsoleHeaderForCountMode(PgnQueryCommandLineParser parser)
 {
     OutputForCountMode(parser, $"{GetDisplayVersion<Program>()}\n");
     OutputForCountMode(parser, $"{GetDisplayVersion<PgnGame>()}\n");
 }
コード例 #5
0
 private static void OutputParserErrors(PgnQueryCommandLineParser parser)
 {
     ErrorWriter.WriteLine("Command line error:");
     ErrorWriter.WriteLine($"{parser.Errors.Select(e => e.Message).Aggregate((s, e) => s + (e + "\n"))}");
 }