Ejemplo n.º 1
0
        void UpdatePositionInList(int oldPosition, ViewModel.CarViewModel carViewModel)
        {
            if (oldPosition == carViewModel.TablePosition)
            {
                //no change
                return;
            }

            if (oldPosition == 0 && carViewModel.TablePosition > 0)
            {
                int insertPosition = carViewModel.TablePosition - 1;
                //first check if we have other car at that position
                HideAtPosition(insertPosition);

                //now we can insert it at correct place
                InsertAtPosition(insertPosition, carViewModel);

                //remove previous element if any
                _invisibleCars.Remove(carViewModel);
            }
            else if (oldPosition > 0 && carViewModel.TablePosition == 0)
            {
                int pos = oldPosition - 1;

                //move to hidden list
                HideAtPosition(pos);

                //insert blank car at old place
                BlankAtPosition(pos);
            }
            else if (oldPosition > 0 && carViewModel.TablePosition > 0 && oldPosition != carViewModel.TablePosition)
            {
                //change places
                int newPos = carViewModel.TablePosition - 1;
                int oldPos = oldPosition - 1;

                //hide car at new pos
                HideAtPosition(newPos);

                //blank old position
                BlankAtPosition(oldPos);

                //now move to new position
                InsertAtPosition(newPos, carViewModel);
            }
        }
Ejemplo n.º 2
0
        void _lt_CarMessageHandler(F1.Messages.IMessage msg)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (MainViewModel.ProgressText.Contains("Connecting"))
                {
                    MainViewModel.ProgressIsVisible = false;
                }

                F1.Messages.ICarMessage carMsg      = (F1.Messages.ICarMessage)msg;
                ViewModel.CarViewModel carViewModel = null;

                int oldPosition = 0;

                try
                {
                    carViewModel = MainViewModel.Cars.First(car => car.CarId == carMsg.CarId);
                    oldPosition  = carViewModel.TablePosition;
                }
                catch (InvalidOperationException)
                {
                    //check for it in our invisible car list
                    try
                    {
                        carViewModel = _invisibleCars.First(car => car.CarId == carMsg.CarId);
                        carViewModel.IsDataEstimationEnabled = MainViewModel.IsDataEstimationEnabled;
                        oldPosition = carViewModel.TablePosition;
                    }
                    catch (InvalidOperationException)
                    {
                        //not there so create new
                        carViewModel                         = new ViewModel.CarViewModel();
                        carViewModel.CarId                   = carMsg.CarId;
                        carViewModel.Position                = 0;
                        carViewModel.TablePosition           = 0;
                        carViewModel.IsDataEstimationEnabled = MainViewModel.IsDataEstimationEnabled;
                        _invisibleCars.Add(carViewModel);
                    }
                }

                UpdateCar(carViewModel, carMsg);
                UpdatePositionInList(oldPosition, carViewModel);
            });
        }
Ejemplo n.º 3
0
        public void UpdateGap(int tablePosition)
        {
            CarViewModel car = Cars[tablePosition - 1];

            if (1 == tablePosition)
            {
                if (car.IntervalType != F1.Messages.Car.CarBaseMessage.TimeType.NoData)
                {
                    car.SetGap(0.0, F1.Messages.Car.CarBaseMessage.TimeType.Lapped);
                }
            }
            else if (2 == tablePosition)
            {
                car.SetGap(car.IntervalRaw, car.IntervalType);
            }
            else if (tablePosition > 2)
            {
                CarViewModel carInFront = Cars[tablePosition - 2];
                if (carInFront.GapType == F1.Messages.Car.CarBaseMessage.TimeType.NLaps)
                {
                    if (car.IntervalType == F1.Messages.Car.CarBaseMessage.TimeType.NLaps)
                    {
                        car.SetGap(car.IntervalRaw + carInFront.GapRaw, carInFront.GapType);
                    }
                    else if (car.IntervalType == F1.Messages.Car.CarBaseMessage.TimeType.Time)
                    {
                        car.SetGap(carInFront.GapRaw, carInFront.GapType);
                    }
                }
                else if (carInFront.GapType == F1.Messages.Car.CarBaseMessage.TimeType.Time)
                {
                    if (car.IntervalType == F1.Messages.Car.CarBaseMessage.TimeType.Time)
                    {
                        car.SetGap(car.IntervalRaw + carInFront.GapRaw, carInFront.GapType);
                    }
                    else if (car.IntervalType == F1.Messages.Car.CarBaseMessage.TimeType.NLaps)
                    {
                        car.SetGap(car.IntervalRaw, car.IntervalType);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void UpdateCar(ViewModel.CarViewModel car, F1.Messages.ICarMessage msg)
        {
            if (msg is F1.Messages.Car.CarDriver)
            {
                F1.Messages.Car.CarDriver carDriver = (F1.Messages.Car.CarDriver)msg;
                if (carDriver.Name != "")
                {
                    car.DriverName = carDriver.Name;

                    try
                    {
                        MainViewModel.DriversNames.Add(Converters.DriverNameConverter.Shorten(carDriver.Name), carDriver.Name);
                    }
                    catch (ArgumentException)
                    {
                        //such key already exists
                    }
                }
                car.DriverNameColor = GetColor(msg.Colour);
            }

            if (msg is F1.Messages.Car.CarInterval)
            {
                F1.Messages.Car.CarInterval carInt = (F1.Messages.Car.CarInterval)msg;
                car.SetInterval(carInt.Interval, carInt.IntervalType, GetColor(msg.Colour));
                MainViewModel.UpdateGaps(car.TablePosition);
            }

            if (msg is F1.Messages.Car.CarLapTime)
            {
                F1.Messages.Car.CarLapTime carLapTime = (F1.Messages.Car.CarLapTime)msg;
                car.SetLapTime(carLapTime.LapTime, carLapTime.LapTimeType, GetColor(msg.Colour));
            }

            if (msg is F1.Messages.Car.CarLapCount)
            {
                F1.Messages.Car.CarLapCount lapCount = (F1.Messages.Car.CarLapCount)msg;
                car.LapCountSet   = lapCount.LapCount;
                car.LapCountColor = GetColor(msg.Colour);
            }

            if (msg is F1.Messages.Car.CarPitCount)
            {
                F1.Messages.Car.CarPitCount pitCount = (F1.Messages.Car.CarPitCount)msg;
                car.PitCountSet   = pitCount.Count;
                car.PitCountColor = GetColor(msg.Colour);
            }

            if (msg is F1.Messages.Car.CarSectorTime1)
            {
                F1.Messages.Car.CarSectorTime1 sect1 = (F1.Messages.Car.CarSectorTime1)msg;
                car.SetSector1Time(sect1.SectorTime, sect1.SectorTimeType, GetColor(msg.Colour));
            }

            if (msg is F1.Messages.Car.CarSectorTime2)
            {
                F1.Messages.Car.CarSectorTime2 sect2 = (F1.Messages.Car.CarSectorTime2)msg;
                car.SetSector2Time(sect2.SectorTime, sect2.SectorTimeType, GetColor(msg.Colour));
            }

            if (msg is F1.Messages.Car.CarSectorTime3)
            {
                F1.Messages.Car.CarSectorTime3 sect3 = (F1.Messages.Car.CarSectorTime3)msg;
                car.SetSector3Time(sect3.SectorTime, sect3.SectorTimeType, GetColor(msg.Colour));
            }

            if (msg is F1.Messages.Car.CarNumber)
            {
                F1.Messages.Car.CarNumber carNum = (F1.Messages.Car.CarNumber)msg;
                car.CarNumberSet   = carNum.Number;
                car.CarNumberColor = GetColor(msg.Colour);
            }

            if (msg is F1.Messages.Car.PracticeBestLapTime)
            {
                F1.Messages.Car.PracticeBestLapTime lapTime = (F1.Messages.Car.PracticeBestLapTime)msg;
                car.SetBestPracticeLapTime(lapTime.BestLap, lapTime.BestLapType, GetColor(msg.Colour));
                car.BestPracticeLapTimeColor = GetColor(lapTime.Colour);
            }

            if (msg is F1.Messages.Car.QualifyPeriodTime1)
            {
                F1.Messages.Car.QualifyPeriodTime1 q1Time = (F1.Messages.Car.QualifyPeriodTime1)msg;
                car.SetQ1Time(q1Time.SectorTime, q1Time.SectorTimeType, GetColor(msg.Colour));
            }

            if (msg is F1.Messages.Car.QualifyPeriodTime2)
            {
                F1.Messages.Car.QualifyPeriodTime2 q2Time = (F1.Messages.Car.QualifyPeriodTime2)msg;
                car.SetQ2Time(q2Time.SectorTime, q2Time.SectorTimeType, GetColor(msg.Colour));
            }

            if (msg is F1.Messages.Car.QualifyPeriodTime3)
            {
                F1.Messages.Car.QualifyPeriodTime3 q3Time = (F1.Messages.Car.QualifyPeriodTime3)msg;
                car.SetQ3Time(q3Time.SectorTime, q3Time.SectorTimeType, GetColor(msg.Colour));
            }


            if (msg is F1.Messages.Car.CarPosition)
            {
                F1.Messages.Car.CarPosition carPos = (F1.Messages.Car.CarPosition)msg;

                car.Position = carPos.Position;

                if (msg.Colour != F1.Messages.CarColours.Unknown)
                {
                    car.PositionColor = GetColor(msg.Colour);
                }
            }

            if (msg is F1.Messages.Car.CarPositionUpdate)
            {
                F1.Messages.Car.CarPositionUpdate carPos = (F1.Messages.Car.CarPositionUpdate)msg;

                if (carPos.Position >= 0)
                {
                    //car.Position = carPos.Position;
                    car.TablePosition = carPos.Position;
                }

                if (msg.Colour != F1.Messages.CarColours.Unknown)
                {
                    car.PositionColor = GetColor(msg.Colour);
                }
            }

            if (msg is F1.Messages.Car.CarGap)
            {
                F1.Messages.Car.CarGap carGap = (F1.Messages.Car.CarGap)msg;
                car.SetGap(carGap.Gap, carGap.GapType);
                car.GapColor = GetColor(msg.Colour);
            }
        }