コード例 #1
0
        /*private void RemoveAllDrivers()
         * {
         *  if (!Application.Current.Dispatcher.CheckAccess())
         *  {
         *      Application.Current.Dispatcher.Invoke(RemoveAllDrivers);
         *      return;
         *  }
         *
         *  lock (_lockObject)
         *  {
         *      _driverNameTimingMap.Clear();
         *      DriversViewModels.Clear();
         *  };
         * }*/

        public void AddDriver(DriverTiming driver)
        {
            if (!Application.Current.Dispatcher.CheckAccess())
            {
                Application.Current.Dispatcher.Invoke(() => AddDriver(driver));
                return;
            }

            DriverTimingViewModel newViewModel = new DriverTimingViewModel(driver)
            {
                ClassIndicationBrush = GetClassColor(driver.DriverInfo)
            };

            lock (_lockObject)
            {
                //If possible, rebind - do not create new
                if (_driverNameTimingMap.ContainsKey(driver.Name))
                {
                    _driverNameTimingMap[driver.Name] = driver;
                    RebindViewModel(DriversViewModels.First(x => x.Name == driver.Name), driver);
                    return;
                }
                _driverNameTimingMap[driver.Name] = driver;
                newViewModel.OutLineColor         = GetDriverOutline(driver.Name);
                DriversViewModels.Add(newViewModel);
            }
        }
コード例 #2
0
        public void MatchDriversList(List <DriverTiming> drivers)
        {
            if (!Application.Current.Dispatcher.CheckAccess())
            {
                Application.Current.Dispatcher.Invoke(() => MatchDriversList(drivers));
                return;
            }
            PitBoardViewModel.Reset();

            lock (_lockObject)
            {
                List <DriverTiming> driversToRemove = _driverNameTimingMap.Values.Where(x => drivers.FirstOrDefault(y => y.Name == x.Name) == null).ToList();
                List <DriverTiming> driversToAdd    = drivers.Where(x => !_driverNameTimingMap.ContainsKey(x.Name)).ToList();
                List <DriverTiming> driversToRebind = drivers.Where(x => _driverNameTimingMap.ContainsKey(x.Name)).ToList();

                foreach (DriverTiming driverToRebind in driversToRebind)
                {
                    _driverNameTimingMap[driverToRebind.Name] = driverToRebind;
                    RebindViewModel(DriversViewModels.First(x => x.Name == driverToRebind.Name), driverToRebind);
                }

                int i = 0;
                for (i = 0; i < driversToAdd.Count && i < driversToRemove.Count; i++)
                {
                    _driverNameTimingMap.Remove(driversToRemove[i].Name);
                    _driverNameTimingMap.Add(driversToAdd[i].Name, driversToAdd[i]);
                    RebindViewModel(DriversViewModels.First(x => x.Name == driversToRemove[i].Name), driversToAdd[i]);
                }

                driversToRemove.Skip(i).ForEach(RemoveDriver);
                AddDrivers(driversToAdd.Skip(i));
            }
        }
コード例 #3
0
        public void MatchDriversList(List <DriverTiming> drivers)
        {
            if (!Application.Current.Dispatcher.CheckAccess())
            {
                Application.Current.Dispatcher.Invoke(() => MatchDriversList(drivers));
                return;
            }

            lock (_lockObject)
            {
                IEnumerable <DriverTiming> driversToRemove = _driverNameTimingMap.Values.Where(x => drivers.FirstOrDefault(y => y.Name == x.Name) == null).ToList();
                IEnumerable <DriverTiming> driversToAdd    = drivers.Where(x => !_driverNameTimingMap.ContainsKey(x.Name)).ToList();
                IEnumerable <DriverTiming> driversToRebind = drivers.Where(x => _driverNameTimingMap.ContainsKey(x.Name)).ToList();

                driversToRemove.ForEach(RemoveDriver);
                AddDrivers(driversToAdd);

                foreach (DriverTiming driverToRebind in driversToRebind)
                {
                    _driverNameTimingMap[driverToRebind.Name] = driverToRebind;
                    RebindViewModel(DriversViewModels.First(x => x.Name == driverToRebind.Name), driverToRebind);
                }
            }
        }