Exemple #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([NotNull] 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);
        }
Exemple #2
0
 /// <summary>
 /// Registers an entry that has not been registered before.
 /// </summary>
 /// <param name="entry">The entry to register.</param>
 internal void RegisterEntry([NotNull] SettingsEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException(nameof(entry));
     }
     lock (SettingsContainer.SettingsLock)
     {
         Settings.Add(entry.Name, entry);
     }
 }
Exemple #3
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([NotNull] 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);
        }
Exemple #4
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;
                }
            }
        }
Exemple #5
0
        internal void RegisterSettingsKey([NotNull] UFile name, object defaultValue, SettingsKey settingsKey)
        {
            lock (SettingsLock)
            {
                settingsKeys.Add(name, settingsKey);
                var entry = SettingsEntry.CreateFromValue(RootProfile, name, defaultValue);
                RootProfile.RegisterEntry(entry);

                // Ensure that the value is converted to the key type in each loaded profile.
                foreach (var profile in Profiles.Where(x => x != RootProfile))
                {
                    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;
                    }
                }
            }
        }
Exemple #6
0
 /// <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;
 }