예제 #1
0
        private Task HandleMatchEvent(MatchEventDto matchEventDto)
        {
            switch ((MatchEventType)matchEventDto.MatchEventType)
            {
            case MatchEventType.None:
                break;

            case MatchEventType.Goal:
                State.Apply(matchEventDto.ToGoalEvent());
                break;

            case MatchEventType.YellowCard:
                State.Apply(matchEventDto.ToYellowCardEvent());
                break;

            case MatchEventType.RedCard:
                State.Apply(matchEventDto.ToRedCardEvent());
                break;

            case MatchEventType.Substitution:
                State.Apply(matchEventDto.ToSubstitutionEvent());
                break;

            case MatchEventType.Time:
                State.Apply(matchEventDto.ToTimeEvent());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(_stream.OnNextAsync(matchEventDto));
        }
예제 #2
0
        private async Task OnMatchEvent(MatchEventDto matchEventDto, StreamSequenceToken streamSequenceToken)
        {
            if (_matches.TryGetValue(matchEventDto.MatchId, out var matchItem))
            {
                var matchListEventType = MatchListEventType.None;

                if ((MatchEventType)matchEventDto.MatchEventType == MatchEventType.Goal)
                {
                    matchItem.Goal(matchEventDto.Home.GetValueOrDefault());
                    matchListEventType = MatchListEventType.MatchGoal;
                }

                if ((MatchEventType)matchEventDto.MatchEventType == MatchEventType.Time)
                {
                    matchItem.Time((MatchPeriod)matchEventDto.MatchPeriod, matchEventDto.Minute);
                    matchListEventType = MatchListEventType.MatchTime;
                }

                if (matchListEventType != MatchListEventType.None)
                {
                    await _matchListStream.OnNextAsync(ToMatchDto(matchItem, matchListEventType));
                }
            }
            else
            {
                Console.WriteLine("invalid match event");
            }
        }
예제 #3
0
 public static TimeEvent ToTimeEvent(this MatchEventDto value)
 {
     return(new TimeEvent
     {
         Id = value.Id,
         MatchPeriod = (MatchPeriod)value.MatchPeriod,
         Minute = value.Minute
     });
 }
예제 #4
0
 public static RedCardEvent ToRedCardEvent(this MatchEventDto value)
 {
     return(new RedCardEvent
     {
         Id = value.Id,
         MatchPeriod = (MatchPeriod)value.MatchPeriod,
         Minute = value.Minute,
         Home = value.Home.Value,
         PlayerId = value.PlayerId
     });
 }
예제 #5
0
 public static SubstitutionEvent ToSubstitutionEvent(this MatchEventDto value)
 {
     return(new SubstitutionEvent
     {
         Id = value.Id,
         MatchPeriod = (MatchPeriod)value.MatchPeriod,
         Minute = value.Minute,
         Home = value.Home.Value,
         PlayerId = value.PlayerId,
         SubstitutionPlayerId = value.SubstitutionPlayerId
     });
 }