상속: ConfigurationElement
예제 #1
0
		private static string GetElementValue(SettingElement element)
		{
			if (element.Value == null || element.Value.ValueXml == null)
				return null;

			return GetElementValue(element.Value.ValueXml, element.SerializeAs);
		}
예제 #2
0
		private static string GetElementValue(SettingElement element)
		{
			if (element.Value == null || element.Value.ValueXml == null)
				return String.Empty; //If the element even exists, we return "".

			return GetElementValue(element.Value.ValueXml, element.SerializeAs);
		}
예제 #3
0
		public void CollectionAddNameless ()
		{
			SettingElement el = new SettingElement ();
			Assert.AreEqual (String.Empty, el.Name, "premise #1");
			SettingElementCollection c = new SettingElementCollection ();
			Assert.AreEqual (ConfigurationElementCollectionType.BasicMap, c.CollectionType, "premise #2");
			c.Add (el);
			Assert.AreEqual (el, c.Get (""), "#1");
		}
예제 #4
0
		private static void SetElementValue(SettingElement element, string value)
		{
			var temp = new XmlDocument();
			XmlNode valueXml = temp.CreateElement("value");

			if (element.SerializeAs == SettingsSerializeAs.String)
			{
				XmlElement escaper = temp.CreateElement("temp");
				escaper.InnerText = value ?? "";
				valueXml.InnerXml = escaper.InnerXml;
			}
			else
			{
				if (!String.IsNullOrEmpty(value))
				{
					XmlElement tempElement = temp.CreateElement("temp");
					tempElement.InnerXml = value;
					RemoveXmlDeclaration(tempElement);
					valueXml.InnerXml = tempElement.InnerXml;
				}
			}

			element.Value.ValueXml = valueXml;
		}
		private void SaveProperties (ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
		{
			Configuration config = ConfigurationManager.OpenMappedExeConfiguration (exeMap, level);
			
			UserSettingsGroup userGroup = config.GetSectionGroup ("userSettings") as UserSettingsGroup;
			bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);

#if true // my reimplementation

			if (userGroup == null) {
				userGroup = new UserSettingsGroup ();
				config.SectionGroups.Add ("userSettings", userGroup);
				ApplicationSettingsBase asb = context.CurrentSettings;
				ClientSettingsSection cs = new ClientSettingsSection ();
				string class_name = NormalizeInvalidXmlChars ((asb != null ? asb.GetType () : typeof (ApplicationSettingsBase)).FullName);
				userGroup.Sections.Add (class_name, cs);
			}

			bool hasChanges = false;

			foreach (ConfigurationSection section in userGroup.Sections) {
				ClientSettingsSection userSection = section as ClientSettingsSection;
				if (userSection == null)
					continue;

				foreach (SettingsPropertyValue value in collection) {
					if (checkUserLevel && value.Property.Attributes.Contains (typeof (SettingsManageabilityAttribute)) != isRoaming)
						continue;
					// The default impl does not save the ApplicationScopedSetting properties
					if (value.Property.Attributes.Contains (typeof (ApplicationScopedSettingAttribute)))
						continue;

					hasChanges = true;
					SettingElement element = userSection.Settings.Get (value.Name);
					if (element == null) {
						element = new SettingElement (value.Name, value.Property.SerializeAs);
						userSection.Settings.Add (element);
					}
					if (element.Value.ValueXml == null)
						element.Value.ValueXml = new XmlDocument ().CreateElement ("value");
					switch (value.Property.SerializeAs) {
					case SettingsSerializeAs.Xml:
						element.Value.ValueXml.InnerXml = (value.SerializedValue as string) ?? string.Empty;
						break;
					case SettingsSerializeAs.String:
						element.Value.ValueXml.InnerText = value.SerializedValue as string;
						break;
					case SettingsSerializeAs.Binary:
						element.Value.ValueXml.InnerText = value.SerializedValue != null ? Convert.ToBase64String (value.SerializedValue as byte []) : string.Empty;
						break;
					default:
						throw new NotImplementedException ();
					}
				}
			}
			if (hasChanges)
				config.Save (ConfigurationSaveMode.Minimal, true);

#else // original impl. - likely buggy to miss some properties to save

			foreach (ConfigurationSection configSection in userGroup.Sections)
			{
				ClientSettingsSection userSection = configSection as ClientSettingsSection;
				if (userSection != null)
				{
/*
					userSection.Settings.Clear();

					foreach (SettingsPropertyValue propertyValue in collection)
					{
						if (propertyValue.IsDirty)
						{
							SettingElement element = new SettingElement(propertyValue.Name, SettingsSerializeAs.String);
							element.Value.ValueXml = new XmlDocument();
							element.Value.ValueXml.InnerXml = (string)propertyValue.SerializedValue;
							userSection.Settings.Add(element);
						}
					}
*/
					foreach (SettingElement element in userSection.Settings)
					{
						if (collection [element.Name] != null) {
							if (collection [element.Name].Property.Attributes.Contains (typeof (SettingsManageabilityAttribute)) != isRoaming)
								continue;

							element.SerializeAs = SettingsSerializeAs.String;
							element.Value.ValueXml.InnerXml = (string) collection [element.Name].SerializedValue;	///Value = XmlElement
						}
					}
 
				}
			}
			config.Save (ConfigurationSaveMode.Minimal, true);
#endif
		}
예제 #6
0
       /// <summary>
       /// 
       /// </summary>
       /// <param name="pConfiguration">Configuration del app.config</param>
       /// <param name="pSectionName">Seccion</param>
        /// <param name="pSectionGroupName">Grupo</param>
       internal static void AddSection(Configuration pConfiguration, String pSectionName,String pSectionGroupName,String pSettingTemplateName)
       {
           ConfigurationSectionGroup wConfigurationSectionGroup =null;
           SettingElement wSettingElement = null;
           XmlDocument doc = new XmlDocument();
           XmlNode xmlValue = doc.CreateNode(XmlNodeType.Element, "value", String.Empty);
           ConfigurationSectionCollection wSections = null;
           if (pSectionGroupName.Length == 0)
           {
               AddSectionFromAssembly(pConfiguration, pSectionName);
               return;
           }
           else
           {
               wConfigurationSectionGroup = pConfiguration.GetSectionGroup(pSectionGroupName);
               if (wConfigurationSectionGroup == null)
                   wConfigurationSectionGroup = AddSectionGroup(pConfiguration, pSectionGroupName);
               wSections = wConfigurationSectionGroup.Sections;
               
           }

           if (wSections.Get(pSectionName) != null) return;

           ClientSettingsSection wClientSettingsSection = new ClientSettingsSection();
           wClientSettingsSection.SectionInformation.RequirePermission = false;
           wClientSettingsSection.SectionInformation.ForceSave = true;
           
           #region Settings


           Dictionary<String, String> wSettings = TemplateProvider.GetSettingDic(pSettingTemplateName);

           if (wSettings != null)
           {
               foreach (KeyValuePair<string, string> seting in wSettings)
               {
                   wSettingElement = new SettingElement();
                   wSettingElement.Name = seting.Key;
                   xmlValue.InnerXml = seting.Value;
                   wSettingElement.Value.ValueXml = xmlValue.Clone();
                   wClientSettingsSection.Settings.Add(wSettingElement);
               }


           }
           #endregion
           wSections.Add(pSectionName, wClientSettingsSection);
           
       }
 private void WriteSettings(string sectionName, ConfigurationUserLevel userLevel, List<SettingsPropertyValue> newSettings)
 {
     System.Configuration.Configuration clientConfig = this.GetClientConfig(userLevel);
     ClientSettingsSection section = this.GetUserSection(clientConfig, sectionName, true);
     if (section == null)
     {
         throw new ConfigurationErrorsException("Failed to save settings. No settings section found");
     }
     foreach (SettingsPropertyValue value2 in newSettings)
     {
         SettingElement element = section.Settings.Get(value2.Name);
         if (element == null)
         {
             element = new SettingElement {
                 Name = value2.Name
             };
             section.Settings.Add(element);
         }
         element.SerializeAs = value2.Property.SerializeAs;
         element.Value.ValueXml = this.SerializeToXmlElement(value2.Property, value2);
     }
     try
     {
         clientConfig.Save();
     }
     catch (ConfigurationErrorsException exception)
     {
         throw new ConfigurationErrorsException(string.Format("Failed to save settings. {0}", exception.Message), exception);
     }
 }
 public void Add(SettingElement element)
 {
 }
예제 #9
0
       internal static void Add_SettingInSection(Configuration pConfiguration,
           String pSectionName,
           String pSectionGroupName,
           String pSettingName,String settingValue)
       {
           ConfigurationSectionGroup wConfigurationSectionGroup = null;
           //SettingElement wSettingElement = null;
           XmlDocument doc = new XmlDocument();
           XmlNode xmlValue = doc.CreateNode(XmlNodeType.Element, "value", String.Empty);
           ConfigurationSectionCollection wSections = null;
           if (pSectionGroupName.Length == 0)
           {
               AddSectionFromAssembly(pConfiguration, pSectionName);
               return;
           }
           else
           {
               wConfigurationSectionGroup = pConfiguration.GetSectionGroup(pSectionGroupName);
               if (wConfigurationSectionGroup == null)
                   wConfigurationSectionGroup = AddSectionGroup(pConfiguration, pSectionGroupName);
               wSections = wConfigurationSectionGroup.Sections;
           }

           ConfigurationSection wConfigurationSection = wSections.Get(pSectionName);
           ClientSettingsSection wClientSettingsSection = (ClientSettingsSection)wConfigurationSection;
           wClientSettingsSection.SectionInformation.RequirePermission = false;
           wClientSettingsSection.SectionInformation.ForceSave = true;

           #region Settings
           //wClientSettingsSection.Settings.Get(pSettingName);

           SettingElement wSettingElement = new SettingElement();
           wSettingElement.Name = pSettingName;
           xmlValue.InnerXml = settingValue;
           wSettingElement.Value.ValueXml = xmlValue.Clone();
           wClientSettingsSection.Settings.Add(wSettingElement);

           #endregion

       }
예제 #10
0
 public void Add(SettingElement element)
 {
 }
예제 #11
0
		//TODO (CR Sept 2010): instead of automatically storing all the defaults, should we 
		//just store what we're given and also delete stuff when we're given null?  Then
		//we could just return what's there in the "get" method rather than removing the defaults.
		private static ClientSettingsSection CreateDefaultSection(IEnumerable<PropertyInfo> properties)
		{
			var section = new ClientSettingsSection();
			section.SectionInformation.RequirePermission = false;

			foreach (PropertyInfo property in properties)
			{
				var element = new SettingElement(property.Name, SettingsClassMetaDataReader.GetSerializeAs(property));
				var valueElement = new SettingValueElement();
				element.Value = valueElement;
				
				string value = SettingsClassMetaDataReader.GetDefaultValue(property, false);
				SetElementValue(element, value);
				section.Settings.Add(element);
			}

			return section;
		}
예제 #12
0
		public void Initial ()
		{
			SettingElement el = new SettingElement ();
			Assert.IsNotNull (el.Value, "#1");
			Assert.IsNull (el.Value.ValueXml, "#2");
		}
예제 #13
0
        public bool SaveSetting(string name, string value)
        {
            try
            {
                SettingElement element = GetSettingInternal(name);
                XmlNode valueXml = SerializeToXmlElement(value);
                if (element == null)
                {
                    element = new SettingElement(name, SettingsSerializeAs.String);
                    _clientSettings.Settings.Add(element);
                }

                element.Value.ValueXml = SerializeToXmlElement(value);
                _configuration.Save();
                return true;
            }
            catch (Exception e)
            {
                // We don't have rights most likely, go ahead and fail gracefully
                Debug.WriteLine("Could not save setting for '{0}': {1}", SettingsLocation, e.Message);
                return false;
            }
        }
		public void Remove (SettingElement element)
		{
			if (element == null)
				throw new ArgumentNullException ("element");
			BaseRemove (element.Name);
		}
예제 #15
0
        } // SaveAs

        // ----------------------------------------------------------------------
        public void Import(UserConfig importUserConfig, bool overwriteSettings)
        {
            if (importUserConfig == null)
            {
                throw new ArgumentNullException("importUserConfig");
            }

            foreach (ConfigurationSectionGroup importSectionGroup in importUserConfig.configuration.SectionGroups)
            {
                UserSettingsGroup importUserSettingsGroup = importSectionGroup as UserSettingsGroup;
                if (importUserSettingsGroup == null)
                {
                    continue;
                }

                UserSettingsGroup userSettingsGroup = configuration.SectionGroups[importSectionGroup.Name] as UserSettingsGroup;
                if (userSettingsGroup == null)
                {
                    userSettingsGroup = new UserSettingsGroup();
                    configuration.SectionGroups.Add(importSectionGroup.Name, userSettingsGroup);
                }

                foreach (ConfigurationSection importSection in importSectionGroup.Sections)
                {
                    ClientSettingsSection importClientSettingsSection = importSection as ClientSettingsSection;
                    if (importClientSettingsSection == null)
                    {
                        continue;
                    }

                    ClientSettingsSection clientSettingsSection = userSettingsGroup.Sections[importSection.SectionInformation.Name] as ClientSettingsSection;
                    if (clientSettingsSection == null)
                    {
                        clientSettingsSection = new ClientSettingsSection();
                        userSettingsGroup.Sections.Add(importSection.SectionInformation.Name, clientSettingsSection);
                    }

                    foreach (SettingElement importSettingElement in importClientSettingsSection.Settings)
                    {
                        bool newSetting = false;

                        SettingElement settingElement = clientSettingsSection.Settings.Get(importSettingElement.Name);
                        if (settingElement == null)
                        {
                            newSetting = true;
                            settingElement = new SettingElement();
                            settingElement.Name = importSettingElement.Name;
                            settingElement.SerializeAs = importSettingElement.SerializeAs;
                            clientSettingsSection.Settings.Add(settingElement);
                        }

                        if (!newSetting && !overwriteSettings)
                        {
                            continue;
                        }

                        SettingValueElement settingValueElement = new SettingValueElement();
                        settingValueElement.ValueXml = importSettingElement.Value.ValueXml;
                        settingElement.SerializeAs = importSettingElement.SerializeAs;
                        settingElement.Value = settingValueElement;
                        clientSettingsSection.Settings.Add(settingElement);
                    }
                }
            }
        } // Import
예제 #16
0
        private void SaveProperties(ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
        {
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exeMap, level);

            UserSettingsGroup userGroup = config.GetSectionGroup("userSettings") as UserSettingsGroup;
            bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);

#if true // my reimplementation
            if (userGroup == null)
            {
                userGroup = new UserSettingsGroup();
                config.SectionGroups.Add("userSettings", userGroup);
                ApplicationSettingsBase asb = context.CurrentSettings;
                ClientSettingsSection   cs  = new ClientSettingsSection();
                string class_name           = NormalizeInvalidXmlChars((asb != null ? asb.GetType() : typeof(ApplicationSettingsBase)).FullName);
                userGroup.Sections.Add(class_name, cs);
            }

            bool hasChanges = false;

            foreach (ConfigurationSection section in userGroup.Sections)
            {
                ClientSettingsSection userSection = section as ClientSettingsSection;
                if (userSection == null)
                {
                    continue;
                }

                foreach (SettingsPropertyValue value in collection)
                {
                    if (checkUserLevel && value.Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                    {
                        continue;
                    }
                    // The default impl does not save the ApplicationScopedSetting properties
                    if (value.Property.Attributes.Contains(typeof(ApplicationScopedSettingAttribute)))
                    {
                        continue;
                    }

                    hasChanges = true;
                    SettingElement element = userSection.Settings.Get(value.Name);
                    if (element == null)
                    {
                        element = new SettingElement(value.Name, value.Property.SerializeAs);
                        userSection.Settings.Add(element);
                    }
                    if (element.Value.ValueXml == null)
                    {
                        element.Value.ValueXml = new XmlDocument().CreateElement("value");
                    }
                    switch (value.Property.SerializeAs)
                    {
                    case SettingsSerializeAs.Xml:
                        element.Value.ValueXml.InnerXml = (value.SerializedValue as string) ?? string.Empty;
                        break;

                    case SettingsSerializeAs.String:
                        element.Value.ValueXml.InnerText = value.SerializedValue as string;
                        break;

                    case SettingsSerializeAs.Binary:
                        element.Value.ValueXml.InnerText = value.SerializedValue != null?Convert.ToBase64String(value.SerializedValue as byte []) : string.Empty;

                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            if (hasChanges)
            {
                config.Save(ConfigurationSaveMode.Minimal, true);
            }
#else // original impl. - likely buggy to miss some properties to save
            foreach (ConfigurationSection configSection in userGroup.Sections)
            {
                ClientSettingsSection userSection = configSection as ClientSettingsSection;
                if (userSection != null)
                {
/*
 *                                      userSection.Settings.Clear();
 *
 *                                      foreach (SettingsPropertyValue propertyValue in collection)
 *                                      {
 *                                              if (propertyValue.IsDirty)
 *                                              {
 *                                                      SettingElement element = new SettingElement(propertyValue.Name, SettingsSerializeAs.String);
 *                                                      element.Value.ValueXml = new XmlDocument();
 *                                                      element.Value.ValueXml.InnerXml = (string)propertyValue.SerializedValue;
 *                                                      userSection.Settings.Add(element);
 *                                              }
 *                                      }
 */
                    foreach (SettingElement element in userSection.Settings)
                    {
                        if (collection [element.Name] != null)
                        {
                            if (collection [element.Name].Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                            {
                                continue;
                            }

                            element.SerializeAs             = SettingsSerializeAs.String;
                            element.Value.ValueXml.InnerXml = (string)collection [element.Name].SerializedValue;                                ///Value = XmlElement
                        }
                    }
                }
            }
            config.Save(ConfigurationSaveMode.Minimal, true);
#endif
        }
 public void Remove(SettingElement element)
 {
     base.BaseRemove(this.GetElementKey(element));
 }
예제 #18
0
 public void Remove(SettingElement element)
 {
 }
 public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
 {
     try
     {
         Configuration config = null;
         ClientSettingsSection clientSettings = GetUserSettings(out config, false);
         clientSettings.Settings.Clear();
         foreach (SettingsPropertyValue spv in collection)
         {
             SettingValueElement sve = new SettingValueElement();
             sve.ValueXml = SerializeToXmlElement(spv.Property, spv);
             SettingElement se = new SettingElement(spv.Name, spv.Property.SerializeAs);
             se.Value = sve;
             clientSettings.Settings.Add(se);
         }
         config.Save();
         config = null;
     }
     catch
     {
         // suppress
     }
 }
예제 #20
0
        private ClientSetting SettingToClientSetting(SettingElement setting)
        {
            IStringProperty property = SettingToProperty(setting);

            if (property == null)
            {
                Debug.Fail("Shouldn't be converting a null element to a ClientSetting.");
                return null;
            }
            else
            {
                return new ClientSetting(property.Name, property.Value, SettingsLocation);
            }
        }
        internal void WriteSettings(string sectionName, bool isRoaming, IDictionary newSettings) {
            if (!ConfigurationManagerInternalFactory.Instance.SupportsUserConfig) {
                throw new ConfigurationErrorsException(SR.GetString(SR.UserSettingsNotSupported));
            }

            Configuration config = GetUserConfig(isRoaming);
            ClientSettingsSection section = GetConfigSection(config, sectionName, true);

            if (section != null) {
                SettingElementCollection sec = section.Settings;
                foreach (DictionaryEntry entry in newSettings) {
                    SettingElement se = sec.Get((string) entry.Key);

                    if (se == null) {
                        se = new SettingElement();
                        se.Name = (string) entry.Key;
                        sec.Add(se);
                    }

                    StoredSetting ss = (StoredSetting) entry.Value;
                    se.SerializeAs = ss.SerializeAs;
                    se.Value.ValueXml = ss.Value;
                }

                try {
                    config.Save();
                }
                catch (ConfigurationErrorsException ex) {
                    // We wrap this in an exception with our error message and throw again.
                    throw new ConfigurationErrorsException(SR.GetString(SR.SettingsSaveFailed, ex.Message), ex);
                }
            }
            else {
                throw new ConfigurationErrorsException(SR.GetString(SR.SettingsSaveFailedNoSection));
            }
        }
 public void Remove(SettingElement element)
 {
 }
예제 #23
0
 private static IStringProperty SettingToProperty(SettingElement setting)
 {
     if (setting == null) { return null; }
     return new StringProperty(setting.Name, XmlEscaper.Unescape(setting.Value.ValueXml.InnerXml));
 }
예제 #24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Writes <paramref name="values"/> properties to config files.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override void SetPropertyValues(SettingsContext context,
			SettingsPropertyValueCollection values)
        {
            var configMap = SetConfigFiles();
            var localConfig = ConfigurationManager.OpenMappedExeConfiguration(configMap,
                ConfigurationUserLevel.PerUserRoamingAndLocal);
            var roamingConfig = ConfigurationManager.OpenMappedExeConfiguration(configMap,
                ConfigurationUserLevel.PerUserRoaming);
            var groupName = (string)context["GroupName"];

            var localCollection = GetSection(localConfig, groupName).Settings;
            var roamingCollection = GetSection(roamingConfig, groupName).Settings;

            // Create new collection of values
            foreach (SettingsPropertyValue value in values)
            {
                if (!value.IsDirty || value.SerializedValue == null)
                    continue;

                if (IsApplicationScoped(value.Property))
                    continue;

                if (value.PropertyValue.Equals(value.Property.DefaultValue))
                    continue;

                SettingElement elem;
                if (value.Property.Attributes[typeof(SettingsManageabilityAttribute)] == null)
                {
                    // this is a property for a local user
                    elem = localCollection.Get(value.Name);
                    if (elem == null)
                    {
                        elem = new SettingElement { Name = value.Name };
                        localCollection.Add(elem);
                    }
                }
                else
                {
                    // this is a property for a roaming user
                    elem = roamingCollection.Get(value.Name);
                    if (elem == null)
                    {
                        elem = new SettingElement { Name = value.Name };
                        roamingCollection.Add(elem);
                    }
                }
                elem.SerializeAs = value.Property.SerializeAs;
                elem.Value.ValueXml = SerializeToXmlElement(value);
            }

            if (localCollection.Count > 0)
                localConfig.Save();
            if (roamingCollection.Count > 0)
                roamingConfig.Save();
        }
예제 #25
0
        public override bool Equals(object settings)
        {
            SettingElement element = settings as SettingElement;

            return(((element != null) && base.Equals(settings)) && object.Equals(element.Value, this.Value));
        }
예제 #26
0
        /// <summary>
        /// Updates the <see cref="SettingElementCollection"/> from the <see cref="SettingsPropertyValueCollection"/>.
        /// </summary>
        /// <param name="settings">A collection representing the settings.</param>
        /// <param name="values">
        /// A <see cref="T:System.Configuration.SettingsPropertyValueCollection"/> representing the
        /// group of property settings to set.
        /// </param>
        private static void UpdateSettingsFromPropertyValues(SettingElementCollection settings, SettingsPropertyValueCollection values)
        {
            foreach (SettingsPropertyValue value in values)
            {
                if (value.IsDirty)
                {
                    var element = settings.Get(value.Name);
                    if (element == null)
                    {
                        // Note: We only support string serialization for brevity of implementation.
                        element = new SettingElement(value.Name, SettingsSerializeAs.String);
                        settings.Add(element);
                    }

                    element.SerializeAs = SettingsSerializeAs.String;
                    element.Value.ValueXml = CreateXmlValue(value.SerializedValue);
                }
            }
        }
예제 #27
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Extracts a property from the XML element.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private static void SetProperty(SettingsPropertyValue property, SettingElement elem)
 {
     property.SerializedValue = elem.Value.ValueXml.InnerText;
     property.IsDirty = true;
 }
예제 #28
0
        public override bool Equals(object settings)
        {
            SettingElement element = settings as SettingElement;

            return(element != null && base.Equals(settings) && Equals(element.Value, Value));
        }
예제 #29
0
        public override bool Equals(object settings)
        {
            SettingElement u = settings as SettingElement;

            return(u != null && base.Equals(settings) && Object.Equals(u.Value, Value));
        }
예제 #30
0
 public void Add(SettingElement element)
 {
     BaseAdd(element);
 }
예제 #31
0
		private static SettingElement GetSettingElement(ClientSettingsSection clientSection, PropertyInfo property, bool create)
		{
			SettingElement element = clientSection.Settings.Get(property.Name);
			if (element == null && create)
			{
				element = new SettingElement(property.Name, SettingsClassMetaDataReader.GetSerializeAs(property));
				clientSection.Settings.Add(element);
			}

			return element;
		}
예제 #32
0
 public void Remove(SettingElement element)
 {
     BaseRemove(GetElementKey(element));
 }
예제 #33
0
       internal static bool CheIsValidSettings(SettingElement wSetting)
       {
           //if (wSetting.Attributes == null) return false;
           //if(wSettings.Attributes["name"] == null)return false;


           return true;
       }
예제 #34
0
 public void Add(SettingElement element) {
     BaseAdd(element);
 }
        private void SaveProperties(ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
        {
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exeMap, level);

            UserSettingsGroup userGroup = config.GetSectionGroup("userSettings") as UserSettingsGroup;
            bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);

            if (userGroup == null)
            {
                userGroup = new UserSettingsGroup();
                config.SectionGroups.Add("userSettings", userGroup);
            }
            ApplicationSettingsBase asb       = context.CurrentSettings;
            string class_name                 = NormalizeInvalidXmlChars((asb != null ? asb.GetType() : typeof(ApplicationSettingsBase)).FullName);
            ClientSettingsSection userSection = null;
            ConfigurationSection  cnf         = userGroup.Sections.Get(class_name);

            userSection = cnf as ClientSettingsSection;
            if (userSection == null)
            {
                userSection = new ClientSettingsSection();
                userGroup.Sections.Add(class_name, userSection);
            }

            bool hasChanges = false;

            if (userSection == null)
            {
                return;
            }

            foreach (SettingsPropertyValue value in collection)
            {
                if (checkUserLevel && value.Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                {
                    continue;
                }
                // The default impl does not save the ApplicationScopedSetting properties
                if (value.Property.Attributes.Contains(typeof(ApplicationScopedSettingAttribute)))
                {
                    continue;
                }

                hasChanges = true;
                SettingElement element = userSection.Settings.Get(value.Name);
                if (element == null)
                {
                    element = new SettingElement(value.Name, value.Property.SerializeAs);
                    userSection.Settings.Add(element);
                }
                if (element.Value.ValueXml == null)
                {
                    element.Value.ValueXml = new XmlDocument().CreateElement("value");
                }
                switch (value.Property.SerializeAs)
                {
                case SettingsSerializeAs.Xml:
                    element.Value.ValueXml.InnerXml = StripXmlHeader(value.SerializedValue as string);
                    break;

                case SettingsSerializeAs.String:
                    element.Value.ValueXml.InnerText = value.SerializedValue as string;
                    break;

                case SettingsSerializeAs.Binary:
                    element.Value.ValueXml.InnerText = value.SerializedValue != null?Convert.ToBase64String(value.SerializedValue as byte []) : string.Empty;

                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            if (hasChanges)
            {
                config.Save(ConfigurationSaveMode.Minimal, true);
            }
        }
예제 #36
0
 public void Remove(SettingElement element) {
     BaseRemove(GetElementKey(element));
 }
예제 #37
0
        public static bool AddProperty(string propertyName, object defaultValue, Type propertyType)
        {
            bool added = false;

            if (!ContainsProperty(propertyName))
            {
                Property p = new Property(propertyName, propertyType, defaultValue);
                _propertyList.Add(propertyName, p);
                added = true;
            }

            if (!ContainsKey(propertyName))
            {
                if (IsStringCollection(propertyType))
                {
                    SettingElement se = new SettingElement(propertyName, SettingsSerializeAs.Xml);
                    SettingValueElement sve = new SettingValueElement();
                    XmlDocument doc = new XmlDocument();
                    XmlNode n = doc.CreateNode(XmlNodeType.Element, "value", String.Empty);
                    sve.ValueXml = n;
                    se.Value = sve;
                    _css.Settings.Add(se);
                    SetPropertyValue(propertyName, null);
                }
                else
                {
                    SettingElement se = new SettingElement(propertyName,SettingsSerializeAs.String);
                    SettingValueElement sve = new SettingValueElement();
                    XmlDocument doc = new XmlDocument();
                    XmlNode n = doc.CreateNode(XmlNodeType.Element, "value", String.Empty);
                    n.InnerText = (defaultValue == null ? String.Empty : defaultValue.ToString());
                    sve.ValueXml = n;
                    se.Value = sve;
                    _css.Settings.Add(se);
                }
                added = true;
            }
            
            return added;
        }
		private void SaveProperties (ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
		{
			Configuration config = ConfigurationManager.OpenMappedExeConfiguration (exeMap, level);
			
			UserSettingsGroup userGroup = config.GetSectionGroup ("userSettings") as UserSettingsGroup;
			bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);

			if (userGroup == null) {
				userGroup = new UserSettingsGroup ();
				config.SectionGroups.Add ("userSettings", userGroup);
			}
			ApplicationSettingsBase asb = context.CurrentSettings;
			string class_name = NormalizeInvalidXmlChars ((asb != null ? asb.GetType () : typeof (ApplicationSettingsBase)).FullName);
			ClientSettingsSection userSection = null;
			ConfigurationSection cnf = userGroup.Sections.Get (class_name);
			userSection = cnf as ClientSettingsSection;
			if (userSection == null) {
				userSection = new ClientSettingsSection ();
				userGroup.Sections.Add (class_name, userSection);
			}

			bool hasChanges = false;

			if (userSection == null)
				return;

			foreach (SettingsPropertyValue value in collection) {
				if (checkUserLevel && value.Property.Attributes.Contains (typeof (SettingsManageabilityAttribute)) != isRoaming)
					continue;
				// The default impl does not save the ApplicationScopedSetting properties
				if (value.Property.Attributes.Contains (typeof (ApplicationScopedSettingAttribute)))
					continue;

				hasChanges = true;
				SettingElement element = userSection.Settings.Get (value.Name);
				if (element == null) {
					element = new SettingElement (value.Name, value.Property.SerializeAs);
					userSection.Settings.Add (element);
				}
				if (element.Value.ValueXml == null)
					element.Value.ValueXml = new XmlDocument ().CreateElement ("value");
				switch (value.Property.SerializeAs) {
				case SettingsSerializeAs.Xml:
					element.Value.ValueXml.InnerXml = StripXmlHeader (value.SerializedValue as string);
					break;
				case SettingsSerializeAs.String:
					element.Value.ValueXml.InnerText = value.SerializedValue as string;
					break;
				case SettingsSerializeAs.Binary:
					element.Value.ValueXml.InnerText = value.SerializedValue != null ? Convert.ToBase64String (value.SerializedValue as byte []) : string.Empty;
					break;
				default:
					throw new NotImplementedException ();
				}
			}
			if (hasChanges)
				config.Save (ConfigurationSaveMode.Minimal, true);
		}
		private void LoadPropertyValue (SettingsPropertyCollection collection, SettingElement element, bool allowOverwrite)
		{
			SettingsProperty prop = collection [element.Name];
			if (prop == null) { // see bug #343459
				prop = new SettingsProperty (element.Name);
				collection.Add (prop);
			}

			SettingsPropertyValue value = new SettingsPropertyValue (prop);
			value.IsDirty = false;
			if (element.Value.ValueXml != null) {
				switch (value.Property.SerializeAs) {
				case SettingsSerializeAs.Xml:
					value.SerializedValue = element.Value.ValueXml.InnerXml;
					break;
				case SettingsSerializeAs.String:
					value.SerializedValue = element.Value.ValueXml.InnerText;
					break;
				case SettingsSerializeAs.Binary:
					value.SerializedValue = Convert.FromBase64String (element.Value.ValueXml.InnerText);
					break;
				}
			}
			else
				value.SerializedValue = prop.DefaultValue;
			try
			{
				if (allowOverwrite)
					values.Remove (element.Name);
				values.Add (value);
			} catch (ArgumentException ex) {
				throw new ConfigurationErrorsException (string.Format (
					CultureInfo.InvariantCulture,
					"Failed to load value for '{0}'.",
					element.Name), ex);
			}
		}
 public void Remove(SettingElement element)
 {
     base.BaseRemove(this.GetElementKey(element));
 }