void _lt_CarMessageHandler(F1.Messages.IMessage msg) { Dispatcher.BeginInvoke(() => { listBox1.Items.Add(msg.ToString()); }); }
void _lt_ControlMessageHandler(F1.Messages.IMessage msg) { var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { MainViewModel.ProgressIsVisible = false; if (msg.Type == F1.Enums.SystemPacketType.ControlType) { MessageDialog dlg = new MessageDialog("Please check credentials or try again later."); await dlg.ShowAsync(); } }); }
void _lt_ControlMessageHandler(F1.Messages.IMessage msg) { Deployment.Current.Dispatcher.BeginInvoke(() => { if (MainViewModel.ProgressText.Contains("Connecting")) { MainViewModel.ProgressIsVisible = false; } if (msg is F1.Messages.Control.AuthorizationProblem) { MessageBox.Show("Please check credentials or try again later.", "Connection problem", MessageBoxButton.OK); } }); }
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); }); }
void _lt_CarMessageHandler(F1.Messages.IMessage msg) { var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { MainViewModel.ProgressIsVisible = false; F1.Messages.ICarMessage carMsg = (F1.Messages.ICarMessage)msg; ViewModels.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 ViewModels.CarViewModel(); carViewModel.CarId = carMsg.CarId; carViewModel.Position = 0; carViewModel.TablePosition = 0; carViewModel.IsDataEstimationEnabled = MainViewModel.IsDataEstimationEnabled; _invisibleCars.Add(carViewModel); } } UpdateCar(carViewModel, carMsg); UpdatePositionInList(oldPosition, carViewModel); }); }
void _lt_ControlMessageHandler(F1.Messages.IMessage msg) { }
void _lt_SystemMessageHandler(F1.Messages.IMessage msg) { Deployment.Current.Dispatcher.BeginInvoke(() => { if (MainViewModel.ProgressText.Contains("Connecting")) { MainViewModel.ProgressIsVisible = false; } if (msg is F1.Messages.System.Copyright) { F1.Messages.System.Copyright system = (F1.Messages.System.Copyright)msg; MainViewModel.Copyright = system.Message; } if (msg is F1.Messages.System.EventId) { F1.Messages.System.EventId eventId = (F1.Messages.System.EventId)msg; MainViewModel.EventType = eventId.EventType; } if (msg is F1.Messages.System.TrackStatus) { F1.Messages.System.TrackStatus trackStatus = (F1.Messages.System.TrackStatus)msg; MainViewModel.TrackStatusColor = trackStatus.Status; MainViewModel.TrackStatusMessage = trackStatus.Message; } if (msg is F1.Messages.System.Commentary) { F1.Messages.System.Commentary commentary = (F1.Messages.System.Commentary)msg; CommentViewModel commentViewModel = new CommentViewModel(); commentViewModel.Comment = commentary.Message; MainViewModel.Comments.Add(commentViewModel); MainViewModel.LastComment = commentary.Message; } if (msg is F1.Messages.System.TimeStamp) { F1.Messages.System.TimeStamp time = (F1.Messages.System.TimeStamp)msg; MainViewModel.EventTimeElapsed = time.Time; } if (msg is F1.Messages.System.WeatherSessionClock) { F1.Messages.System.WeatherSessionClock weather = (F1.Messages.System.WeatherSessionClock)msg; if (weather.TimeStr == "") { MainViewModel.AllowTimeEstimation = true; //start the timer if (_timer == null) { _timer = new Timer(SessionTimerCallback, null, 0, 1000); } } else { //stop the timer if (_timer != null) { _timer.Dispose(); _timer = null; } //set correct remaining time MainViewModel.AllowTimeEstimation = false; MainViewModel.LastCorrectRemainingTime = weather.Time; } } if (msg is F1.Messages.System.EndOfSession) { if (_timer != null) { _timer.Dispose(); _timer = null; } MainViewModel.AllowTimeEstimation = false; MainViewModel.LastCorrectRemainingTime = TimeSpan.Zero; } if (msg is F1.Messages.System.WeatherAirTemperature) { F1.Messages.System.WeatherAirTemperature weather = (F1.Messages.System.WeatherAirTemperature)msg; MainViewModel.WeatherAirTemperature = weather.Temperature; } if (msg is F1.Messages.System.WeatherHumidity) { F1.Messages.System.WeatherHumidity weather = (F1.Messages.System.WeatherHumidity)msg; MainViewModel.WeatherHumidity = weather.Humidity; } if (msg is F1.Messages.System.WeatherPressure) { F1.Messages.System.WeatherPressure weather = (F1.Messages.System.WeatherPressure)msg; MainViewModel.WeatherPressure = weather.Pressure; } if (msg is F1.Messages.System.WeatherTrackTemperature) { F1.Messages.System.WeatherTrackTemperature weather = (F1.Messages.System.WeatherTrackTemperature)msg; MainViewModel.WeatherTrackTemperature = weather.Temperature; } if (msg is F1.Messages.System.WeatherWetTrack) { F1.Messages.System.WeatherWetTrack weather = (F1.Messages.System.WeatherWetTrack)msg; MainViewModel.WeatherIsWet = weather.IsWet; } if (msg is F1.Messages.System.WeatherWindDirection) { F1.Messages.System.WeatherWindDirection weather = (F1.Messages.System.WeatherWindDirection)msg; MainViewModel.WeatherWindDirection = weather.WindDirection; } if (msg is F1.Messages.System.WeatherWindSpeed) { F1.Messages.System.WeatherWindSpeed weather = (F1.Messages.System.WeatherWindSpeed)msg; MainViewModel.WeatherWindSpeed = weather.Speed; } if (msg is F1.Messages.System.Speed) { F1.Messages.System.Speed speed = (F1.Messages.System.Speed)msg; switch (speed.Column) { case F1.Messages.System.Speed.ColumnType.FastestSector1: { MainViewModel.SpeedSector1.Clear(); foreach (var pair in speed.FastestSectors) { if (MainViewModel.DriversNames.ContainsKey(pair.Driver)) { pair.Driver = MainViewModel.DriversNames[pair.Driver]; } MainViewModel.SpeedSector1.Add(new SpeedViewModel() { DriverName = pair.Driver, Speed = pair.Speed }); } break; } case F1.Messages.System.Speed.ColumnType.FastestSector2: { MainViewModel.SpeedSector2.Clear(); foreach (var pair in speed.FastestSectors) { if (MainViewModel.DriversNames.ContainsKey(pair.Driver)) { pair.Driver = MainViewModel.DriversNames[pair.Driver]; } MainViewModel.SpeedSector2.Add(new SpeedViewModel() { DriverName = pair.Driver, Speed = pair.Speed }); } break; } case F1.Messages.System.Speed.ColumnType.FastestSector3: { MainViewModel.SpeedSector3.Clear(); foreach (var pair in speed.FastestSectors) { if (MainViewModel.DriversNames.ContainsKey(pair.Driver)) { pair.Driver = MainViewModel.DriversNames[pair.Driver]; } MainViewModel.SpeedSector3.Add(new SpeedViewModel() { DriverName = pair.Driver, Speed = pair.Speed }); } break; } case F1.Messages.System.Speed.ColumnType.FastestInTrap: { MainViewModel.SpeedTrap.Clear(); foreach (var pair in speed.FastestSectors) { if (MainViewModel.DriversNames.ContainsKey(pair.Driver)) { pair.Driver = MainViewModel.DriversNames[pair.Driver]; } MainViewModel.SpeedTrap.Add(new SpeedViewModel() { DriverName = pair.Driver, Speed = pair.Speed }); } break; } case F1.Messages.System.Speed.ColumnType.FastestDriverName: MainViewModel.FastestDriverName = speed.MetaData; break; case F1.Messages.System.Speed.ColumnType.FastestDriverNumber: MainViewModel.FastestDriverNumber = speed.MetaData; break; case F1.Messages.System.Speed.ColumnType.FastestLapNumber: MainViewModel.FastestLapNumber = speed.MetaData; break; case F1.Messages.System.Speed.ColumnType.FastestLapTime: MainViewModel.FastestLapTime = speed.MetaData; break; } } }); }