Ejemplo n.º 1
0
 /// <summary>
 /// Clears the current settings, by removing registered <see cref="SettingsKey"/> and <see cref="SettingsProfile"/> instances. This method should be used only for tests.
 /// </summary>
 public void ClearSettings()
 {
     lock (SettingsLock)
     {
         CurrentProfile = RootProfile;
         CurrentProfile.ValidateSettingsChanges();
         profileList.Clear();
         RootProfile.Settings.Clear();
         settingsKeys.Clear();
     }
 }
Ejemplo n.º 2
0
        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();
        }