static SettingsStore <AppSettings> LoadSettings() { var path = SettingsDirectory.GetDefaultSettingsFilePath(AppSettings.DefaultSettingsFile); var store = SettingsStore <AppSettings> .Create(path); return(store); }
/// <summary> /// Launches the <see cref="SettingsManagementComponent"/> or activates it if it's already open. /// </summary> /// <remarks> /// This method first looks for a valid extension of <see cref="SettingsStoreExtensionPoint"/> and /// with which to initialize the <see cref="SettingsManagementComponent"/>. If one is not found, /// an instance of <see cref="LocalSettingsStore"/> is instantiated and passed to the /// <see cref="SettingsManagementComponent"/>. The <see cref="LocalSettingsStore"/> allows /// the local application settings to be modified, where by default they cannot be. /// </remarks> public void Activate() { if (_workspace != null) { _workspace.Activate(); return; } ISettingsStore store; try { store = SettingsStore.Create(); } catch (NotSupportedException) { // there is no central settings store store = new NullSettingsStore(); } if (!store.IsOnline) { Context.DesktopWindow.ShowMessageBox(SR.MessageSettingsStoreOffline, MessageBoxActions.Ok); return; } _workspace = ApplicationComponent.LaunchAsWorkspace( this.Context.DesktopWindow, new SettingsManagementComponent(store), SR.TitleSettingsEditor, "Settings Management"); _workspace.Closed += OnWorkspaceClosed; }
/// <summary> /// Launches the <see cref="SettingsManagementComponent"/> or activates it if it's already open. /// </summary> /// <remarks> /// This method first looks for a valid extension of <see cref="SettingsStoreExtensionPoint"/> and /// with which to initialize the <see cref="SettingsManagementComponent"/>. If one is not found, /// an instance of <see cref="LocalSettingsStore"/> is instantiated and passed to the /// <see cref="SettingsManagementComponent"/>. The <see cref="LocalSettingsStore"/> allows /// the local application settings to be modified, where by default they cannot be. /// </remarks> public void Activate() { if (_workspace != null) { _workspace.Activate(); return; } ISettingsStore store; try { store = SettingsStore.Create(); //If there is a store, and it is not online, then settings can't be edited. if (!store.IsOnline) { Context.DesktopWindow.ShowMessageBox(SR.MessageSettingsStoreOffline, MessageBoxActions.Ok); return; } } catch (NotSupportedException) { // There is no central settings store; all settings will be treated as though they were local. store = new NullSettingsStore(); } _workspace = ApplicationComponent.LaunchAsWorkspace( this.Context.DesktopWindow, new SettingsManagementComponent(store), SR.TitleSettingsEditor, "Settings Management"); _workspace.Closed += OnWorkspaceClosed; }
/// <summary> /// Launches the <see cref="SettingsManagementComponent"/> or activates it if it's already open. /// </summary> /// <remarks> /// This method first looks for a valid extension of <see cref="SettingsStoreExtensionPoint"/> and /// with which to initialize the <see cref="SettingsManagementComponent"/>. If one is not found, /// an instance of <see cref="LocalSettingsStore"/> is instantiated and passed to the /// <see cref="SettingsManagementComponent"/>. The <see cref="LocalSettingsStore"/> allows /// the local application settings to be modified, where by default they cannot be. /// </remarks> public void Activate() { if (_workspace != null) { _workspace.Activate(); return; } ISettingsStore store; try { // if this throws an exception, only the default LocalFileSettingsProvider can be used. store = SettingsStore.Create(); } catch (NotSupportedException) { //allow editing of the app.config file via the LocalSettingsStore. store = new LocalSettingsStore(); } if (!store.IsOnline) { base.Context.DesktopWindow.ShowMessageBox(SR.MessageSettingsStoreOffline, MessageBoxActions.Ok); return; } _workspace = ApplicationComponent.LaunchAsWorkspace( this.Context.DesktopWindow, new SettingsManagementComponent(store), SR.TitleSettingsEditor, "Settings Management"); _workspace.Closed += OnWorkspaceClosed; }
public SettingsController() { _lazySettingsStore = new Lazy <SettingsStore>(() => { var appDataPath = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();; return(SettingsStore.Create(appDataPath)); }); }
public void RunApplication(string[] args) { var cmdLine = new SetSettingCommandLine(); try { cmdLine.Parse(args); using (new AuthenticationScope(cmdLine.UserName, "setup", Dns.GetHostName(), cmdLine.Password)) { ISettingsStore store; try { store = SettingsStore.Create(); //If there is a store, and it is not online, then settings can't be edited. if (!store.IsOnline) { Platform.Log(LogLevel.Error, "Settings Store is not online, cannot update configuration"); return; } } catch (NotSupportedException) { // There is no central settings store; all settings will be treated as though they were local. Platform.Log(LogLevel.Error, "No Enterprise settings store, cannot update configuration"); return; } if (!string.IsNullOrEmpty(cmdLine.SettingData)) { SetupHelper.ImportSettingsDefinition(store, cmdLine.SettingData, cmdLine.Overwrite); } else { var settings = new List <SettingDefinition> { new SettingDefinition { Group = cmdLine.SettingGroup, Property = cmdLine.SettingName, Version = cmdLine.Version, Value = cmdLine.Value } }; SetupHelper.ImportSettingsDefinition(store, settings, cmdLine.Overwrite); } } } catch (CommandLineException e) { Console.WriteLine(e.Message); Platform.Log(LogLevel.Error, e, "Command line error."); } }
/// <summary> /// Constructor /// </summary> private XmlValidationManager() { try { _settingsStore = SettingsStore.Create(); } catch (NotSupportedException e) { Platform.Log(LogLevel.Debug, e); } }
public async Task LoadFollowedByExternalUpdate() { var path = Path.GetTempFileName(); try { File.WriteAllLines(path, new[] { "<?xml version=\"1.0\" encoding=\"utf-8\"?>", "<HandsFreeSettings>", " <General VoiceVolume=\"7\"/>", "</HandsFreeSettings>" }); using (var store = SettingsStore <AppSettings> .Create(path)) { Assert.AreEqual(7, store.Settings.General.VoiceVolume); Assert.AreEqual(10, store.Settings.General.ClickVolume); Assert.AreEqual(15, store.Settings.Mouse.Filter.HistoryLength); var semaphore = new SemaphoreSlim(0); store.Changed += (s, e) => { semaphore.Release(); }; File.WriteAllLines(path, new[] { "<?xml version=\"1.0\" encoding=\"utf-8\"?>", "<HandsFreeSettings>", " <General ClickVolume=\"3\"/>", "</HandsFreeSettings>" }); Assert.IsTrue(await semaphore.WaitAsync(TimeSpan.FromSeconds(0.5))); while (await semaphore.WaitAsync(TimeSpan.FromSeconds(0.25))) { // Spin. } Assert.AreEqual(7, store.Settings.General.VoiceVolume); Assert.AreEqual(3, store.Settings.General.ClickVolume); Assert.AreEqual(15, store.Settings.Mouse.Filter.HistoryLength); } } finally { File.Delete(path); } }
public FilmController() { _lazyFilmStore = new Lazy <FilmStore>(() => { var appDataPath = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();; var user = HttpContext.User.Identity.GetUserName(); return(FilmStore.Create(appDataPath, user)); }); _lazyParserFactory = new Lazy <WebsiteParserFactory>(() => { var appDataPath = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();; var settingsStore = SettingsStore.Create(appDataPath); return(new WebsiteParserFactory(settingsStore.Settings.UseProxy, settingsStore.Settings.ProxyAddress)); }); }
public void CheckFirstInstallBehaviour() { // Get a file to work with. var path = Path.GetTempFileName(); Assert.IsTrue(File.Exists(path)); File.Delete(path); Assert.IsFalse(File.Exists(path)); try { Assert.IsFalse(File.Exists(path), "File does not initially exist"); using (var store = SettingsStore <AppSettings> .Create(path)) { Assert.AreEqual(10, store.Settings.General.ClickVolume, "ClickVolume starts at known default value"); store.Settings.General.ClickVolume = 5; Assert.AreEqual(5, store.Settings.General.ClickVolume, "Change happened"); store.Save(); Assert.AreEqual(5, store.Settings.General.ClickVolume, "Locally set ClickVolume change retained"); } Assert.IsTrue(File.Exists(path), "File was created by the above"); using (var store = SettingsStore <AppSettings> .Create(path)) { Assert.AreEqual(5, store.Settings.General.ClickVolume, "ClickVolume change persisted"); store.Reset(); Assert.AreEqual(10, store.Settings.General.ClickVolume, "ClickVolume returned to default"); } } finally { // Clean up test. File.Delete(path); } }
public void RunApplication(string[] args) { var cmdLine = new SetSettingCommandLine(); try { cmdLine.Parse(args); using (new AuthenticationScope(cmdLine.UserName, "setup", Dns.GetHostName(), cmdLine.Password)) { ISettingsStore store; try { store = SettingsStore.Create(); //If there is a store, and it is not online, then settings can't be edited. if (!store.IsOnline) { Platform.Log(LogLevel.Error, "Settings Store is not online, cannot update configuration option: {0}/{1} to {2} ", cmdLine.SettingGroup, cmdLine.SettingName, cmdLine.Value); return; } } catch (NotSupportedException) { // There is no central settings store; all settings will be treated as though they were local. Platform.Log(LogLevel.Error, "No Enterprise settings store, cannot update configuration option: {0}/{1} to {2} ", cmdLine.SettingGroup, cmdLine.SettingName, cmdLine.Value); return; } if (!string.IsNullOrEmpty(cmdLine.ConfigData)) { SetupHelper.ImportConfigurations(cmdLine.ConfigData); return; } var found = false; var list = store.ListSettingsGroups(); foreach (var descriptor in list) { if (descriptor.Name.Equals(cmdLine.SettingGroup)) { if (!string.IsNullOrEmpty(cmdLine.Version)) { if (!descriptor.Version.ToString().Equals(cmdLine.Version)) { continue; } } var properties = store.ListSettingsProperties(descriptor); foreach (var property in properties) { if (property.Name.Equals(cmdLine.SettingName)) { // Note, we're not checking version information, so all settings are updated here that // match, regardless of version. var settings = store.GetSettingsValues(descriptor, null, null); settings[cmdLine.SettingName] = cmdLine.Value; store.PutSettingsValues(descriptor, null, null, settings); Platform.Log(LogLevel.Info, "Updated setting: {0}/{1}/{2} to {3} ", cmdLine.SettingGroup, cmdLine.SettingName, descriptor.Version, cmdLine.Value); found = true; } } } } if (!found) { Platform.Log(LogLevel.Error, "Settings stored did not have {0}/{1} set in it, cannot update setting to {2} ", cmdLine.SettingGroup, cmdLine.SettingName, cmdLine.Value); } } } catch (CommandLineException e) { Console.WriteLine(e.Message); Platform.Log(LogLevel.Error, e, "Command line error."); } }