public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) { XmlSettingsFile localFile = XmlSettingsFile.GetLocalSettingsFile(GetTypeFromContext(context)); XmlSettingsFile roamingFile = XmlSettingsFile.GetRoamingSettingsFile(GetTypeFromContext(context)); SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); foreach (SettingsProperty setting in props) { SettingsPropertyValue value = new SettingsPropertyValue(setting); value.IsDirty = false; if (IsRoaming(setting)) { value.SerializedValue = roamingFile.GetValue(setting); } else { value.SerializedValue = localFile.GetValue(setting); } values.Add(value); } return values; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { // set all of the inherited default values first in case we have failure later SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection(); foreach (SettingsProperty prop in collection) { SettingsPropertyValue spv = new SettingsPropertyValue(prop); spv.SerializedValue = prop.DefaultValue; settings.Add(spv); } // now read in overridden user settings try { Configuration config = null; ClientSettingsSection clientSettings = GetUserSettings(out config, true); foreach (SettingsPropertyValue spv in settings) { DeserializeFromXmlElement(spv.Property, spv, clientSettings); } } catch { // suppress } return settings; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { SettingsPropertyValueCollection result = new SettingsPropertyValueCollection(); if (collection.Count < 1) return result; string userEmail = (string) context["UserName"]; //Эта строка мне пока не понятна if (string.IsNullOrEmpty(userEmail)) return result; var user = UserService.GetByEmail(userEmail); var profile = ProfileService.GetProfile(user); foreach (SettingsProperty prop in collection) { SettingsPropertyValue svp = new SettingsPropertyValue(prop) { PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null) }; result.Add(svp); } return result; }
public static SettingsPropertyValueCollection GetSharedPropertyValues(LocalFileSettingsProvider provider, SettingsContext context, SettingsPropertyCollection properties, string currentExeConfigFilename = null) { var settingsClass = (Type)context["SettingsClassType"]; var systemConfiguration = String.IsNullOrEmpty(currentExeConfigFilename) ? SystemConfigurationHelper.GetExeConfiguration() : SystemConfigurationHelper.GetExeConfiguration(currentExeConfigFilename); var storedValues = systemConfiguration.GetSettingsValues(settingsClass); // Create new collection of values var values = new SettingsPropertyValueCollection(); foreach (SettingsProperty setting in properties) { var value = new SettingsPropertyValue(setting) { SerializedValue = storedValues.ContainsKey(setting.Name) ? storedValues[setting.Name] : null, IsDirty = false }; // use the stored value, or set the SerializedValue to null, which tells .NET to use the default value values.Add(value); } return values; }
/// <summary> /// Returns the collection of settings property values for the specified application instance and settings property group. /// </summary> /// <returns> /// A <see cref="T:System.Configuration.SettingsPropertyValueCollection"/> containing the values for the specified settings property group. /// </returns> /// <param name="context">A <see cref="T:System.Configuration.SettingsContext"/> describing the current application use. /// </param><param name="collection">A <see cref="T:System.Configuration.SettingsPropertyCollection"/> containing the settings property group whose values are to be retrieved. /// </param><filterpriority>2</filterpriority> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { var username = (string) context["UserName"]; var isAuthenticated = (bool) context["IsAuthenticated"]; Profile profile = ProfileManager.Instance.GetCurrentUser(username); var svc = new SettingsPropertyValueCollection(); foreach (SettingsProperty prop in collection) { var pv = new SettingsPropertyValue(prop); switch (pv.Property.Name) { case _PROFILE_SHOPPINGCART: pv.PropertyValue = CartList.GetCart(profile.UniqueID, true); break; case _PROFILE_WISHLIST: pv.PropertyValue = CartList.GetCart(profile.UniqueID, false); break; case _PROFILE_ACCOUNT: if (isAuthenticated) pv.PropertyValue = new Address(profile); break; default: throw new ApplicationException(string.Format("{0} name.", _ERR_INVALID_PARAMETER)); } svc.Add(pv); } return svc; }
/// <summary> /// Returns the collection of settings property values for the specified application instance and settings property group. /// </summary> /// <param name="context">A System.Configuration.SettingsContext describing the current application use.</param> /// <param name="collection">A System.Configuration.SettingsPropertyCollection containing the settings property group whose values are to be retrieved.</param> /// <returns>A System.Configuration.SettingsPropertyValueCollection containing the values for the specified settings property group.</returns> public override SettingsPropertyValueCollection GetPropertyValues( SettingsContext context, SettingsPropertyCollection collection) { string username = (string)context["UserName"]; bool isAuthenticated = (bool) context["IsAuthenticated"]; SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection(); foreach (SettingsProperty prop in collection) { SettingsPropertyValue pv = new SettingsPropertyValue(prop); switch (pv.Property.Name) { case PROFILE_SHOPPINGCART: pv.PropertyValue = GetCartItems(username, true); break; case PROFILE_WISHLIST: pv.PropertyValue = GetCartItems(username, false); break; case PROFILE_ACCOUNT: if (isAuthenticated) pv.PropertyValue = GetAccountInfo(username); break; default: throw new ApplicationException(ERR_INVALID_PARAMETER + " name."); } svc.Add(pv); } return svc; }
private void CreatePropNode(SettingsProperty setting, SettingsPropertyValue value, SettingsContext context) { string xPathQuery = getXPathQuerySection(setting, context); XmlNode groupNode = doc.SelectSingleNode(xPathQuery); if (groupNode == null) { groupNode = doc.CreateElement(GetSectionName(context)); if (this.IsUserScoped(setting)) { userSettings.AppendChild(groupNode); } else { appSettings.AppendChild(groupNode); } } //if (node == null) XmlNode nodeProp = doc.CreateElement(setting.Name); nodeProp.AppendChild(this.SerializeToXmlElement(setting, value)); groupNode.AppendChild(nodeProp); }
public void SettingValuesCreatesAnAppAndUserId() { MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", false); ctx.Add("UserName", "user1"); SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); SettingsProperty property1 = new SettingsProperty("color"); property1.PropertyType = typeof(string); property1.Attributes["AllowAnonymous"] = true; SettingsPropertyValue value = new SettingsPropertyValue(property1); value.PropertyValue = "blue"; values.Add(value); provider.SetPropertyValues(ctx, values); DataTable dt = FillTable("SELECT * FROM my_aspnet_applications"); Assert.AreEqual(1, dt.Rows.Count); dt = FillTable("SELECT * FROM my_aspnet_users"); Assert.AreEqual(1, dt.Rows.Count); dt = FillTable("SELECT * FROM my_aspnet_profiles"); Assert.AreEqual(1, dt.Rows.Count); values["color"].PropertyValue = "green"; provider.SetPropertyValues(ctx, values); dt = FillTable("SELECT * FROM my_aspnet_applications"); Assert.AreEqual(1, dt.Rows.Count); dt = FillTable("SELECT * FROM my_aspnet_users"); Assert.AreEqual(1, dt.Rows.Count); dt = FillTable("SELECT * FROM my_aspnet_profiles"); Assert.AreEqual(1, dt.Rows.Count); }
/// <summary> /// Must override this, this is the bit that matches up the designer properties to the dictionary values /// </summary> /// <param name="context"></param> /// <param name="collection"></param> /// <returns></returns> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { //load the file if (!_loaded) { _loaded = true; LoadValuesFromFile(); } //collection that will be returned. SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); //itterate thought the properties we get from the designer, checking to see if the setting is in the dictionary foreach (SettingsProperty setting in collection) { SettingsPropertyValue value = new SettingsPropertyValue(setting); value.IsDirty = false; //need the type of the value for the strong typing var t = Type.GetType(setting.PropertyType.FullName); if (SettingsDictionary.ContainsKey(setting.Name)) { value.SerializedValue = SettingsDictionary[setting.Name].value; value.PropertyValue = Convert.ChangeType(SettingsDictionary[setting.Name].value, t); } else //use defaults in the case where there are no settings yet { value.SerializedValue = setting.DefaultValue; value.PropertyValue = Convert.ChangeType(setting.DefaultValue, t); } values.Add(value); } return values; }
public SalesforceProfilePropertyValue(SettingsPropertyValue propertyValue, SalesforceProfileProperty property) : base(property) { base.PropertyValue = propertyValue.PropertyValue; base.Deserialized = propertyValue.Deserialized; base.IsDirty = propertyValue.IsDirty; base.SerializedValue = propertyValue.SerializedValue; }
public void Add (SettingsPropertyValue property) { if (isReadOnly) throw new NotSupportedException (); /* actually do the add */ items.Add (property.Name, property); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { SettingsPropertyValueCollection v = new SettingsPropertyValueCollection(); value = new SettingsPropertyValue(new SettingsProperty("Style")); value.PropertyValue = "null"; v.Add(value); return v; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) { var values = new SettingsPropertyValueCollection(); foreach (SettingsProperty property in props) { var value2 = new SettingsPropertyValue(property) { IsDirty = false, SerializedValue = GetValue(property) }; values.Add(value2); } return values; }
private static void MigrateProperty(IMigrateSettings customMigrator, MigrationScope migrationScope, SettingsPropertyValue currentValue, object previousValue) { var migrationValues = new SettingsPropertyMigrationValues( currentValue.Property.Name, migrationScope, currentValue.PropertyValue, previousValue); customMigrator.MigrateSettingsProperty(migrationValues); if (!Equals(migrationValues.CurrentValue, currentValue.PropertyValue)) currentValue.PropertyValue = migrationValues.CurrentValue; }
/// <summary> /// Checks the specified settings collection to see if it has a serialized value that should /// be applied to the specified <see cref="SettingsPropertyValue"/>. /// </summary> /// <param name="value">An individual settings property value.</param> /// <param name="settings">A collection representing the settings.</param> private static void ApplySettingToValue(SettingsPropertyValue value, SettingElementCollection settings) { var setting = settings.Get(value.Name); if (setting != null) { value.SerializedValue = setting.Value.ValueXml.InnerText; // Mark the value as not deserialized, which will trigger a deserialization of the SerializedValue into the PropertyValue. value.Deserialized = false; } }
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) { foreach (SettingsPropertyValue value in collection) { SettingsPropertyValue existing = SimpleSettingsStore.Instance.CurrentUserValues[value.Name]; if (existing == null) SimpleSettingsStore.Instance.CurrentUserValues.Add(existing = new SettingsPropertyValue(value.Property)); existing.PropertyValue = value.PropertyValue; } }
public void Add () { SettingsPropertyValueCollection col = new SettingsPropertyValueCollection (); SettingsProperty test_prop = new SettingsProperty ("test_prop"); SettingsPropertyValue val = new SettingsPropertyValue (test_prop); Assert.AreEqual (0, col.Count, "A1"); col.Add (val); Assert.AreEqual (1, col.Count, "A2"); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { SettingsPropertyValueCollection spCollection = new SettingsPropertyValueCollection(); foreach (SettingsProperty settingsProperty in collection) { SettingsPropertyValue spVal = new SettingsPropertyValue(settingsProperty); spVal.PropertyValue = String.Empty; spCollection.Add(spVal); } return spCollection; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) { // Create new collection of values SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); // Iterate through the settings to be retrieved foreach (SettingsProperty setting in props) { SettingsPropertyValue value = new SettingsPropertyValue(setting); value.IsDirty = false; value.SerializedValue = (string)GetRegKey(setting).GetValue(setting.Name); values.Add(value); } return values; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { Configuration config = null; ClientSettingsSection clientSettings = null; // set all of the inherited default values first in case we have failure later SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection(); foreach (SettingsProperty prop in collection) { SettingsPropertyValue spv = new SettingsPropertyValue(prop); spv.SerializedValue = prop.DefaultValue; settings.Add(spv); } // now read in app-level settings config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSectionGroup configSectionGroup = config.GetSectionGroup(APP_SETTINGS_SECTION_GROUP_NAME); if (configSectionGroup != null) { ConfigurationSection configSection = configSectionGroup.Sections[APP_SETTINGS_SECTION_NAME]; if (configSection != null) { clientSettings = (ClientSettingsSection)configSection; foreach (SettingsPropertyValue spv in settings) { DeserializeFromXmlElement(spv.Property, spv, clientSettings); } } } // now read in overridden user settings try { config = null; clientSettings = GetUserSettings(out config, true); foreach (SettingsPropertyValue spv in settings) { DeserializeFromXmlElement(spv.Property, spv, clientSettings); } } catch { // suppress } return settings; }
//////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public void Add(SettingsPropertyValue property) { if (_ReadOnly) throw new NotSupportedException(); int pos = _Values.Add(property); try { _Indices.Add(property.Name, pos); } catch (Exception) { _Values.RemoveAt(pos); throw; } }
public void Add(SettingsPropertyValue property) { if (this._ReadOnly) { throw new NotSupportedException(); } int num = this._Values.Add(property); try { this._Indices.Add(property.Name, num); } catch (Exception) { this._Values.RemoveAt(num); throw; } }
//------------------------------------------------------ #endregion internal static void ParseProfileData(string PropertyNames, string PropertyValuesString, System.Configuration.SettingsPropertyValueCollection properties) { //------------------------------------------------------------- string[] names = null; string values = null; char[] chArr = new char[] { ':' }; names = PropertyNames.Split(chArr); values = PropertyValuesString; //------------------------------------------------------------- if ((names == null) || (values == null) || (properties == null)) { return; } try { for (int i1 = 0; i1 < (names.Length / 4); i1++) { string s = names[i1 * 4]; System.Configuration.SettingsPropertyValue settingsPropertyValue = properties[s]; if (settingsPropertyValue != null) { //int i2 = System.Int32.Parse(names[(i1 * 4) + 2], System.Globalization.CultureInfo.InvariantCulture); //int i3 = System.Int32.Parse(names[(i1 * 4) + 3], System.Globalization.CultureInfo.InvariantCulture); int i2 = System.Int32.Parse(names[(i1 * 4) + 2]); int i3 = System.Int32.Parse(names[(i1 * 4) + 3]); if ((i3 == -1) && !settingsPropertyValue.Property.PropertyType.IsValueType) { settingsPropertyValue.PropertyValue = null; settingsPropertyValue.IsDirty = false; //settingsPropertyValue.Deserialized = false; } //if (names[(i1 * 4) + 1] == "S\uFFFD" && (i2 >= 0) && (i3 > 0) && (values.Length >= (i2 + i3))) if (names[(i1 * 4) + 1] == "S" && (i2 >= 0) && (i3 > 0) && (values.Length >= (i2 + i3))) { settingsPropertyValue.PropertyValue = values.Substring(i2, i3); } //if (names[(i1 * 4) + 1] == "B\uFFFD" && (i2 >= 0) && (i3 > 0) && (buf.Length >= (i2 + i3))) } } } catch { } }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) { // Create new collection of values SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); string sectionName = this.GetSectionName(context); string settingKey = (string)context["SettingsKey"]; // Iterate through the settings to be retrieved foreach (SettingsProperty setting in props) { SettingsPropertyValue value = new SettingsPropertyValue(setting); value.IsDirty = false; value.SerializedValue = getValue(setting, context); values.Add(value); } return values; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { // коллекция, которая возвращает значения свойств профиля var result = new SettingsPropertyValueCollection(); if (collection == null || collection.Count < 1 || context == null) { return result; } // получаем из контекста имя пользователя - логин в системе var username = (string)context["UserName"]; if (String.IsNullOrEmpty(username)) return result; // получаем id пользователя из таблицы Users по логину var firstOrDefault = userService.GetUserEntityByEmail(username); if (firstOrDefault != null) { int userId = firstOrDefault.Id; // по этому id извлекаем профиль из таблицы профилей ProfileEntity profile = profileService.GetProfileByUserId(userId); if (profile != null) { foreach (SettingsProperty prop in collection) { var spv = new SettingsPropertyValue(prop) { PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null) }; result.Add(spv); } } else { foreach (SettingsProperty prop in collection) { var svp = new SettingsPropertyValue(prop) { PropertyValue = null }; result.Add(svp); } } } return result; }
private static SettingsPropertyValueCollection GetSettingsValues(SettingsPropertyCollection properties, IDictionary<string, string> storedValues) { // Create new collection of values SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); foreach (SettingsProperty setting in properties) { var value = new SettingsPropertyValue(setting) { SerializedValue = storedValues.ContainsKey(setting.Name) ? storedValues[setting.Name] : null, IsDirty = false }; // use the stored value, or set the SerializedValue to null, which tells .NET to use the default value values.Add(value); } return values; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) { lock (_locker) { // create new collection of values SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); // iterate through the settings to be retrieved foreach (SettingsProperty prop in props) { SettingsPropertyValue value = new SettingsPropertyValue(prop); value.SerializedValue = _GetValue(prop); value.IsDirty = false; values.Add(value); } return values; } }
private void SetValue(SettingsPropertyValue propVal) { XmlElement newChild = null; try { newChild = (XmlElement)SettingsXML.SelectSingleNode("Settings/" + propVal.Name); } catch (Exception) { newChild = null; } if (newChild != null) { newChild.InnerText = propVal.SerializedValue.ToString(); } else { newChild = SettingsXML.CreateElement(propVal.Name); newChild.InnerText = propVal.SerializedValue.ToString(); var selectSingleNode = SettingsXML.SelectSingleNode("Settings"); if (selectSingleNode != null) selectSingleNode.AppendChild(newChild); } }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { if (Settings.ClientSpecificMode) { var values = (Dictionary<SettingsProperty, object>) context[ValuesName]; var result = new SettingsPropertyValueCollection(); foreach (SettingsProperty setting in collection) { object propertyValue = values.ContainsKey(setting) ? values[setting] : base.GetPropertyValues(context, new SettingsPropertyCollection {setting})[ setting.Name].PropertyValue; var value = new SettingsPropertyValue(setting) { IsDirty = false, PropertyValue = propertyValue }; result.Add(value); } return result; } try { return base.GetPropertyValues(context, collection); } catch (ConfigurationErrorsException) { //A user-scoped setting was encountered but the current configuration only supports application-scoped settings. //example - Asp.Net web-site foreach (SettingsProperty setting in collection) { setting.Attributes.Remove(typeof (UserScopedSettingAttribute)); setting.Attributes.Add(typeof (ApplicationScopedSettingAttribute), new ApplicationScopedSettingAttribute()); } return base.GetPropertyValues(context, collection); } }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { if (this.Error != null) { throw this.Error; } SettingsPropertyValueCollection spvc = new SettingsPropertyValueCollection(); if (this.User == null) { return spvc; } foreach (SettingsProperty prop in collection) { SettingsPropertyValue propValue = new SettingsPropertyValue(prop); propValue.PropertyValue = typeof(MockUser).GetProperty(prop.Name).GetValue(this.User, null); spvc.Add(propValue); } return spvc; }
private void LoadSettings(string fileName) { IDictionary <string, string> dictionary = ReadDictionaryFile(fileName); var settings = Properties.Settings.Default; settings.LastSettingsFile = fileName; var values = settings.PropertyValues; foreach (SettingsPropertyValue value in values) { if (dictionary.ContainsKey(value.Name)) { // it seems to be impossible to write to values directly, so we use a newly created one SettingsPropertyValue newValue = new System.Configuration.SettingsPropertyValue(value.Property); newValue.SerializedValue = dictionary[value.Name]; settings[value.Name] = newValue.PropertyValue; } } DisplaySettings(settings); }
public override SettingsPropertyValueCollection GetPropertyValues( SettingsContext context, SettingsPropertyCollection collection) { var values = new SettingsPropertyValueCollection(); foreach (SettingsProperty property in collection) { var value = new SettingsPropertyValue(property) {IsDirty = false}; values.Add(value); } if (!File.Exists(SettingsPath)) return values; try { using (var xtr = new XmlTextReader(SettingsPath)) { var xDoc = new XmlDocument(); xDoc.Load(xtr); var settingsNode = xDoc["Settings"]; if (settingsNode == null) return values; foreach (XmlNode node in settingsNode.GetElementsByTagName("Setting")) { var name = node.Attributes?["Name"]?.Value; if (string.IsNullOrEmpty(name)) continue; var property = values[name]; if (property == null) continue; var value = node.InnerXml; var dataType = property.Property.PropertyType; property.PropertyValue = XmlDeserializeProperty(value, dataType); } } } catch (XmlException) { // Ignore } return values; }
private XmlNode SerializeToXmlElement(SettingsProperty setting, SettingsPropertyValue value) { XmlElement element = new XmlDocument().CreateElement("value"); string serializedValue = value.SerializedValue as string; if ((serializedValue == null) && (setting.SerializeAs == SettingsSerializeAs.Binary)) { byte[] inArray = value.SerializedValue as byte[]; if (inArray != null) { serializedValue = Convert.ToBase64String(inArray); } } if (serializedValue == null) { serializedValue = string.Empty; } if (setting.SerializeAs == SettingsSerializeAs.String) { serializedValue = this.Escaper.Escape(serializedValue); } element.InnerXml = serializedValue; XmlNode oldChild = null; foreach (XmlNode node2 in element.ChildNodes) { if (node2.NodeType == XmlNodeType.XmlDeclaration) { oldChild = node2; break; } } if (oldChild != null) { element.RemoveChild(oldChild); } return(element); }
private void SetPropertyValueByName(string propertyName, object propertyValue) { if (Properties == null || _PropertyValues == null || Properties.Count == 0) { throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); } SettingsProperty pp = Properties[propertyName]; if (pp == null) { throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); } if (pp.IsReadOnly) { throw new SettingsPropertyIsReadOnlyException(SR.GetString(SR.SettingsPropertyReadOnly, propertyName)); } if (propertyValue != null && !pp.PropertyType.IsInstanceOfType(propertyValue)) { throw new SettingsPropertyWrongTypeException(SR.GetString(SR.SettingsPropertyWrongType, propertyName)); } SettingsPropertyValue p = _PropertyValues[propertyName]; if (p == null) { GetPropertiesFromProvider(pp.Provider); p = _PropertyValues[propertyName]; if (p == null) { throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); } } p.PropertyValue = propertyValue; }
private SettingsPropertyValueCollection GetSettingValuesFromFile(string configFileName, string sectionName, bool userScoped, SettingsPropertyCollection properties) { SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); IDictionary dictionary = ClientSettingsStore.ReadSettingsFromFile(configFileName, sectionName, userScoped); foreach (SettingsProperty property in properties) { string name = property.Name; SettingsPropertyValue value2 = new SettingsPropertyValue(property); if (dictionary.Contains(name)) { StoredSetting setting = (StoredSetting)dictionary[name]; string innerXml = setting.Value.InnerXml; if (setting.SerializeAs == SettingsSerializeAs.String) { innerXml = this.Escaper.Unescape(innerXml); } value2.SerializedValue = innerXml; value2.IsDirty = true; values.Add(value2); } } return(values); }
/// <summary> /// Abstract SettingsProvider method /// </summary> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) { SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); string sectionName = GetSectionName(context); // Look for this section in both applicationSettingsGroup and userSettingsGroup IDictionary appSettings = Store.ReadSettings(sectionName, false); IDictionary userSettings = Store.ReadSettings(sectionName, true); ConnectionStringSettingsCollection connStrings = Store.ReadConnectionStrings(); // Now map each SettingProperty to the right StoredSetting and deserialize the value if found. foreach (SettingsProperty setting in properties) { string settingName = setting.Name; SettingsPropertyValue value = new SettingsPropertyValue(setting); // First look for and handle "special" settings SpecialSettingAttribute attr = setting.Attributes[typeof(SpecialSettingAttribute)] as SpecialSettingAttribute; bool isConnString = (attr != null) ? (attr.SpecialSetting == SpecialSetting.ConnectionString) : false; if (isConnString) { string connStringName = sectionName + "." + settingName; if (connStrings != null && connStrings[connStringName] != null) { value.PropertyValue = connStrings[connStringName].ConnectionString; } else if (setting.DefaultValue != null && setting.DefaultValue is string) { value.PropertyValue = setting.DefaultValue; } else { //No value found and no default specified value.PropertyValue = string.Empty; } value.IsDirty = false; //reset IsDirty so that it is correct when SetPropertyValues is called values.Add(value); continue; } // Not a "special" setting bool isUserSetting = IsUserSetting(setting); if (isUserSetting && !ConfigurationManagerInternalFactory.Instance.SupportsUserConfig) { // We encountered a user setting, but the current configuration system does not support // user settings. throw new ConfigurationErrorsException(SR.UserSettingsNotSupported); } IDictionary settings = isUserSetting ? userSettings : appSettings; if (settings.Contains(settingName)) { StoredSetting ss = (StoredSetting)settings[settingName]; string valueString = ss.Value.InnerXml; // We need to un-escape string serialized values if (ss.SerializeAs == SettingsSerializeAs.String) { valueString = Escaper.Unescape(valueString); } value.SerializedValue = valueString; } else if (setting.DefaultValue != null) { value.SerializedValue = setting.DefaultValue; } else { //No value found and no default specified value.PropertyValue = null; } value.IsDirty = false; //reset IsDirty so that it is correct when SetPropertyValues is called values.Add(value); } return(values); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) { SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); string sectionName = this.GetSectionName(context); IDictionary dictionary = this.Store.ReadSettings(sectionName, false); IDictionary dictionary2 = this.Store.ReadSettings(sectionName, true); ConnectionStringSettingsCollection settingss = this.Store.ReadConnectionStrings(); foreach (SettingsProperty property in properties) { string name = property.Name; SettingsPropertyValue value2 = new SettingsPropertyValue(property); SpecialSettingAttribute attribute = property.Attributes[typeof(SpecialSettingAttribute)] as SpecialSettingAttribute; if ((attribute != null) ? (attribute.SpecialSetting == SpecialSetting.ConnectionString) : false) { string str3 = sectionName + "." + name; if ((settingss != null) && (settingss[str3] != null)) { value2.PropertyValue = settingss[str3].ConnectionString; } else if ((property.DefaultValue != null) && (property.DefaultValue is string)) { value2.PropertyValue = property.DefaultValue; } else { value2.PropertyValue = string.Empty; } value2.IsDirty = false; values.Add(value2); } else { bool flag2 = this.IsUserSetting(property); if (flag2 && !ConfigurationManagerInternalFactory.Instance.SupportsUserConfig) { throw new ConfigurationErrorsException(System.SR.GetString("UserSettingsNotSupported")); } IDictionary dictionary3 = flag2 ? dictionary2 : dictionary; if (dictionary3.Contains(name)) { StoredSetting setting = (StoredSetting)dictionary3[name]; string innerXml = setting.Value.InnerXml; if (setting.SerializeAs == SettingsSerializeAs.String) { innerXml = this.Escaper.Unescape(innerXml); } value2.SerializedValue = innerXml; } else if (property.DefaultValue != null) { value2.SerializedValue = property.DefaultValue; } else { value2.PropertyValue = null; } value2.IsDirty = false; values.Add(value2); } } return(values); }
public void Add(SettingsPropertyValue property) { Contract.Requires(property != null); }
public void Add(SettingsPropertyValue property) { throw new NotImplementedException(); }
private void SetSetting(SettingsPropertyValue setProp) { // Search for the specific settings node we are looking for in the configuration file. XmlNode SettingNode = XMLConfig.SelectSingleNode("//setting[@name='" + setProp.Name + "']"); SettingNode = SettingNode == null ? null : SettingNode.FirstChild; // If we have a pointer to an actual XML node, update the value stored there if (SettingNode != null) { switch (setProp.Property.SerializeAs) { case SettingsSerializeAs.String: SettingNode.InnerText = setProp.SerializedValue.ToString(); break; case SettingsSerializeAs.Xml: // Write the object to the config serialized as Xml - we must remove the Xml declaration when writing // the value, otherwise .Net's configuration system complains about the additional declaration. SettingNode.InnerXml = setProp.SerializedValue.ToString().Replace(@"<?xml version=""1.0"" encoding=""utf-16""?>", ""); break; case SettingsSerializeAs.Binary: default: throw new NotSupportedException(); //break; } } else { // If the value did not already exist in this settings file, create a new entry for this setting // Search for the application settings node (<Appname.Properties.Settings>) and store it. XmlNode tmpNode = XMLConfig.SelectSingleNode("//" + APPNODE); // Create a new settings node and assign its name as well as how it will be serialized XmlElement newSetting = _XMLConfig.CreateElement("setting"); // Create an element under our named settings node, and assign it the value we are trying to save XmlElement valueElement = _XMLConfig.CreateElement("value"); newSetting.SetAttribute("name", setProp.Name); switch (setProp.Property.SerializeAs) { case SettingsSerializeAs.String: newSetting.SetAttribute("serializeAs", "String"); valueElement.InnerText = setProp.SerializedValue.ToString(); break; case SettingsSerializeAs.Xml: newSetting.SetAttribute("serializeAs", "Xml"); // Write the object to the config serialized as Xml - we must remove the Xml declaration when writing // the value, otherwise .Net's configuration system complains about the additional declaration valueElement.InnerXml = setProp.SerializedValue.ToString().Replace(@"<?xml version=""1.0"" encoding=""utf-16""?>", ""); break; case SettingsSerializeAs.Binary: default: throw new NotSupportedException(); //break; } // Append this node to the application settings node (<Appname.Properties.Settings>) tmpNode.AppendChild(newSetting); //Append this new element under the setting node we created above newSetting.AppendChild(valueElement); } }