コード例 #1
0
//        [TestCase(@".\PGNFiles")]
//        [TestCase(@"D:\Src\PGNArchive\PGN")]
        public void ParseAllFiles(string path)
        {
            var pgnfiles       = Directory.GetFiles(path, "*.pgn", SearchOption.AllDirectories);
            var fileCount      = 0;
            var gamesCount     = 0;
            var fileGamesCount = 0;

            foreach (var file in pgnfiles)
            {
                fileCount++;
                if (file.Contains("FAILED"))
                {
                    continue;
                }

                try
                {
                    var games = PgnGame.ReadAllGamesFromString(File.ReadAllText(file));

                    // DumpGameInfo(game);
                    gamesCount += games.Count();
                }
                catch
                {
                    Console.WriteLine($"Failed: {file}\nGame Idx: {fileCount}/{fileGamesCount}");
                    throw;
                }

                fileGamesCount = 0;
            }

            TestContext.Progress.WriteLine($"Files #: {fileCount}, Total Games #: {gamesCount}");
            Assert.That(fileCount, Is.GreaterThan(0), "No files processed");
            Assert.That(gamesCount, Is.GreaterThan(0), "No games processed");
        }
コード例 #2
0
        private TimeSpan Play(bool parallelise)
        {
            var previousFf = FeatureFlags.ParalleliseRefreshAllPaths;

            FeatureFlags.ParalleliseRefreshAllPaths = parallelise;
            TimeSpan elapsed;
            var      stopwatch = Stopwatch.StartNew();

            try
            {
                var pgnGame = PgnGame.ReadAllGamesFromString(WikiGame.PgnText).First();
                PlaySingleGame(pgnGame);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            finally
            {
                elapsed = stopwatch.Elapsed;
                FeatureFlags.ParalleliseRefreshAllPaths = previousFf;
            }

            return(elapsed);
        }
コード例 #3
0
        public void Wiki_games_FromString_works()
        {
            var games = PgnGame.ReadAllGamesFromString(
                WikiGame.PgnText + "\n" +
                WikiGame.PgnText).ToList();

            AssertWikiGameIsCorrect(games[0]);
            AssertWikiGameIsCorrect(games[1]);
        }
コード例 #4
0
        [Explicit("WARNING: Could take a long time.")] // NEVER COMMIT THIS !!!!!!!!!!!!!!!!!!!!!!!!!
        public void Measure_parse_wiki_game_time_100_games()
        {
            var times = new List <TimeSpan>();

            for (int i = 0; i < 100; i++)
            {
                var sw = Stopwatch.StartNew();
                PlayAllGames(PgnGame.ReadAllGamesFromString(WikiGame.PgnText));
                times.Add(sw.Elapsed);
            }

            TestContext.Progress.WriteLine($"Average Game Parse TIme: { new TimeSpan(Convert.ToInt64(times.Average(ts => ts.Ticks)))}");
        }
コード例 #5
0
 public PgnGame Build()
 {
     return(PgnGame.ReadAllGamesFromString(
                PgnText
                .Replace("{Event}", _event)
                .Replace("{Site}", _site)
                .Replace("{Date}", _date)
                .Replace("{Round}", _round)
                .Replace("{White}", _white)
                .Replace("{Black}", _black)
                .Replace("{Result}", _result)
                ).Single());
 }
コード例 #6
0
        public string SerializeAllGames(string text, bool expandedFormat)
        {
            try
            {
                var games    = PgnGame.ReadAllGamesFromString(text);
                var settings = new JsonSerializerSettings();

                settings.NullValueHandling    = NullValueHandling.Ignore;
                settings.DefaultValueHandling = DefaultValueHandling.Ignore;

                return(expandedFormat
                    ? JsonConvert.SerializeObject(games, Formatting.Indented, settings)
                    : JsonConvert.SerializeObject(games.Select(p => new PgnJson(p)), Formatting.Indented, settings));
            }
            catch (Exception e)
            {
                return($"Error: {e.Message}");
            }
        }
コード例 #7
0
        private static void ParseSingleFile(string file)
        {
            PgnGame game  = null;
            var     count = 1;

            try
            {
                var games = PgnGame.ReadAllGamesFromString(File.ReadAllText(file));
                count = games.Count();
            }
            catch
            {
                Console.WriteLine($"Failed: #{count}, {file}, {game?.ToString() ?? ""}");
                if (game != null)
                {
                    DumpGameInfo(game);
                }
                throw;
            }

            Console.WriteLine($"{count} games parsed from {file}");
        }
コード例 #8
0
        [Explicit("WARNING: Could take a VERY long time.")]// NEVER COMMIT THIS !!!!!!!!!!!!!!!!!!!!!!!!!
        public void PlayAllFiles(string path)
        {
            var pgnfiles   = Directory.GetFiles(path, "*.pgn", SearchOption.AllDirectories);
            var fileCount  = 0;
            var gamesCount = 0;
            var sw         = Stopwatch.StartNew();
            var fileTimes  = new List <TimeSpan>();

            // NOTE: As this loop includes file access care must be taken with current VS/R#dotnet type setups
            // if they run tests in the background they can lock the files and cause weird errors here.
            // TODO: Change these long running tests to a console application
            pgnfiles.AsParallel().ForAll(file =>
            {
                TestContext.Progress.WriteLine("*************************************");
                TestContext.Progress.WriteLine($"*** starting file: {file}");
                TestContext.Progress.WriteLine("*************************************");
                var fileSw = new Stopwatch();
                if (file.Contains("FAILED"))
                {
                    return;
                }
                fileCount++;

                var text = File.ReadAllText(file);
                PlayAllGames(PgnGame.ReadAllGamesFromString(text));
                fileSw.Stop();
                fileTimes.Add(fileSw.Elapsed);
                TestContext.Progress.WriteLine("*************************************");
                TestContext.Progress.WriteLine($"*** finished file: {file} in {fileSw.Elapsed}");
                TestContext.Progress.WriteLine("*************************************");
            });
            sw.Stop();
            Console.WriteLine($"Files #: {fileCount}/{pgnfiles.Length}, Total Games #: {gamesCount}");
            Console.Write($"Total time: {sw.Elapsed}, Avg. File Parse Time: {sw.Elapsed / pgnfiles.Length}");
            Assert.That(fileCount, Is.GreaterThan(0), "No files processed");
            Assert.That(gamesCount, Is.GreaterThan(0), "No games processed");
        }
コード例 #9
0
        public void Wiki_games_FromFile_works()
        {
            var reader = PgnGame.ReadAllGamesFromString(File.ReadAllText(@".\TestData\wikigame.pgn"));

            AssertWikiGame(reader);
        }
コード例 #10
0
 public PgnGame Build()
 {
     return(PgnGame.ReadAllGamesFromString(CreatePgn()).First());
 }