public async Task InitializeNewMatch()
        {
            TrySetMatchRuleset(_rulesetManager.ActiveRuleset);

            _matchStartTime = DateTime.UtcNow;

            CurrentSeriesMatch++;

            if (MatchConfiguration.SaveLogFiles == true)
            {
                var matchId = BuildMatchId();

                _messageService.SetLogFileName($"{matchId}.txt");

                var scrimMatch = new Data.Models.ScrimMatch
                {
                    Id        = matchId,
                    StartTime = _matchStartTime,
                    Title     = MatchConfiguration.Title,
                    RulesetId = MatchRuleset.Id
                };

                await _matchDataService.SaveToCurrentMatch(scrimMatch);
            }
        }
        public ScrimMatchInfo(Data.Models.ScrimMatch scrimMatch, ScrimMatchRoundConfiguration lastRoundConfiguration, string firstTeamTag, string secondTeamTag)
        {
            ScrimMatchId = scrimMatch.Id;
            StartTime    = scrimMatch.StartTime;
            Title        = scrimMatch.Title;

            SetTeamAliases();

            RoundCount = lastRoundConfiguration.ScrimMatchRound;
            WorldId    = lastRoundConfiguration.WorldId;
            FacilityId = lastRoundConfiguration.FacilityId;
        }
        public async Task InitializeNewMatch()
        {
            _matchStartTime = DateTime.UtcNow;

            if (MatchConfiguration.SaveLogFiles == true)
            {
                var matchId = BuildMatchId();

                _messageService.SetLogFileName($"{matchId}.txt");

                var scrimMatch = new Data.Models.ScrimMatch
                {
                    Id        = matchId,
                    StartTime = _matchStartTime,
                    Title     = MatchConfiguration.Title
                };

                await _matchDataService.SaveToCurrentMatch(scrimMatch);
            }
        }
Beispiel #4
0
        public async Task SaveToCurrentMatch(Data.Models.ScrimMatch scrimMatch)
        {
            var id = scrimMatch.Id;

            using (await _scrimMatchLock.WaitAsync(id))
            {
                var oldMatchId = CurrentMatchId;

                CurrentMatchId = id;

                try
                {
                    CurrentMatchId = id;

                    using var factory = _dbContextHelper.GetFactory();
                    var dbContext = factory.GetDbContext();

                    var storeEntity = await dbContext.ScrimMatches.FirstOrDefaultAsync(sm => sm.Id == id);

                    if (storeEntity == null)
                    {
                        dbContext.ScrimMatches.Add(scrimMatch);
                    }
                    else
                    {
                        storeEntity = scrimMatch;
                        dbContext.ScrimMatches.Update(storeEntity);
                    }

                    await dbContext.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    CurrentMatchId = oldMatchId;

                    _logger.LogError(ex.ToString());
                }
            }
        }