public Match Replay(IEnumerable <Event> events) { var match = new Match(); foreach (var e in events) { var whatHappened = (EventType)Enum.Parse(typeof(EventType), e.EventType); switch (whatHappened) { case EventType.Created: var matchCreatedEventArgs = JsonConvert.DeserializeObject <MatchCreatedEvent.MatchCreatedEventArgs>(e.Payload); match = Match.Factory.CreateNewMatch(e.PartitionKey, matchCreatedEventArgs.Team1, matchCreatedEventArgs.Team2); break; case EventType.Start: match.Start(); break; case EventType.End: match.Finish(); break; case EventType.Period: match.StartPeriod(); break; case EventType.EndPeriod: match.EndPeriod(); break; case EventType.Goal: var goalScoredEventEventArgs = JsonConvert.DeserializeObject <GoalScoredEvent.GoalScoredEventEventArgs>(e.Payload); match.Goal(goalScoredEventEventArgs?.TeamId ?? TeamId.Unknown); break; case EventType.Timeout: var timeoutRequestedEventArgs = JsonConvert.DeserializeObject <TimeoutRequestedEvent.TimeoutRequestedEventArgs>(e.Payload); match.Timeout(timeoutRequestedEventArgs?.TeamId ?? TeamId.Unknown); break; case EventType.Resume: match.Resume(); break; } } return(match); }
private static MatchData CopyFrom(Match match) { var persistedMatch = new MatchData() { MatchId = match.Id, Period = match.CurrentPeriod, Score1 = match.CurrentScore.TotalGoals1, Score2 = match.CurrentScore.TotalGoals2, State = (int)match.State, Team1 = match.Team1, Team2 = match.Team2, Timeouts1 = match.TimeoutSummary(TeamId.Home), Timeouts2 = match.TimeoutSummary(TeamId.Visitors) }; return(persistedMatch); }