예제 #1
0
        private static void ValidateStoredValues(Type type, MigrationScope migrationScope, SettingValue expectedValue)
        {
            var settings = ApplicationSettingsHelper.GetSettingsClassInstance(type);

            foreach (SettingsProperty property in settings.Properties)
            {
                string expected = CreateSettingValue(property, migrationScope, expectedValue);
                if (migrationScope == MigrationScope.User)
                {
                    if (SettingsPropertyExtensions.IsAppScoped(property))
                    {
                        continue;
                    }

                    string actual = (string)settings[property.Name];
                    Assert.AreEqual(expected, actual);
                }
                else
                {
                    if (SettingsPropertyExtensions.IsAppScoped(property))
                    {
                        string actual = (string)settings[property.Name];
                        Assert.AreEqual(expected, actual);
                    }

                    string shared = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name);
                    Assert.AreEqual(expected, shared);
                }
            }
        }
예제 #2
0
        private void TestGetSharedSettings_NoneExist(Type settingsClass)
        {
            RemoveSettings(settingsClass);

            var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass);

            settings.Reload();

            foreach (SettingsProperty property in settings.Properties)
            {
                var shared = settings.GetSharedPropertyValue(property.Name);
                Assert.AreEqual(property.DefaultValue, shared);

                if (SettingsPropertyExtensions.IsAppScoped(property))
                {
                    Assert.AreEqual(property.DefaultValue, settings[property.Name]);
                }
            }
        }
예제 #3
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

            foreach (SettingsProperty property in collection)
            {
                if (SettingsPropertyExtensions.IsUserScoped(property))
                {
                    SettingsPropertyValue value = SimpleSettingsStore.Instance.CurrentUserValues[property.Name] ?? new SettingsPropertyValue(property);
                    values.Add(value);
                }
                else
                {
                    SettingsPropertyValue value = SimpleSettingsStore.Instance.CurrentSharedValues[property.Name] ?? new SettingsPropertyValue(property);
                    values.Add(value);
                }
            }

            return(values);
        }
예제 #4
0
        private void TestGetSharedSettings_Exists(Type settingsClass)
        {
            RemoveSettings(settingsClass);

            SystemConfigurationHelperTests.WriteSharedValuesToConfig(settingsClass, SettingValue.Current);
            var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass);

            settings.Reload();

            foreach (SettingsProperty property in settings.Properties)
            {
                var    shared   = settings.GetSharedPropertyValue(property.Name);
                string expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current);
                Assert.AreEqual(expected, shared);

                if (SettingsPropertyExtensions.IsAppScoped(property))
                {
                    Assert.AreEqual(expected, settings[property.Name]);
                }
            }
        }
예제 #5
0
        public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
        {
            foreach (SettingsProperty property in properties)
            {
                if (!SettingsPropertyExtensions.IsUserScoped(property))
                {
                    continue;
                }

                SettingsPropertyValue previousValue = SimpleSettingsStore.Instance.PreviousUserValues[property.Name];
                if (previousValue == null)
                {
                    continue;
                }

                SettingsPropertyValue currentValue = SimpleSettingsStore.Instance.CurrentUserValues[property.Name];
                if (currentValue == null)
                {
                    continue;
                }

                currentValue.PropertyValue = previousValue.PropertyValue;
            }
        }