public static ICar AddCar(int tournamentID, ICar car) { IRlmRepository repo = RepositoryManager.GetDefaultRepository(); Car newCar = Car.From(car); lock (_lock) { Tournament tournament = repo.LoadTournament(tournamentID); // find an ID to assign to this new Car int maxID = 0; foreach (Car c in tournament.CarData) { if (c.ID > maxID) { maxID = c.ID; } } newCar.ID = maxID + 1; tournament.CarData.Add(newCar); repo.SaveTournament(tournament); } CarsUpdated?.Invoke(tournamentID, new CarsUpdatedEventArgs(GetCars(tournamentID))); StandingsUpdated?.Invoke(tournamentID, new StandingsUpdatedEventArgs(GetStandings(tournamentID))); return(newCar); }
public static void RaceMonitor_LaneResultAdded(LaneResultEventArgs e) { UpdateRaceTime(e.TournamentID, e.RaceNum, e.LaneNum, e.Time); //RacesUpdated?.Invoke(e.TournamentID, new RacesUpdatedEventArgs(GetRaces(e.TournamentID))); RaceUpdated?.Invoke(e.TournamentID, new RaceUpdatedEventArgs(GetCurrentRace(e.TournamentID))); StandingsUpdated?.Invoke(e.TournamentID, new StandingsUpdatedEventArgs(GetStandings(e.TournamentID))); }
public static ICar DeleteCar(int tournamentID, int carID) { IRlmRepository repo = RepositoryManager.GetDefaultRepository(); Car deletedCar = null; lock (_lock) { Tournament tournament = repo.LoadTournament(tournamentID); deletedCar = tournament.CarData.Where(c => c.ID == carID).SingleOrDefault(); tournament.CarData.Remove(deletedCar); repo.SaveTournament(tournament); } CarsUpdated?.Invoke(tournamentID, new CarsUpdatedEventArgs(GetCars(tournamentID))); StandingsUpdated?.Invoke(tournamentID, new StandingsUpdatedEventArgs(GetStandings(tournamentID))); return(deletedCar); }
public static ICar UpdateCar(int tournamentID, ICar car) { IRlmRepository repo = RepositoryManager.GetDefaultRepository(); Car updatedCar = null; lock (_lock) { Tournament tournament = repo.LoadTournament(tournamentID); updatedCar = tournament.CarData.Where(c => c.ID == car.ID).SingleOrDefault(); updatedCar.CopyFrom(car); repo.SaveTournament(tournament); } CarUpdated?.Invoke(tournamentID, new CarUpdatedEventArgs(updatedCar)); StandingsUpdated?.Invoke(tournamentID, new StandingsUpdatedEventArgs(GetStandings(tournamentID))); return(updatedCar); }
public static IRace UpdateRace(int tournamentID, IRace race) { IRlmRepository repo = RepositoryManager.GetDefaultRepository(); Race updatedRace = null; lock (_lock) { Tournament tournament = repo.LoadTournament(tournamentID); updatedRace = tournament.RaceData.Where(r => r.RaceNumber == race.RaceNumber).Single(); if (updatedRace.LaneAssignmentData.Count != race.LaneAssignments.Count()) { throw new ArgumentException("Races do not have the same number of lane assignments"); } updatedRace.State = race.State; ILaneAssignment[] laneAssignments = race.LaneAssignments.ToArray(); for (int i = 0; i < updatedRace.LaneAssignmentData.Count; i++) { LaneAssignment to = updatedRace.LaneAssignmentData[i]; ILaneAssignment from = laneAssignments[i]; to.ElapsedTime = from.ElapsedTime; to.Points = from.Points; to.Position = from.Position; } repo.SaveTournament(tournament); } //RacesUpdated?.Invoke(tournamentID, new RacesUpdatedEventArgs(GetRaces(tournamentID))); RaceUpdated?.Invoke(tournamentID, new RaceUpdatedEventArgs(updatedRace)); //NextRacesUpdated?.Invoke(tournamentID, new NextRacesUpdatedEventArgs(GetNextRaces(tournamentID))); StandingsUpdated?.Invoke(tournamentID, new StandingsUpdatedEventArgs(GetStandings(tournamentID))); return(updatedRace); }
public static RlmGetRacesResponse GenerateRaces(int tournamentID) { IRlmRepository repo = RepositoryManager.GetDefaultRepository(); RlmGetRacesResponse result = null; lock (_lock) { Tournament tournament = repo.LoadTournament(tournamentID); // generate the races TournamentManager.GenerateRaces(ref tournament); repo.SaveTournament(tournament); result = GetRaces(tournament); } RacesUpdated?.Invoke(tournamentID, new RacesUpdatedEventArgs(result)); CurrentRaceChanged?.Invoke(tournamentID, new CurrentRaceChangedEventArgs(null, GetCurrentRace(tournamentID))); //RaceUpdated?.Invoke(tournamentID, new RaceUpdatedEventArgs(GetCurrentRace(tournamentID))); NextRacesUpdated?.Invoke(tournamentID, new NextRacesUpdatedEventArgs(GetNextRaces(tournamentID))); StandingsUpdated?.Invoke(tournamentID, new StandingsUpdatedEventArgs(GetStandings(tournamentID))); return(result); }