public void TestReadWriteValues_Xml() { Type settingsClass = typeof(LocalXmlSettings); SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass); try { var values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), settingsClass); Assert.AreEqual(0, values.Count); values = new Dictionary <string, string>(); values[LocalXmlSettings.PropertyUser] = LocalXmlSettings.DefaultValueUser; values[LocalXmlSettings.PropertyApp] = LocalXmlSettings.DefaultValueApp; SystemConfigurationHelper.PutSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass, values); values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), settingsClass); Assert.AreEqual(1, values.Count); LocalXmlSettings settings = (LocalXmlSettings)ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); Assert.IsNull(ApplicationSettingsExtensions.GetSharedPropertyValue(settings, LocalXmlSettings.PropertyUser)); XmlDocument defaultDoc = new XmlDocument(); defaultDoc.LoadXml(LocalXmlSettings.DefaultValueApp); Assert.AreEqual(defaultDoc.DocumentElement.OuterXml, settings.App.DocumentElement.OuterXml); } finally { SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass); } }
public void TestGetPreviousSharedValues_Exists() { ResetAllSettingsClasses(); string path = Path.GetDirectoryName(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath); string fileName = String.Format("{0}{1}TestPrevious.exe.config", path, System.IO.Path.DirectorySeparatorChar); TestConfigResourceToFile(fileName); try { var settings = ApplicationSettingsHelper.GetSettingsClassInstance(_settingsClass); settings.Reload(); foreach (SettingsProperty property in settings.Properties) { var actual = ApplicationSettingsExtensions.GetPreviousSharedPropertyValue(settings, property.Name, fileName); var expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); Assert.AreEqual(expected, actual); } } finally { File.Delete(fileName); } }
public void TestSimpleUserSettingsMigration() { ResetUpgradeSettings(); Type settingsClass = typeof(SimpleUserSettings); PopulateSimpleStore(settingsClass); Assert.IsTrue(SettingsMigrator.MigrateUserSettings(settingsClass)); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); SettingsProperty property = settings.Properties[SimpleUserSettings.PropertyUser]; string expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Previous); string actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Previous); Assert.IsFalse(SettingsMigrator.MigrateUserSettings(settingsClass)); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); }
private static void ValidateStoredValues(Type type, MigrationScope migrationScope, SettingValue expectedValue) { var settings = ApplicationSettingsHelper.GetSettingsClassInstance(type); foreach (SettingsProperty property in settings.Properties) { string expected = CreateSettingValue(property, migrationScope, expectedValue); if (migrationScope == MigrationScope.User) { if (SettingsPropertyExtensions.IsAppScoped(property)) { continue; } string actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); } else { if (SettingsPropertyExtensions.IsAppScoped(property)) { string actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); } string shared = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, shared); } } }
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); }
private void ValidateLocalMixedScopeSettingsValuesInConfig(System.Configuration.Configuration configuration, SettingValue settingValue) { Type settingsClass = typeof(LocalMixedScopeSettings); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); settings.Reload(); SettingsProperty property = settings.Properties[LocalMixedScopeSettings.PropertyApp1]; string expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); string actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyApp2]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyUser1]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); var values = SystemConfigurationHelper.GetSettingsValues(configuration, settingsClass, SettingScope.Application); Assert.AreEqual(2, values.Count); property = settings.Properties[LocalMixedScopeSettings.PropertyApp1]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = values[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyApp2]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = values[property.Name]; Assert.AreEqual(expected, actual); values = SystemConfigurationHelper.GetSettingsValues(configuration, settingsClass, SettingScope.User); Assert.AreEqual(2, values.Count); property = settings.Properties[LocalMixedScopeSettings.PropertyUser1]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = values[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = values[property.Name]; Assert.AreEqual(expected, actual); }
public void SetLicenseInfo(string licenseKey) { var oldLicenseKey = ApplicationSettingsExtensions.GetSharedPropertyValue(new LicenseSettings(), "LicenseKey").ToString(); ApplicationSettingsExtensions.SetSharedPropertyValue(new LicenseSettings(), "LicenseKey", licenseKey); if (oldLicenseKey != licenseKey) { EventsHelper.Fire(LicenseInfoChanged, this, new EventArgs()); } }
public void RunApplication(string[] args) { CommandLine commandLine = new CommandLine(args); foreach (SettingsGroupDescriptor group in SettingsGroupDescriptor.ListInstalledSettingsGroups(SettingsGroupFilter.LocalStorage)) { Type type = Type.GetType(group.AssemblyQualifiedTypeName, true); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(type); ApplicationSettingsExtensions.ImportSharedSettings(settings, commandLine.ConfigurationFilename); } }
public void TestGetPreviousSharedValues_NoneExist() { ResetAllSettingsClasses(); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(_settingsClass); settings.Reload(); foreach (SettingsProperty property in settings.Properties) { var previous = ApplicationSettingsExtensions.GetPreviousSharedPropertyValue(settings, property.Name, null); Assert.IsNull(previous); } }
private static void TestMultipleSharedSettingsMigrated(Type mixedScopeSettingsClass) { if (!mixedScopeSettingsClass.IsSubclassOf(typeof(MixedScopeSettingsBase))) { throw new ArgumentException(); } ResetSimpleStore(); ResetAllSettingsClasses(); PopulateSimpleStore(mixedScopeSettingsClass); SettingsMigrator.MigrateSharedSettings(mixedScopeSettingsClass, null); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(mixedScopeSettingsClass); SettingsProperty property = settings.Properties[MixedScopeSettingsBase.PropertyUser1]; string expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current); string actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyApp1]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyApp2]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyUser1]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); }
public void TestCustomSharedSettingsMigration() { ResetSimpleStore(); ResetAllSettingsClasses(); Type settingsClass = typeof(CustomMigrationMixedScopeSettings); PopulateSimpleStore(settingsClass); SettingsMigrator.MigrateSharedSettings(settingsClass, null); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); SettingsProperty property = settings.Properties[CustomMigrationMixedScopeSettings.PropertyUser1]; string expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current); string actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[CustomMigrationMixedScopeSettings.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[CustomMigrationMixedScopeSettings.PropertyApp1]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[CustomMigrationMixedScopeSettings.PropertyApp2]; expected = "CustomApp2"; actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[CustomMigrationMixedScopeSettings.PropertyUser1]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[CustomMigrationMixedScopeSettings.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); }
public void TestGetSharedSettings_NoneExist() { RemoveSettings(); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(_settingsClass); settings.Reload(); foreach (SettingsProperty property in settings.Properties) { var shared = ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(property.DefaultValue, shared); if (SettingsPropertyExtensions.IsAppScoped(property)) { Assert.AreEqual(property.DefaultValue, settings[property.Name]); } } }
public void TestNonMigratableSharedSettings() { ResetUpgradeSettings(); Type settingsClass = typeof(NonMigratableSharedSettings); PopulateSimpleStore(settingsClass); Assert.IsFalse(SettingsMigrator.MigrateSharedSettings(settingsClass, null)); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); SettingsProperty property = settings.Properties[NonMigratableSharedSettings.PropertyApp]; string expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); Assert.AreEqual(expected, settings[property.Name]); string current = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, current); }
public void TestGetSharedSettings_Exists() { RemoveSettings(); SystemConfigurationHelperTests.WriteSharedValuesToConfig(_settingsClass, SettingValue.Current); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(_settingsClass); settings.Reload(); foreach (SettingsProperty property in settings.Properties) { var shared = ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); string expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); Assert.AreEqual(expected, shared); if (SettingsPropertyExtensions.IsAppScoped(property)) { Assert.AreEqual(expected, settings[property.Name]); } } }
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 TestMigrateXmlSettings() { Type settingsClass = typeof(LocalXmlSettings); var configuration = SystemConfigurationHelper.GetExeConfiguration(); var settings = (LocalXmlSettings)ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); XmlDocument document = new XmlDocument(); document.LoadXml((string)settings.Properties[LocalXmlSettings.PropertyApp].DefaultValue); var node = document.SelectSingleNode("//test"); node.InnerText = "CurrentApp"; Dictionary <string, string> values = new Dictionary <string, string>(); values[LocalXmlSettings.PropertyApp] = document.InnerXml; SystemConfigurationHelper.PutSettingsValues(configuration, settingsClass, values); string directory = Path.GetDirectoryName(configuration.FilePath); string previousExeFilename = String.Format("{0}{1}Previous.exe.config", directory, Path.DirectorySeparatorChar); try { TestConfigResourceToFile(previousExeFilename); SettingsMigrator.MigrateSharedSettings(settingsClass, previousExeFilename); configuration = SystemConfigurationHelper.GetExeConfiguration(); settings = (LocalXmlSettings)ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); settings.Reload(); document = (XmlDocument)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, LocalXmlSettings.PropertyApp); Assert.AreEqual("PreviousApp", document.SelectSingleNode("//test").InnerXml); document = settings.App; Assert.AreEqual("PreviousApp", document.SelectSingleNode("//test").InnerXml); } finally { File.Delete(previousExeFilename); SystemConfigurationHelper.RemoveSettingsValues(configuration, settingsClass); } }
public override void Save() { ApplicationSettingsExtensions.SetSharedPropertyValue(DicomPublishingSettings.Default, "SendLocalToStudySourceAE", PublishLocalToSourceAE); }
public void GetLicenseInfo(out string licenseKey, out string machineId) { licenseKey = ApplicationSettingsExtensions.GetSharedPropertyValue(new LicenseSettings(), "LicenseKey").ToString(); machineId = EnvironmentUtilities.MachineIdentifier; }
private object this[string propertyName] { get { return(_settings[propertyName]); } set { ApplicationSettingsExtensions.SetSharedPropertyValue(_settings, propertyName, value); } }