Пример #1
0
        public void UpdateMatch(List <PlayerInfo> playersTeamWinner, List <PlayerInfo> playersTeamLooser, string userId, string matchId)
        {
            //lock (_lockMatchUpdate)
            {
                var match = _matchRepository.GetById(matchId);

                if (IsMatchConcluded(playersTeamWinner.Concat(playersTeamLooser).ToList()))
                {
                    match = Match.Factory.From(match)
                            .WithWinners(playersTeamWinner)
                            .WithLoosers(playersTeamLooser)
                            .MarkAsConcluded()
                            .Instance;
                }
                else
                {
                    match = Match.Factory.From(match)
                            .WithWinners(playersTeamWinner)
                            .WithLoosers(playersTeamLooser)
                            .Instance;
                }

                _matchRepository.Upsert(match);
                OnMatchResolved?.Invoke(this, new OnMatchDoneArgs(match, userId));
            }
        }
Пример #2
0
        public void MarkMatchAsResolved(string matchId, List <PlayerInfo> winners,
                                        List <PlayerInfo> loosers)
        {
            var match = _matchRepository.GetById(matchId);

            match.PlayersTeamWinner.Clear();
            winners.ForEach(w => match.PlayersTeamWinner.Add(w));
            match.PlayersTeamLooser.Clear();
            loosers.ForEach(l => match.PlayersTeamLooser.Add(l));

            match = Match.Factory.From(match).MarkAsConcluded().Instance;
            _matchRepository.Upsert(match);
            lock (_lockMatchUpdate)
            {
                OnMatchResolved?.Invoke(this, new OnMatchDoneArgs(match));
            }
        }
Пример #3
0
        public void OnMatchProcessed(object sender, OnMatchDoneArgs args)
        {
            var result = args.Match;

            var matches = GroupMatchesByDate(args.MatchInfo);

            matches.GroupBy(p => p.Key)
            .ToList()
            .Where(p => !string.IsNullOrEmpty(p.Key))
            .ToList()
            .ForEach(match =>
            {
                var m = match.FirstOrDefault();
                if (args.Match.IsMatchDateEmpty)
                {
                    result = Factory.From(result)
                             .WithDate(
                        DateTime.ParseExact(match.Key, "yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture))
                             .Instance;
                }
                m.Value.ForEach(player =>
                {
                    var values = player.Split(';');
                    int points = 0;
                    int.TryParse(values[2], out points);
                    var character   = values[3];
                    var currentChar = CharEnum.ToList().FirstOrDefault(c => c.Valor.ToUpper() == character.ToUpper());
                    if (currentChar == null)
                    {
                        currentChar = CharEnum.UNDEFINED;
                    }
                    var p = new PlayerInfo(currentChar, values[1], points);
                    if (values[0] == "Derrota")
                    {
                        result.PlayersTeamLooser.Add(p);
                    }
                    else
                    {
                        result.PlayersTeamWinner.Add(p);
                    }
                });
            });
            _matchRepository.Upsert(result);
            OnMatchResolved?.Invoke(this, args);
        }