Example #1
0
        /// <summary>
        /// Gets the <see cref="SettingsEntry"/> that matches the given name.
        /// </summary>
        /// <param name="name">The name of the <see cref="SettingsEntry"/> to fetch.</param>
        /// <param name="searchInParent">Indicates whether to search in the parent profile, if the name is not found in this profile.</param>
        /// <param name="createInCurrentProfile"></param>
        /// <returns>An instance of <see cref="SettingsEntry"/> that matches the name, or <c>null</c>.</returns>
        private SettingsEntry GetEntry(UFile name, bool searchInParent, bool createInCurrentProfile)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            lock (SettingsContainer.SettingsLock)
            {
                SettingsEntry entry;
                if (Settings.TryGetValue(name, out entry))
                {
                    return(entry);
                }

                if (createInCurrentProfile)
                {
                    entry = parentProfile.GetEntry(name, true, false);
                    entry = SettingsEntry.CreateFromValue(this, name, entry.Value);
                    RegisterEntry(entry);
                    return(entry);
                }
            }

            return(parentProfile != null && searchInParent?parentProfile.GetEntry(name, true, false) : null);
        }
Example #2
0
 /// <summary>
 /// Registers an entry that has not been registered before.
 /// </summary>
 /// <param name="entry">The entry to register.</param>
 internal void RegisterEntry(SettingsEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     Settings.Add(entry.Name, entry);
 }
Example #3
0
 /// <summary>
 /// Registers an entry that has not been registered before.
 /// </summary>
 /// <param name="entry">The entry to register.</param>
 internal void RegisterEntry(SettingsEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException(nameof(entry));
     }
     lock (SettingsContainer.SettingsLock)
     {
         Settings.Add(entry.Name, entry);
     }
 }
Example #4
0
        /// <summary>
        /// Gets the settings value that matches the given name.
        /// </summary>
        /// <param name="name">The name of the <see cref="SettingsEntry"/> to fetch.</param>
        /// <param name="value">The resulting value if the name is found, <c>null</c> otherwise.</param>
        /// <param name="searchInParent">Indicates whether to search in the parent profile, if the name is not found in this profile.</param>
        /// <param name="createInCurrentProfile">If true, the list will be created in the current profile, from the value of its parent profile.</param>
        /// <returns><c>true</c> if an entry matching the name is found, <c>false</c> otherwise.</returns>
        internal bool GetValue(UFile name, out object value, bool searchInParent, bool createInCurrentProfile)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            SettingsEntry entry = GetEntry(name, searchInParent, createInCurrentProfile);

            if (entry != null)
            {
                value = entry.Value;
                return(true);
            }
            value = null;
            return(false);
        }
Example #5
0
        internal void RegisterSettingsKey(UFile name, object defaultValue, SettingsKey settingsKey)
        {
            settingsKeys.Add(name, settingsKey);
            var entry = SettingsEntry.CreateFromValue(defaultProfile, name, defaultValue);

            defaultProfile.RegisterEntry(entry);
            // Ensure that the value is converted to the key type in each loaded profile.
            foreach (var profile in Profiles.Where(x => x != defaultProfile))
            {
                if (profile.Settings.TryGetValue(name, out entry))
                {
                    var parsingEvents  = entry.Value as List <ParsingEvent>;
                    var convertedValue = parsingEvents != null?settingsKey.ConvertValue(parsingEvents) : entry.Value;

                    entry = SettingsEntry.CreateFromValue(profile, name, convertedValue);
                    profile.Settings[name] = entry;
                }
            }
        }
Example #6
0
        /// <summary>
        /// Set the value of the entry that match the given name.
        /// </summary>
        /// <param name="name">The name to match.</param>
        /// <param name="value">The value to set.</param>
        internal void SetValue(UFile name, object value)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            SettingsEntry entry;

            if (!Settings.TryGetValue(name, out entry))
            {
                entry          = SettingsEntry.CreateFromValue(this, name, value);
                Settings[name] = entry;
            }
            else
            {
                Settings[name].Value = value;
            }
        }
Example #7
0
        /// <summary>
        /// Set the value of the entry that match the given name.
        /// </summary>
        /// <param name="name">The name to match.</param>
        /// <param name="value">The value to set.</param>
        internal void SetValue([NotNull] UFile name, object value)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            lock (SettingsContainer.SettingsLock)
            {
                SettingsEntry entry;
                if (!Settings.TryGetValue(name, out entry))
                {
                    entry          = SettingsEntry.CreateFromValue(this, name, value);
                    Settings[name] = entry;
                }
                else
                {
                    Settings[name].Value = value;
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsEntryChangeValueOperation"/> class.
 /// </summary>
 /// <param name="entry">The settings entry that has been modified.</param>
 /// <param name="oldValue">The value of the settings entry before the modification.</param>
 public SettingsEntryChangeValueOperation(SettingsEntry entry, object oldValue)
 {
     this.entry = entry;
     this.oldValue = oldValue;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsEntryChangeValueOperation"/> class.
 /// </summary>
 /// <param name="entry">The settings entry that has been modified.</param>
 /// <param name="oldValue">The value of the settings entry before the modification.</param>
 public SettingsEntryChangeValueOperation(SettingsEntry entry, object oldValue)
 {
     this.entry    = entry;
     this.oldValue = oldValue;
 }
Example #10
0
 /// <summary>
 /// Registers an entry that has not been registered before.
 /// </summary>
 /// <param name="entry">The entry to register.</param>
 internal void RegisterEntry(SettingsEntry entry)
 {
     if (entry == null) throw new ArgumentNullException("entry");
     Settings.Add(entry.Name, entry);
 }