internal void DecodeSettings([NotNull] SettingsDictionary settingsDictionary, SettingsProfile profile) { lock (SettingsLock) { foreach (var settings in settingsDictionary) { SettingsKey key; var value = settings.Value; object finalValue = value; if (settingsKeys.TryGetValue(settings.Key, out key)) { finalValue = key.ConvertValue(value); } profile.SetValue(settings.Key, finalValue); } } }
private void ChangeCurrentProfile([NotNull] SettingsProfile oldProfile, [NotNull] SettingsProfile newProfile) { if (oldProfile == null) { throw new ArgumentNullException(nameof(oldProfile)); } if (newProfile == null) { throw new ArgumentNullException(nameof(newProfile)); } currentProfile = newProfile; lock (SettingsLock) { foreach (var key in settingsKeys) { object oldValue; oldProfile.GetValue(key.Key, out oldValue, true, false); object newValue; newProfile.GetValue(key.Key, out newValue, true, false); var oldList = oldValue as IList; var newList = newValue as IList; var oldDictionary = oldValue as IDictionary; var newDictionary = newValue as IDictionary; bool isDifferent; if (oldList != null && newList != null) { isDifferent = oldList.Count != newList.Count; for (int i = 0; i < oldList.Count && !isDifferent; ++i) { if (!Equals(oldList[i], newList[i])) { isDifferent = true; } } } else if (oldDictionary != null && newDictionary != null) { isDifferent = oldDictionary.Count != newDictionary.Count; foreach (var k in oldDictionary.Keys) { if (!newDictionary.Contains(k) || !Equals(oldDictionary[k], newDictionary[k])) { isDifferent = true; } } } else { isDifferent = !Equals(oldValue, newValue); } if (isDifferent) { newProfile.NotifyEntryChanged(key.Key); } } } // Changes have been notified, empty the list of modified settings. newProfile.ValidateSettingsChanges(); }
public SettingsProfile LoadSettingsProfile([NotNull] UFile filePath, bool setAsCurrent, SettingsProfile parent = null, bool registerInContainer = true) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } if (setAsCurrent && !registerInContainer) { throw new ArgumentException(@"Cannot set the profile as current if it's not registered to the container", nameof(setAsCurrent)); } if (!File.Exists(filePath)) { Logger.Error($"Settings file [{filePath}] was not found"); return(null); } var profile = new SettingsProfile(this, parent ?? RootProfile) { FilePath = filePath }; try { var settingsFile = new SettingsFile(profile); using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { SettingsYamlSerializer.Default.Deserialize(stream, settingsFile); } } catch (Exception) { return(null); } if (registerInContainer) { lock (SettingsLock) { profileList.Add(profile); if (setAsCurrent) { CurrentProfile = profile; } } } var handler = SettingsFileLoaded; handler?.Invoke(null, new SettingsFileLoadedEventArgs(filePath)); return(profile); }
/// <summary> /// Initializes a new instance of the <see cref="SettingsFile"/> class. /// </summary> public SettingsFile(SettingsProfile profile) { Settings = profile; }
/// <summary> /// Initializes a new instance of the <see cref="ChangesValidatedEventArgs"/> class. /// </summary> /// <param name="profile">The profile in which changes have been validated.</param> public ChangesValidatedEventArgs(SettingsProfile profile) { Profile = profile; }
/// <summary> /// Initializes a new instance of the <see cref="SettingsProfile"/> class. /// </summary> /// <param name="container">The <see cref="SettingsContainer"/> containing this profile.</param> /// <param name="parentProfile">The parent profile.</param> internal SettingsProfile(SettingsContainer container, SettingsProfile parentProfile) { Container = container; this.parentProfile = parentProfile; }
/// <summary> /// Initializes a new instance of the <see cref="FileModifiedEventArgs"/> /// </summary> /// <param name="profile">The profile corresponding to the file that has been modified.</param> public FileModifiedEventArgs(SettingsProfile profile) { Profile = profile; }