public void GetUserScopedPropertyValues()
        {
            SettingsAttributeDictionary dict = new SettingsAttributeDictionary();
            UserScopedSettingAttribute  attr = new UserScopedSettingAttribute();

            dict.Add(attr.GetType(), attr);

            LocalFileSettingsProvider prov = new LocalFileSettingsProvider();
            SettingsContext           ctx  = new SettingsContext();
            SettingsProperty          p    = new SettingsProperty("property",
                                                                  typeof(int),
                                                                  prov,
                                                                  false,
                                                                  10,
                                                                  SettingsSerializeAs.Binary,
                                                                  dict,
                                                                  false,
                                                                  false);
            SettingsPropertyCollection      col = new SettingsPropertyCollection();
            SettingsPropertyValueCollection vals;

            col.Add(p);

            prov.Initialize(null, null);

            vals = prov.GetPropertyValues(ctx, col);
            Assert.IsNotNull(vals, "A1");
            Assert.AreEqual(1, vals.Count, "A2");
        }
Ejemplo n.º 2
0
        public void AddPropertySetting(string name, Type type, object defaultValue)
        {
            // Only allow settings to be added during initialization
            if (!_initialized)
            {
                string providerName = "LocalFileSettingsProvider";

                SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
                UserScopedSettingAttribute  attr       = new UserScopedSettingAttribute();
                attributes.Add(attr.TypeId, attr);

                var prop = new SettingsProperty(
                    new SettingsProperty(name
                                         , type
                                         , cairoSettings.Providers[providerName]
                                         , false
                                         , defaultValue
                                         , SettingsSerializeAs.String
                                         , attributes
                                         , false
                                         , false));

                cairoSettings.Properties.Add(prop);
                cairoSettings.Save();
                cairoSettings.Reload();
            }
        }
Ejemplo n.º 3
0
        public static string GetCredentialStoreServiceName()
        {
            var propertyName = "CredentialStoreServiceName";
            var providerName = "LocalFileSettingsProvider";

            if (!string.IsNullOrWhiteSpace(Settings.Default.Properties[propertyName]?.DefaultValue.ToString()))
            {
                var attributes = new SettingsAttributeDictionary();
                var attr       = new UserScopedSettingAttribute();
                attributes.Add(attr.TypeId, attr);

                var prop = new SettingsProperty(
                    propertyName,
                    typeof(string),
                    Settings.Default.Providers[providerName],
                    false, DefaultCredentialStoreServiceName, SettingsSerializeAs.String, attributes, false, false);

                Settings.Default.Properties.Add(prop);
                Settings.Default.Save();
                Settings.Default.Reload();
            }

            var result = Settings.Default.Properties[propertyName]?.ToString();

            if (result != null)
            {
                Console.WriteLine(result);
                return(result);
            }

            return(DefaultCredentialStoreServiceName);
        }
        /// <summary>
        /// Returns true if the property is decorated with a <see cref="UserScopedSettingAttribute"/>.
        /// </summary>
        public static bool IsUserScoped(PropertyInfo property)
        {
            UserScopedSettingAttribute a = CollectionUtils.FirstElement <UserScopedSettingAttribute>(
                property.GetCustomAttributes(typeof(UserScopedSettingAttribute), false));

            return(a != null);
        }
Ejemplo n.º 5
0
        protected void CreateSettingProperty(string name, Type type, SettingsSerializeAs serializeAs, object defaultValue)
        {
            ApplicationSettings _applicationSettings = ApplicationSettings;

            if (_applicationSettings == null || _applicationSettings.DefaultProvider == null)
            {
                return;
            }

            SettingsProperty _settingsProperty = _applicationSettings.Properties[name];

            if (_settingsProperty != null)
            {
                return; // already present
            }

            SettingsAttributeDictionary _attributes = new SettingsAttributeDictionary();
            SettingAttribute            _attribute;

            switch (Scope)
            {
            case SettingScope.Application:
                // attribute = new ApplicationScopedSettingAttribute();
                throw new NotImplementedException();     // currently not supported

            case SettingScope.User:
                _attribute = new UserScopedSettingAttribute();
                break;

            default:
                return;
            }

            _attributes.Add(_attribute.TypeId, _attribute);

            _settingsProperty = new SettingsProperty(
                name,                                 // name
                type,                                 // type
                _applicationSettings.DefaultProvider, // settings provider
                false,                                // is readonly
                defaultValue,                         // default
                serializeAs,                          // serialize as
                _attributes,                          // attribute
                ThrowOnErrorDeserializing,            // throw on deserialization
                ThrowOnErrorSerializing);             // throw on serialization

            _applicationSettings.Properties.Add(_settingsProperty);
        }
Ejemplo n.º 6
0
 public static void EnsureProperties(FrameworkElement sender, Dictionary <FrameworkElement, DependencyProperty> savedElements)
 {
     foreach (FrameworkElement element in savedElements.Keys)
     {
         bool hasProperty =
             Properties.Settings.Default.Properties[sender.Name + "." + element.Name] != null;
         if (!hasProperty)
         {
             SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
             UserScopedSettingAttribute  attribute  = new UserScopedSettingAttribute();
             attributes.Add(attribute.GetType(), attribute);
             SettingsProperty property = new SettingsProperty(sender.Name + "." + element.Name,
                                                              savedElements[element].DefaultMetadata.DefaultValue.GetType(), Properties.Settings.Default.Providers["LocalFileSettingsProvider"], false, null, SettingsSerializeAs.String, attributes, true, true);
             Properties.Settings.Default.Properties.Add(property);
         }
     }
     Properties.Settings.Default.Reload();
 }
Ejemplo n.º 7
0
        public void CreateSettingProperty(string name, Type type, SettingsSerializeAs serializeAs, object defaultValue)
        {
            var settingsProperty = Properties[name];

            if (settingsProperty != null)
            {
                return;
            }

            var attributes = new SettingsAttributeDictionary();
            var attribute  = new UserScopedSettingAttribute();

            attributes.Add(attribute.TypeId, attribute);

            settingsProperty = new SettingsProperty(
                name, type, DefaultProvider,
                false, defaultValue, serializeAs,
                attributes, false, false);

            Properties.Add(settingsProperty);
        }