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)); }
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"); } }
public static TimeEvent ToTimeEvent(this MatchEventDto value) { return(new TimeEvent { Id = value.Id, MatchPeriod = (MatchPeriod)value.MatchPeriod, Minute = value.Minute }); }
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 }); }
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 }); }