private void ApplyChanges(ICollection <Profile> profiles, int defaultProfileId) { if (profiles == null) { throw new ArgumentException("profiles argument cannot be null"); } this.Profiles.Clear(); //Add clones of instances foreach (Profile p in profiles) { Profile newProfile = new Profile(p); IConfiguration config = ConfigurationManager.GetConfiguration(p.GameModel); if (config == null) { newProfile.GameModel.Type = ConfigurationManager.First().GameType; } Profiles.Add(newProfile); } DefaultProfile = Profiles.FirstOrDefault(i => i.Id == defaultProfileId); if (DefaultProfile == null) { DefaultProfile = Profiles.First(); } if (_CurrentProfile != null) { _CurrentProfile = Profiles.FirstOrDefault(i => i.Id == _CurrentProfile.Id); } if (_CurrentProfile == null) { _CurrentProfile = DefaultProfile; } if (_CurrentProfile == null) { _CurrentProfile = Profiles.First(); } OnCollectionChanged(); OnCurrentChanged(); }
private void OnConfigurationUnRegistered(object sender, ConfigurationChangedEventArgs e) { List <Profile> invalidProfiles = Profiles.Where(p => e.Configuration.GameType.Equals(p.GameModel.Type)).ToList(); if (invalidProfiles.Count == 0) { return; } bool updateCurrent = false; string newType = ConfigurationManager.First().GameType; foreach (Profile p in invalidProfiles) { p.GameModel.Type = newType; updateCurrent = updateCurrent || p.Equals(CurrentProfile); } RevertChanges(); OnCollectionChanged(); if (updateCurrent) { OnCurrentChanged(); } }