示例#1
0
 private void BackupDemo(Demo demo, DemoBackuper backuper)
 {
     try
     {
         backuper.BackupDemoFile(demo, true);
     }
     catch (Exception)
     {
         myLogger.LogWarning($"Backing up the downloaded demo file ({demo.FilePath}) failed.");
     }
 }
示例#2
0
        public void ProcessNewMatches(object state)
        {
            var newMatches         = new List <Match>();
            var blacklistedMatches = new List <Match>();
            var newDemoFiles       = Directory.EnumerateFiles(myDemoWatchFolder).Where(x => x.EndsWith(".dem"));

            myLogger.LogDebug($"Found {newDemoFiles.Count()} new demo files in the watch folder");

            var demoBackuper = new DemoBackuper(myLoggerFactory.CreateLogger <DemoBackuper>());

            foreach (var demoFile in newDemoFiles)
            {
                var match = new Match {
                    Demo = new Demo {
                        FilePath = demoFile
                    }, Date = File.GetCreationTime(demoFile)
                };

                try
                {
                    using var demoReader = new DemoReader(match);
                    demoReader.ReadHeader();
                    demoReader.Read();
                    match = demoReader.Match;
                    myLogger.LogTrace($"Finished analyzing demo file {Path.GetFileName(demoFile)}");
                    newMatches.Add(match);
                }
                catch (DemoReaderException e)
                {
                    match.Id     += Guid.NewGuid().ToString();
                    match.Demo.Id = match.Id;
                    myLogger.LogWarning($"Analyzing demo from watch folder ({Path.GetFileName(demoFile)}) failed: {e.Message}. Adding to repository (id: {match.Id}) without stats -> blacklisted.");
                    match.PlayerResults.Clear();
                    match.CTScore = -1;
                    match.TScore  = -1;
                    blacklistedMatches.Add(match);
                }

                BackupDemo(match.Demo, demoBackuper);
            }

            using var scope = myScopeFactory.CreateScope();
            myLogger.LogTrace($"Getting match repository to add {newMatches.Count} new matches and blacklist {blacklistedMatches.Count} demos.");
            var matchRepository = scope.ServiceProvider.GetRequiredService <MatchRepository>();

            matchRepository.AddMatchesAndSave(newMatches);
            matchRepository.AddMatchesAndSave(blacklistedMatches);
        }
示例#3
0
        private void TryBackupDemo(Demo demo, DemoBackuper backuper)
        {
            if (string.IsNullOrEmpty(demo.FilePath))
            {
                myLogger.LogWarning($"No local file path for demo to backup given (share code: {demo.ShareCode}");
                return;
            }

            try
            {
                backuper.BackupDemoFile(demo);
            }
            catch (Exception)
            {
                myLogger.LogError($"Backing up the downloaded demo file ({demo.FilePath}) failed.");
            }
        }
示例#4
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));
        }