public static void StartRace(int tournamentID, int raceNum) { IRlmRepository repo = RepositoryManager.GetDefaultRepository(); lock (_lock) { Tournament tournament = repo.LoadTournament(tournamentID); Race race = tournament.RaceData.Where(r => r.RaceNumber == raceNum).Single(); tournament.CurrentRace = raceNum; foreach (LaneAssignment assignment in race.LaneAssignmentData) { assignment.ElapsedTime = 0; assignment.Points = 0; assignment.Position = 0; assignment.ScaleSpeed = 0.0; } race.State = RaceState.Racing; repo.SaveTournament(tournament); } //RacesUpdated?.Invoke(tournamentID, new RacesUpdatedEventArgs(GetRaces(tournamentID))); RaceUpdated?.Invoke(tournamentID, new RaceUpdatedEventArgs(GetCurrentRace(tournamentID))); //NextRacesUpdated?.Invoke(tournamentID, new NextRacesUpdatedEventArgs(GetNextRaces(tournamentID))); RaceMonitor.LaneResultAdded += RaceMonitor_LaneResultAdded; RaceMonitor.Monitor(TournamentManager.ComPort, TournamentManager.BaudRate, tournamentID, raceNum, TournamentManager.Simulate); }
public static void StopRace(int tournamentID, int raceNum) { RaceMonitor.Stop(); RaceMonitor.LaneResultAdded -= RaceMonitor_LaneResultAdded; IRlmRepository repo = RepositoryManager.GetDefaultRepository(); lock (_lock) { Tournament tournament = repo.LoadTournament(tournamentID); Race race = tournament.RaceData.Where(r => r.RaceNumber == raceNum).Single(); tournament.CurrentRace = raceNum; race.State = RaceState.Done; repo.SaveTournament(tournament); } //RacesUpdated?.Invoke(tournamentID, new RacesUpdatedEventArgs(GetRaces(tournamentID))); RaceUpdated?.Invoke(tournamentID, new RaceUpdatedEventArgs(GetCurrentRace(tournamentID))); //NextRacesUpdated?.Invoke(tournamentID, new NextRacesUpdatedEventArgs(GetNextRaces(tournamentID))); }