public void TestReadStringSettings(Type localSettingsClass)
        {
            var settings = ApplicationSettingsHelper.GetSettingsClassInstance(localSettingsClass);

            settings.SetSharedPropertyValue(MixedScopeSettingsBase.PropertyApp1, "TestApp1");
            settings.SetSharedPropertyValue(MixedScopeSettingsBase.PropertyApp2, "TestApp2");
            settings.SetSharedPropertyValue(MixedScopeSettingsBase.PropertyUser1, "TestUser1");
            settings.SetSharedPropertyValue(MixedScopeSettingsBase.PropertyUser2, "TestUser2");

            var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
            var path   = new ConfigurationSectionPath(localSettingsClass, SettingScope.Application);
            var values = reader.GetSettingsValues(path);

            Assert.AreEqual(2, values.Count);
            Assert.AreEqual("TestApp1", values[MixedScopeSettingsBase.PropertyApp1]);
            Assert.AreEqual("TestApp2", values[MixedScopeSettingsBase.PropertyApp2]);

            path   = new ConfigurationSectionPath(localSettingsClass, SettingScope.User);
            values = reader.GetSettingsValues(path);
            Assert.AreEqual(2, values.Count);
            Assert.AreEqual("TestUser1", values[MixedScopeSettingsBase.PropertyUser1]);
            Assert.AreEqual("TestUser2", values[MixedScopeSettingsBase.PropertyUser2]);

            SystemConfigurationHelper.GetExeConfiguration().RemoveSettingsValues(localSettingsClass);
        }
Ejemplo n.º 2
0
        public void TestReadStringSettings()
        {
            Type settingsClass = typeof(LocalMixedScopeSettings);
            var  settings      = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass);

            ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalMixedScopeSettings.PropertyApp1, "TestApp1");
            ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalMixedScopeSettings.PropertyApp2, "TestApp2");
            ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalMixedScopeSettings.PropertyUser1, "TestUser1");
            ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalMixedScopeSettings.PropertyUser2, "TestUser2");

            var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
            var path   = new ConfigurationSectionPath(typeof(LocalMixedScopeSettings), SettingScope.Application);
            var values = reader.GetSettingsValues(path);

            Assert.AreEqual(2, values.Count);
            Assert.AreEqual("TestApp1", values[LocalMixedScopeSettings.PropertyApp1]);
            Assert.AreEqual("TestApp2", values[LocalMixedScopeSettings.PropertyApp2]);

            path   = new ConfigurationSectionPath(typeof(LocalMixedScopeSettings), SettingScope.User);
            values = reader.GetSettingsValues(path);
            Assert.AreEqual(2, values.Count);
            Assert.AreEqual("TestUser1", values[LocalMixedScopeSettings.PropertyUser1]);
            Assert.AreEqual("TestUser2", values[LocalMixedScopeSettings.PropertyUser2]);

            SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass);
        }
		public void TestReadStringSettings()
		{
			Type settingsClass = typeof (LocalMixedScopeSettings);
			var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass);

			ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalMixedScopeSettings.PropertyApp1, "TestApp1");
			ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalMixedScopeSettings.PropertyApp2, "TestApp2");
			ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalMixedScopeSettings.PropertyUser1, "TestUser1");
			ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalMixedScopeSettings.PropertyUser2, "TestUser2");

			var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
			var path = new ConfigurationSectionPath(typeof(LocalMixedScopeSettings), SettingScope.Application);
			var values = reader.GetSettingsValues(path);
			Assert.AreEqual(2, values.Count);
			Assert.AreEqual("TestApp1", values[LocalMixedScopeSettings.PropertyApp1]);
			Assert.AreEqual("TestApp2", values[LocalMixedScopeSettings.PropertyApp2]);

			path = new ConfigurationSectionPath(typeof(LocalMixedScopeSettings), SettingScope.User);
			values = reader.GetSettingsValues(path);
			Assert.AreEqual(2, values.Count);
			Assert.AreEqual("TestUser1", values[LocalMixedScopeSettings.PropertyUser1]);
			Assert.AreEqual("TestUser2", values[LocalMixedScopeSettings.PropertyUser2]);
			
			SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass);
		}
Ejemplo n.º 4
0
		public IDictionary<string, string> GetSettingsValues(ConfigurationSectionPath path)
		{
			var values = new Dictionary<string, string>();

			if (_document.DocumentElement != null)
			{
				var element = _document.DocumentElement.SelectSingleNode(path) as XmlElement;
				if (element != null)
				{
					foreach (XmlElement setting in element.ChildNodes)
					{
						var nameAttribute = setting.Attributes["name"];
						if (nameAttribute == null)
							continue;

						var name = nameAttribute.Value;
						if (String.IsNullOrEmpty(name))
							continue;

						var valueNode = setting.SelectSingleNode("value");
						if (valueNode == null)
							continue;

						var serializeAsAttribute = setting.Attributes["serializeAs"];
						var serializeAsValue = serializeAsAttribute != null ? serializeAsAttribute.Value : String.Empty;
						var serializeAs = SystemConfigurationHelper.GetSerializeAs(serializeAsValue);
						values.Add(name, SystemConfigurationHelper.GetElementValue(valueNode, serializeAs));
					}
				}
			}

			return values;
		}
		public void TestReadXmlSettings()
		{
			Type settingsClass = typeof(LocalXmlSettings);
			var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass);

			var appValue = @"<test><app/></test>";
			XmlDocument appDocument = new XmlDocument();
			appDocument.LoadXml(appValue);
			ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalXmlSettings.PropertyApp, appDocument);

			var userValue = @"<test><user/></test>";
			XmlDocument userDocument= new XmlDocument();
			userDocument.LoadXml(userValue);
			ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalXmlSettings.PropertyUser, userDocument);

			var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
			var path = new ConfigurationSectionPath(typeof(LocalXmlSettings), SettingScope.Application);
			var values = reader.GetSettingsValues(path);
			Assert.AreEqual(1, values.Count);

			XmlDocument testDocument = new XmlDocument();
			testDocument.LoadXml(values[LocalXmlSettings.PropertyApp]);
			Assert.AreEqual(appDocument.InnerXml, testDocument.InnerXml);

			path = new ConfigurationSectionPath(typeof(LocalXmlSettings), SettingScope.User);
			values = reader.GetSettingsValues(path);
			Assert.AreEqual(1, values.Count);

			testDocument = new XmlDocument();
			testDocument.LoadXml(values[LocalXmlSettings.PropertyUser]);
			Assert.AreEqual(userDocument.InnerXml, testDocument.InnerXml);

			SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass);
		}
        private static void TestReadNoSettings(Type localSettingsClass)
        {
			SystemConfigurationHelper.GetExeConfiguration().RemoveSettingsValues(localSettingsClass);

			var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
			var path = new ConfigurationSectionPath(localSettingsClass, SettingScope.Application);
			var values = reader.GetSettingsValues(path);
			Assert.AreEqual(0, values.Count);

            path = new ConfigurationSectionPath(localSettingsClass, SettingScope.User);
			values = reader.GetSettingsValues(path);
			Assert.AreEqual(0, values.Count);
		}
        private static void TestReadNoSettings(Type localSettingsClass)
        {
            SystemConfigurationHelper.GetExeConfiguration().RemoveSettingsValues(localSettingsClass);

            var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
            var path   = new ConfigurationSectionPath(localSettingsClass, SettingScope.Application);
            var values = reader.GetSettingsValues(path);

            Assert.AreEqual(0, values.Count);

            path   = new ConfigurationSectionPath(localSettingsClass, SettingScope.User);
            values = reader.GetSettingsValues(path);
            Assert.AreEqual(0, values.Count);
        }
		public void TestReadNoSettings()
		{
			Type settingsClass = typeof(LocalMixedScopeSettings);
			SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass);

			var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
			var path = new ConfigurationSectionPath(typeof(LocalMixedScopeSettings), SettingScope.Application);
			var values = reader.GetSettingsValues(path);
			Assert.AreEqual(0, values.Count);

			path = new ConfigurationSectionPath(typeof(LocalMixedScopeSettings), SettingScope.User);
			values = reader.GetSettingsValues(path);
			Assert.AreEqual(0, values.Count);
		}
Ejemplo n.º 9
0
        public void TestReadNoSettings()
        {
            Type settingsClass = typeof(LocalMixedScopeSettings);

            SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass);

            var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
            var path   = new ConfigurationSectionPath(typeof(LocalMixedScopeSettings), SettingScope.Application);
            var values = reader.GetSettingsValues(path);

            Assert.AreEqual(0, values.Count);

            path   = new ConfigurationSectionPath(typeof(LocalMixedScopeSettings), SettingScope.User);
            values = reader.GetSettingsValues(path);
            Assert.AreEqual(0, values.Count);
        }
Ejemplo n.º 10
0
        public void TestReadXmlSettings()
        {
            Type settingsClass = typeof(LocalXmlSettings);
            var  settings      = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass);

            var         appValue    = @"<test><app/></test>";
            XmlDocument appDocument = new XmlDocument();

            appDocument.LoadXml(appValue);
            ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalXmlSettings.PropertyApp, appDocument);

            var         userValue    = @"<test><user/></test>";
            XmlDocument userDocument = new XmlDocument();

            userDocument.LoadXml(userValue);
            ApplicationSettingsExtensions.SetSharedPropertyValue(settings, LocalXmlSettings.PropertyUser, userDocument);

            var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
            var path   = new ConfigurationSectionPath(typeof(LocalXmlSettings), SettingScope.Application);
            var values = reader.GetSettingsValues(path);

            Assert.AreEqual(1, values.Count);

            XmlDocument testDocument = new XmlDocument();

            testDocument.LoadXml(values[LocalXmlSettings.PropertyApp]);
            Assert.AreEqual(appDocument.InnerXml, testDocument.InnerXml);

            path   = new ConfigurationSectionPath(typeof(LocalXmlSettings), SettingScope.User);
            values = reader.GetSettingsValues(path);
            Assert.AreEqual(1, values.Count);

            testDocument = new XmlDocument();
            testDocument.LoadXml(values[LocalXmlSettings.PropertyUser]);
            Assert.AreEqual(userDocument.InnerXml, testDocument.InnerXml);

            SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass);
        }
		public void TestReadStringSettings(Type localSettingsClass)
        {
			var settings = ApplicationSettingsHelper.GetSettingsClassInstance(localSettingsClass);

			settings.SetSharedPropertyValue(MixedScopeSettingsBase.PropertyApp1, "TestApp1");
            settings.SetSharedPropertyValue(MixedScopeSettingsBase.PropertyApp2, "TestApp2");
            settings.SetSharedPropertyValue(MixedScopeSettingsBase.PropertyUser1, "TestUser1");
            settings.SetSharedPropertyValue(MixedScopeSettingsBase.PropertyUser2, "TestUser2");

			var reader = new ConfigurationFileReader(SystemConfigurationHelper.GetExeConfiguration().FilePath);
			var path = new ConfigurationSectionPath(localSettingsClass, SettingScope.Application);
			var values = reader.GetSettingsValues(path);
			Assert.AreEqual(2, values.Count);
            Assert.AreEqual("TestApp1", values[MixedScopeSettingsBase.PropertyApp1]);
            Assert.AreEqual("TestApp2", values[MixedScopeSettingsBase.PropertyApp2]);

			path = new ConfigurationSectionPath(localSettingsClass, SettingScope.User);
			values = reader.GetSettingsValues(path);
			Assert.AreEqual(2, values.Count);
            Assert.AreEqual("TestUser1", values[MixedScopeSettingsBase.PropertyUser1]);
            Assert.AreEqual("TestUser2", values[MixedScopeSettingsBase.PropertyUser2]);
			
			SystemConfigurationHelper.GetExeConfiguration().RemoveSettingsValues(localSettingsClass);
		}
Ejemplo n.º 12
0
		/// <summary>
		/// Stores the settings values for a given settings class.
		/// </summary>
        /// <param name="configuration">the configuration where the values will be stored</param>
		/// <param name="settingsClass">the settings class for which to store the values</param>
		/// <param name="dirtyValues">contains the values to be stored</param>
        public static void PutSettingsValues(SystemConfiguration configuration, Type settingsClass, Dictionary<string, string> dirtyValues)
		{
			var applicationScopedProperties = GetProperties(settingsClass, SettingScope.Application);
			var userScopedProperties = GetProperties(settingsClass, SettingScope.User);

			bool modified = false;
			if (applicationScopedProperties.Count > 0)
			{
				var sectionPath = new ConfigurationSectionPath(settingsClass, SettingScope.Application);
				var group = sectionPath.GroupPath.GetSectionGroup(configuration, true);
				modified = StoreSettings(group, sectionPath.SectionName, applicationScopedProperties, dirtyValues);
			}
			if (userScopedProperties.Count > 0)
			{
				var sectionPath = new ConfigurationSectionPath(settingsClass, SettingScope.User);
				var group = sectionPath.GroupPath.GetSectionGroup(configuration, true);
				if (StoreSettings(group, sectionPath.SectionName, userScopedProperties, dirtyValues))
					modified = true;
			}

			if (modified)
				configuration.Save(ConfigurationSaveMode.Minimal, true);
		}
Ejemplo n.º 13
0
	    public static void RemoveSettingsValues(this SystemConfiguration configuration, Type settingsClass, SettingScope? scope = null)
	    {
	        var removeApplicationSettings = !scope.HasValue || scope.Value == SettingScope.Application;
            var removeUserSettings = !scope.HasValue || scope.Value == SettingScope.User;

            if (removeApplicationSettings)
            {
                var sectionPath = new ConfigurationSectionPath(settingsClass, SettingScope.Application);
                ConfigurationSectionGroup group = configuration.GetSectionGroup(sectionPath.GroupPath);
                if (group != null)
                    group.Sections.Remove(sectionPath.SectionName);
            }

            if (removeUserSettings)
            {
                var sectionPath = new ConfigurationSectionPath(settingsClass, SettingScope.User);
                var group = configuration.GetSectionGroup(sectionPath.GroupPath);
                if (group != null)
                    group.Sections.Remove(sectionPath.SectionName);
            }

	        configuration.Save(ConfigurationSaveMode.Minimal, true);
		}
Ejemplo n.º 14
0
		/// <summary>
		/// Stores the settings values for a given settings class.
		/// </summary>
        /// <param name="configuration">the configuration where the values will be stored</param>
		/// <param name="settingsClass">the settings class for which to store the values</param>
		/// <param name="dirtyValues">contains the values to be stored</param>
        public static void PutSettingsValues(this SystemConfiguration configuration, Type settingsClass, IDictionary<string, string> dirtyValues)
		{
			var applicationScopedProperties = GetProperties(settingsClass, SettingScope.Application);
			var userScopedProperties = GetProperties(settingsClass, SettingScope.User);

			bool modified = false;
			if (applicationScopedProperties.Count > 0)
			{
				var sectionPath = new ConfigurationSectionPath(settingsClass, SettingScope.Application);
				modified = UpdateSection(configuration, sectionPath, applicationScopedProperties, dirtyValues);
			}
			if (userScopedProperties.Count > 0)
			{
				var sectionPath = new ConfigurationSectionPath(settingsClass, SettingScope.User);
				if (UpdateSection(configuration, sectionPath, userScopedProperties, dirtyValues))
					modified = true;
			}

			if (modified)
				configuration.Save(ConfigurationSaveMode.Minimal, true);
		}
Ejemplo n.º 15
0
		/// <summary>
		/// Gets only those settings values that are different from the defaults for the given settings group.
		/// </summary>
		/// <param name="configuration">the configuration where the values will be taken from</param>
		/// <param name="settingsClass">the settings class for which to get the values</param>
		/// <param name="settingScope">the scope of the settings for which to get the values</param>
		public static Dictionary<string, string> GetSettingsValues(this SystemConfiguration configuration, Type settingsClass, SettingScope settingScope)
		{
			var properties = GetProperties(settingsClass, settingScope);
			var sectionPath = new ConfigurationSectionPath(settingsClass, settingScope);
			return GetSettingsValues(configuration, sectionPath, properties);
		}
Ejemplo n.º 16
0
		private static Dictionary<string, string> GetSettingsValues(
			SystemConfiguration configuration, 
			ConfigurationSectionPath sectionPath, 
			ICollection<PropertyInfo> properties)
        {
            var values = new Dictionary<string, string>();
			if (properties.Count > 0)
			{
				var section = sectionPath.GetSection(configuration);
				if (section != null)
				{
					var clientSection = CastToClientSection(section);
					foreach (PropertyInfo property in properties)
					{
						SettingElement element = GetSettingElement(clientSection, property, false);
						if (element != null) //If the setting element is there, we'll assume it means the value is to be set.
							values[property.Name] = GetElementValue(element);
					}
				}
			}

            return values;
        }
Ejemplo n.º 17
0
		private static bool UpdateSection(SystemConfiguration configuration, ConfigurationSectionPath sectionPath, IEnumerable<PropertyInfo> properties, IDictionary<string, string> newValues)
		{
			var section = sectionPath.GetSection(configuration);
			if (section != null)
				return UpdateSection(CastToClientSection(section), properties, newValues);

			var group = sectionPath.GroupPath.GetSectionGroup(configuration, true);
			section = sectionPath.CreateSection();

			if (!UpdateSection(CastToClientSection(section), properties, newValues))
				return false;

			group.Sections.Add(sectionPath.SectionName, section);
			return true;
		}
Ejemplo n.º 18
0
		public static void RemoveSettingsValues(SystemConfiguration configuration, Type settingsClass)
		{
			var sectionPath = new ConfigurationSectionPath(settingsClass, SettingScope.Application);
			ConfigurationSectionGroup group = configuration.GetSectionGroup(sectionPath.GroupPath);
			if (group != null)
				group.Sections.Remove(sectionPath.SectionName);

			sectionPath = new ConfigurationSectionPath(settingsClass, SettingScope.User);
			group = configuration.GetSectionGroup(sectionPath.GroupPath);
			if (group != null)
				group.Sections.Remove(sectionPath.SectionName);

			configuration.Save(ConfigurationSaveMode.Minimal, true);
		}
Ejemplo n.º 19
0
        private static Dictionary<string, string> GetSettingsValues(
			SystemConfiguration configuration, 
			ConfigurationSectionPath sectionPath, 
			ICollection<PropertyInfo> properties)
        {
            var values = new Dictionary<string, string>();
			if (properties.Count > 0)
			{
				var section = sectionPath.GetSection(configuration);
				if (section != null)
				{
					var clientSection = CastToClientSection(section);
					if (clientSection != null)
					{
						foreach (PropertyInfo property in properties)
						{
							SettingElement element = GetSettingElement(clientSection, property, false);
							if (element == null)
								continue;

							string currentValue = GetElementValue(element);
							if (currentValue == null) //not there means it's the default.
								continue;

							var defaultValue = SettingsClassMetaDataReader.GetDefaultValue(property, false);
							if (!Equals(currentValue, defaultValue))
								values[property.Name] = currentValue;
						}
					}
				}
			}

            return values;
        }