Example #1
0
        public void Parse_MatchHasDifferentNumberOfRoundsPreset_ThrowsInconsistentStatistics()
        {
            var demo = new Demo {
                FilePath = Path.Combine("TestData", @"auto0-20210103-190414-139014994-de_dust2-honigbiene_vs_waldfrosch.dem")
            };
            var match = new Match {
                Demo = demo, Rounds = 6
            };

            //Setting minimum number of rounds & players to 0 (different than during runtime) to allow reading this smaller demo file
            var demoReader = new DemoReader(match, 0, 0);

            Assert.Throws <InconsistentStatisticsException>(() => demoReader.Parse());
        }
Example #2
0
        public void Read_GameOnOurServer_ReturnsCorrectScores(string demoFileName, int CTScore, int TScore)
        {
            var demo = new Demo {
                FilePath = Path.Combine("TestData", demoFileName)
            };

            var demoReader = new DemoReader(new Match {
                Demo = demo
            }, 0, 0);

            var match = demoReader.Parse();

            Assert.Equal(CTScore, match.CTScore);
            Assert.Equal(TScore, match.TScore);
        }
Example #3
0
        public void Read_MatchMakingGame_ReturnsCorrectPlayerHighestAndLowestHLTV(string demoFileName, string highestHLTVPlayerSteamId, string lowestHLTVPlayerSteamId)
        {
            var demo = new Demo {
                FilePath = Path.Combine("TestData", demoFileName)
            };

            var demoReader = new DemoReader(new Match {
                Demo = demo
            }, 0, 0);

            var match = demoReader.Parse();

            var orderedByDescendingHLTV = match.PlayerResults.OrderByDescending(x => x.HLTVScore);

            Assert.Equal(long.Parse(highestHLTVPlayerSteamId), orderedByDescendingHLTV.First().SteamID);
            Assert.Equal(long.Parse(lowestHLTVPlayerSteamId), orderedByDescendingHLTV.Last().SteamID);
        }
Example #4
0
        public void Read_MatchMakingGame_ReturnsCorrectMatchType(string demoFileName, CompetitiveMatchType expectedMatchType)
        {
            var demo = new Demo {
                FilePath = Path.Combine("TestData", demoFileName)
            };

            var demoReader = new DemoReader(new Match {
                Demo = demo
            }, 0, 0);

            var match = demoReader.Parse();

            foreach (var matchStatistics in match.PlayerResults)
            {
                Assert.Equal(expectedMatchType, matchStatistics.MatchType);
            }
        }
Example #5
0
        private void ProcessNewMatches(GameCoordinatorClient gameCoordinatorClient, ShareCodeRepository shareCodeRepository, MatchRepository matchRepository)
        {
            var newSharingCodes = shareCodeRepository.GetRetryableBatch(5);

            if (!newSharingCodes.Any())
            {
                return;
            }

            myLogger.LogDebug($"Retrieved {newSharingCodes.Count} new sharing codes: {string.Join(", ", newSharingCodes.Select(x => x.Code))}");
            var newMatches     = new List <Match>();
            var demoDownloader = new DemoDownloader(myLoggerFactory.CreateLogger <DemoDownloader>());
            var demoBackuper   = new DemoBackuper(myLoggerFactory.CreateLogger <DemoBackuper>());

            foreach (var sharingCode in newSharingCodes)
            {
                var demo = CreateNewDemoForShareCode(sharingCode);

                try
                {
                    var match = gameCoordinatorClient.GetMatchInfo(demo);
                    myLogger.LogTrace($"Got match details for sharing code {sharingCode.Code}");

                    match.Demo.FilePath = demoDownloader.DownloadAndDecompressDemo(match.Demo.DownloadURL);
                    myLogger.LogTrace($"Downloaded and decompressed demo file for sharing code {sharingCode.Code}");

                    using var demoReader = new DemoReader(match, 0, 0);
                    match = demoReader.Parse();

                    myLogger.LogTrace($"Finished analyzing demo file for sharing code {sharingCode.Code}");
                    newMatches.Add(match);
                }
                catch (GameCoordinatorException)
                {
                    myLogger.LogWarning($"Couldn't get download url for sharing code {sharingCode.Code}. See previous logs/exceptions for explanation. Continuing.");
                    continue;
                }
                catch (DemoDownloaderException exception)
                {
                    myLogger.LogWarning($"Demo downloading or decompressing failed: {exception.Message} for sharing code {sharingCode.Code}.");
                    continue;
                }
                catch (DemoReaderException e)
                {
                    myLogger.LogWarning($"Analyzing demo for share code {sharingCode.Code} failed: {e.Message}");
                    demo.State = DemoState.ParseFailure;
                    continue;
                }
                finally
                {
                    TryBackupDemo(demo, demoBackuper);
                }
            }

            myLogger.LogDebug($"Downloaded and analyzed {newMatches.Count} new matches (from {newSharingCodes.Count} new sharing codes).");
            myLogger.LogTrace($"Saving {newMatches.Count} new matches to repository.");

            var successfullySavedMatches = matchRepository.AddMatchesAndSave(newMatches);

            shareCodeRepository.RemoveCodes(successfullySavedMatches.Select(x => x.Demo.ShareCode));
        }