private void ObserveRaceRun(RaceRun previousRaceRun, RaceRun raceRun) { // Only the list of the current run is allowed to be sent. // => Startlist needs to be send in following cases: // a) Start list itself changes // b) The previous run completed so that the next run needs to be send ItemsChangedNotifier startListNotifier = new ItemsChangedNotifier(raceRun.GetStartListProvider().GetViewList()); startListNotifier.CollectionChanged += (o, e) => { updateStartList(previousRaceRun, raceRun); }; updateStartList(previousRaceRun, raceRun); // Initial update _notifier.Add(startListNotifier); if (previousRaceRun != null) { IsCompleteObserver completeObserver = new IsCompleteObserver(previousRaceRun, raceRun, updateStartList); _notifier.Add(completeObserver); } // Results ItemsChangedNotifier resultsNotifier = new ItemsChangedNotifier(raceRun.GetResultList()); resultsNotifier.ItemChanged += (o, e) => { _liveTiming.UpdateResults(raceRun); }; _liveTiming.UpdateResults(raceRun); // Initial update _notifier.Add(resultsNotifier); }
private void observeRaceRun(RaceRun previousRaceRun, RaceRun raceRun) { ItemsChangedNotifier startListNotifier = new ItemsChangedNotifier(raceRun.GetStartListProvider().GetViewList()); startListNotifier.CollectionChanged += (o, e) => { updateStartList(previousRaceRun, raceRun); }; updateStartList(previousRaceRun, raceRun); // Initial update _notifier.Add(startListNotifier); if (previousRaceRun != null) { IsCompleteObserver completeObserver = new IsCompleteObserver(previousRaceRun, raceRun, updateStartList); _notifier.Add(completeObserver); } // Results _liveTiming.UpdateResults(raceRun); // Initial update ItemsChangedNotifier resultsNotifier = new ItemsChangedNotifier(raceRun.GetResultList()); resultsNotifier.ItemChanged += (sender, e) => { if (sender is RunResult rr) { Task.Delay(new TimeSpan(0, 0, 0, 0, 200)).ContinueWith(o => { System.Windows.Application.Current.Dispatcher.Invoke(() => { _liveTiming.UpdateInFinish(raceRun, rr.Participant); updateNextStarter(raceRun); }); }); } }; _notifier.Add(resultsNotifier); raceRun.OnTrackChanged += raceRun_OnTrackChanged; }
private void ObserveRace() { ItemsChangedNotifier notifier = new ItemsChangedNotifier(_race.GetParticipants()); notifier.CollectionChanged += (o, e) => { _liveTiming.UpdateParticipants(); }; _liveTiming.UpdateParticipants(); _notifier.Add(notifier); RaceRun rLast = null; foreach (var r in _race.GetRuns()) { System.Diagnostics.Debug.Assert(rLast == null || rLast.Run < r.Run, "previous run number must be smaller than current run number"); ObserveRaceRun(rLast, r); rLast = r; } }