protected virtual void OnModelAvailable(ModelAvailableEventArgs e) { if (ModelAvailable != null) { ModelAvailable(e); } }
public void Service_ModelAvailable(ModelAvailableEventArgs e) { List<string> keys = _vehicles.Keys.Cast<string>().ToList(); //remove all vehicles not presented in new list foreach (string s in keys) { if (!e.Data.ContainsKey(s)) _vehicles.Remove(s); } //add new and update old vehicles foreach (string s in e.Data.Keys) { if (!_vehicles.ContainsKey(s)) _vehicles.Add(s, e.Data[s]); else { //have selected vehicle moved? bool selectedLocationChanged = false; /* if (SelectedVehicle != null && SelectedVehicle.VehicleRef == ((Vehicle)e.Data[s]).VehicleRef && (SelectedVehicle.Longitude != ((Vehicle)e.Data[s]).Longitude || SelectedVehicle.Latitude != ((Vehicle)e.Data[s]).Latitude)) { selectedLocationChanged = true; } */ ((Vehicle)_vehicles[s]).LineRef = ((Vehicle)e.Data[s]).LineRef; ((Vehicle)_vehicles[s]).Longitude = ((Vehicle)e.Data[s]).Longitude; ((Vehicle)_vehicles[s]).Latitude = ((Vehicle)e.Data[s]).Latitude; //change location of selected vehicle if has been moved if (selectedLocationChanged) { /* List<Vehicle> vl = new List<Vehicle>(); vl.Add(SelectedVehicle); SelectedVehicleLocation = vl; * */ } } } RaisePropertyChanged(VehiclesProperty); }