예제 #1
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);
            }
        }