public static void SetSharedPropertyValue(this ApplicationSettingsBase settings, string propertyName, object value) { SettingsProperty property = settings.Properties[propertyName]; if (property == null) { throw new ArgumentException(String.Format("The specified property does not exist: {0}", propertyName), "propertyName"); } ISharedApplicationSettingsProvider sharedSettingsProvider = GetSharedSettingsProvider(property.Provider); if (sharedSettingsProvider == null) { throw new NotSupportedException("Setting shared values is not supported."); } SettingsPropertyValue settingsValue = new SettingsPropertyValue(property) { PropertyValue = value }; sharedSettingsProvider.SetSharedPropertyValues(settings.Context, new SettingsPropertyValueCollection { settingsValue }); SaveIfDirty(settings); //Need to call Reload because changes to shared settings aren't automatically realized by the .NET settings framework. settings.Reload(); }
private void btnReset_Click(object sender, EventArgs e) { //Properties.Settings.Default.Reload (); settings.Reload(); //settings.Upgrade(); propertyGrid1.Refresh(); }
public static void Add <T>(this ApplicationSettingsBase settings, string propertyName, T val) { if (settings.Properties[propertyName] != null) { return; } var p = new SettingsProperty(propertyName) { PropertyType = typeof(T), Provider = settings.Providers["LocalFileSettingsProvider"], SerializeAs = SettingsSerializeAs.String }; p.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute()); settings.Properties.Add(p); settings.Reload(); //finally set value with new value if none was loaded from userConfig.xml var item = settings[propertyName]; if (item == null) { settings[propertyName] = val; settings.Save(); } }
private static void SetSharedPropertyValues(ApplicationSettingsBase settings, Dictionary <string, string> values) { foreach (SettingsProvider provider in settings.Providers) { ISharedApplicationSettingsProvider sharedSettingsProvider = GetSharedSettingsProvider(provider); if (sharedSettingsProvider == null) { throw new NotSupportedException("Setting shared values is not supported."); } var properties = GetPropertiesForProvider(settings, provider); SettingsPropertyValueCollection settingsValues = new SettingsPropertyValueCollection(); foreach (var value in values) { SettingsProperty property = properties[value.Key]; if (property == null) { continue; } settingsValues.Add(new SettingsPropertyValue(property) { SerializedValue = value.Value, IsDirty = true }); } sharedSettingsProvider.SetSharedPropertyValues(settings.Context, settingsValues); } SaveIfDirty(settings); settings.Reload(); }
public void OnSaveOptions() { _Saving = true; if (OptionsSaving != null) { OptionsSaving(this, EventArgs.Empty); } foreach (SettingsProperty sett in _Settings) { try { _AppSettings[sett.Name] = sett.DefaultValue; } catch { } } if (_AutomaticSaveSettings) { _AppSettings.Save(); _AppSettings.Reload(); if (OptionsSaved != null) { OptionsSaved(this, EventArgs.Empty); } } _Saving = false; }
private string AddNew(string key, string value) { ApplicationSettingsBase settings = Properties.Settings.Default; var p = new SettingsProperty(key) { PropertyType = typeof(string), Provider = settings.Providers["LocalFileSettingsProvider"], SerializeAs = SettingsSerializeAs.Xml }; p.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute()); settings.Properties.Add(p); settings.Reload(); //finally set value with new value if none was loaded from userConfig.xml var item = settings[key]; if (item == null) { settings[key] = value; settings.Save(); return(value); } else { return(item.ToString()); } }
static void RedirectSettings(ApplicationSettingsBase settings, SettingsProvider provider) { settings.Providers.Add(provider); foreach (SettingsProperty property in settings.Properties) { property.Provider = provider; } settings.Reload(); }
public ConfigurationService(IEventAggregator eventAggregator, IApplicationSettingsBaseFactory applicationSettingsFactory) { _eventAggregator = eventAggregator; _settings = applicationSettingsFactory.CreateDefault(); _settings.Reload(); EnsureValueCollectionPopulated(); IsInitialized = true; }
private static void MakePortable(ApplicationSettingsBase settings) { var portableSettingsProvider = new PortableSettingsProvider(); settings.Providers.Add(portableSettingsProvider); foreach (SettingsProperty prop in settings.Properties) { prop.Provider = portableSettingsProvider; } settings.Reload(); }
private static void MakePortable(ApplicationSettingsBase settings) { var portableSettingsProvider = new PortableSettingsProvider2();//(settings.GetType().Name + ".settings"); settings.Providers.Add(portableSettingsProvider); foreach (System.Configuration.SettingsProperty prop in settings.Properties) { prop.Provider = portableSettingsProvider; } settings.Reload(); }
/// <summary> /// Sets the settings provider of the specified settings to an instance of the SimplerFileSettingsProvider class. /// </summary> /// <param name="settings">The settings that will use the SimplerFileSettingsProvider.</param> public static void ApplyProvider(ApplicationSettingsBase settings) { var simplerFileSettingsProvider = new SimplerFileSettingsProvider(); settings.Providers.Add(simplerFileSettingsProvider); foreach (SettingsProperty property in settings.Properties) { property.Provider = simplerFileSettingsProvider; } settings.Reload(); }
private static SettingsProperty AddUserSetting(this ApplicationSettingsBase settings, string settingName, Type settingType, object defaultValue) { var val = Convert.ChangeType(defaultValue, settingType); var provider = settings.Providers.Cast <SettingsProvider>().FirstOrDefault(); var setting = new SettingsProperty(settingName) { PropertyType = settingType, DefaultValue = val, IsReadOnly = false, Provider = provider }; setting.Attributes[setting.Attributes.Count] = new UserScopedSettingAttribute(); settings.Properties.Add(setting); settings.Reload(); return(setting); }
private static void MakePortable(ApplicationSettingsBase settings) { var portableSettingsProvider = new PortableSettingsProvider("Mist.settings"); settings.Providers.Add(portableSettingsProvider); foreach (System.Configuration.SettingsProperty prop in settings.Properties) { prop.Provider = portableSettingsProvider; } if (Type.GetType("Mono.Runtime") == null) { settings.Reload(); } }
/// <summary> /// Changes the settings provider so as to store settings in Helper.GetAppdataPath(), not some cryptic directory as is standard. /// </summary> /// <param name="settings"></param> public static void RewireSettingsProvider(ApplicationSettingsBase settings) { string SettingsFile = Path.Combine(Helper.GetAppdataPath(), "TikzEdt.settings"); var portableSettingsProvider = new TESettingsProvider(SettingsFile); settings.Providers.Add(portableSettingsProvider); foreach (System.Configuration.SettingsProperty prop in settings.Properties) { prop.Provider = portableSettingsProvider; } if (File.Exists(SettingsFile)) // mono throws an exception if one reloads w/o file present for some unknown reason { settings.Reload(); } }
public void OnSaveOptions(CancelEventArgs e) { OnSaveOptionsStart(); _Saving = true; try { if (OptionsSaving != null) { OptionsSaving(this, e); } } catch { // string msg = ServiceManager.ErrorHandler.GetExceptionMessages(ex); // MessageBox.Show(msg, "Invalid setup item...", MessageBoxButtons.OK, MessageBoxIcon.Error); // CancelEventArgs cancelClose = (CancelEventArgs)e; // cancelClose.Cancel = true; } foreach (SettingsProperty sett in _Settings) { try { _AppSettings[sett.Name] = sett.DefaultValue; } catch { } } if (_AutomaticSaveSettings) { _AppSettings.Save(); _AppSettings.Reload(); if (OptionsSaved != null) { OptionsSaved(this, e); } } _Saving = false; OnSaveOptionsEnd(); }
/// <summary> /// 檢查更新時載入舊版本設定參數,請先建立參數 bool _SettingUpgrade = false /// </summary> /// <param name="settings"></param> static public void Run(ApplicationSettingsBase settings) { //檢查是否為新版本未更新參數值 if (Upgraded == false) { //從舊版本載入設定 settings.Upgrade(); //存檔 settings.Save(); //設定為已載入舊版本參數 Upgraded = true; } //重載入設定參數值 settings.Reload(); }
public static ControllerSettings GetControllerSettings(ApplicationSettingsBase settings, Type controllerType) { if (controllerType == null) { return(null); } string propKey = controllerType.FullName; Type settingsType = Controllers.GetControllerSettingsType(controllerType); if (settingsType == null) { return(null); } // Add entry for custom settings property (required for it to be accessable) var prop = new SettingsProperty(propKey); prop.DefaultValue = null; prop.IsReadOnly = false; prop.PropertyType = settingsType; // Must match the actual type being used for it to serialize properly prop.Provider = settings.Providers["LocalFileSettingsProvider"]; prop.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute), new System.Configuration.UserScopedSettingAttribute()); prop.SerializeAs = SettingsSerializeAs.Xml; prop.ThrowOnErrorSerializing = true; prop.ThrowOnErrorDeserializing = true; try { settings.Properties.Add(prop); settings.Reload(); } catch (System.ArgumentException) { } // Ignore if it's already been added // Load the settings for the specific controller var conf = settings[propKey]; if (conf == null) { // Set defaults conf = (ControllerSettings)Activator.CreateInstance(settingsType); settings[propKey] = conf; settings.Save(); } return((ControllerSettings)conf); }
private void OnUserValidated(object src, UserValidatedEventArgs e) { _NeedToDoReset = GetNeedToReset(); if (_Properties != null && _Properties.Count > 0 && string.Compare(e.UserName, _UserName, StringComparison.OrdinalIgnoreCase) != 0) { try { if (_SettingsBaseClass != null) { _SettingsBaseClass.Reload(); } // _PropertyValues = new SettingsPropertyValueCollection(); // GetPropertyValuesCore(); // refresh the collection } catch { // it's possible that the (new) user doesn't have the same props // if (_PropertyValues.Count < _Properties.Count) // SetRemainingValuesToDefault(); } } }
public static bool ShowModal(ApplicationSettingsBase settings) { if (settings == null) throw new ArgumentNullException("settings"); using (CommonForm fm = new CommonForm()) { UcOptions ucOptions = new UcOptions(settings); fm.AddControlForDialog(ucOptions, "Options"); if (fm.ShowDialog() == DialogResult.OK) { settings.Save(); return true; } else { settings.Reload(); return false; } } }
private void btnCancel_Click(object sender, EventArgs e) { //Properties.Settings.Default.Reload (); settings.Reload(); propertyGrid1.Refresh(); }
internal static void MigrateSharedSettings(ApplicationSettingsBase settings, string previousExeConfigFilename) { if (settings is IMigrateSettings) { IMigrateSettings customMigrator = (IMigrateSettings)settings; foreach (SettingsProvider settingsProvider in settings.Providers) { ISharedApplicationSettingsProvider sharedSettingsProvider = GetSharedSettingsProvider(settingsProvider); if (sharedSettingsProvider == null || !sharedSettingsProvider.CanUpgradeSharedPropertyValues(settings.Context)) { continue; } var properties = GetPropertiesForProvider(settings, settingsProvider); var previousValues = sharedSettingsProvider.GetPreviousSharedPropertyValues(settings.Context, properties, previousExeConfigFilename); if (previousValues == null || previousValues.Count == 0) { continue; } var currentValues = sharedSettingsProvider.GetSharedPropertyValues(settings.Context, properties); foreach (SettingsPropertyValue previousValue in previousValues) { SettingsPropertyValue currentValue = currentValues[previousValue.Name]; if (currentValue == null) { continue; } MigrateProperty(customMigrator, MigrationScope.Shared, currentValue, previousValue.PropertyValue); } foreach (SettingsPropertyValue property in currentValues) { if (!property.IsDirty) { continue; } sharedSettingsProvider.SetSharedPropertyValues(settings.Context, currentValues); break; } } } else { foreach (SettingsProvider settingsProvider in settings.Providers) { ISharedApplicationSettingsProvider sharedSettingsProvider = GetSharedSettingsProvider(settingsProvider); if (sharedSettingsProvider == null) { continue; } var properties = GetPropertiesForProvider(settings, settingsProvider); sharedSettingsProvider.UpgradeSharedPropertyValues(settings.Context, properties, previousExeConfigFilename); } } SaveIfDirty(settings); //Need to call Reload because changes to shared settings aren't automatically realized by the .NET settings framework. settings.Reload(); }
public static void Reload(ApplicationSettingsBase config) { config.Reload(); }
private void Button_Click(object sender, EventArgs e) { try { if (sender == this.buttonApply) { // Get Property Grids List <PropertyGrid> propertyGrids = this.GetPropertyGrids(this.tabControlOptions); // Loop through each Property Grid foreach (PropertyGrid propertyGrid in propertyGrids) { // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Reload Application Settings settings.Save(); // Reload Application Settings propertyGrid.Refresh(); } // Disable Edited Button this.m_edited = false; } else if (sender == this.buttonCancel) { // Get Property Grids List <PropertyGrid> propertyGrids = this.GetPropertyGrids(this.tabControlOptions); // Reload foreach (PropertyGrid propertyGrid in propertyGrids) { // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Reload Application Settings settings.Reload(); } // Close this.Close(); } else if (sender == this.buttonReset) { DialogResult dialogResult = MessageBox.Show( Resources.TEXT_RESET_CURRENT_TAB_WARNING, Resources.TEXT_ARCDIAGRAMMER, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3, MessageBoxOptions.DefaultDesktopOnly); switch (dialogResult) { case DialogResult.Cancel: case DialogResult.No: break; case DialogResult.Yes: // Find Current Tab PropertyGrid propertyGrid = this.SelectedPropertGrid(this.tabControlOptions); if (propertyGrid == null) { return; } if (propertyGrid.SelectedObject == null) { return; } if (!(propertyGrid.SelectedObject is ApplicationSettingsBase)) { return; } // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Reset Application Settings settings.Reset(); // Refresh Application Settings propertyGrid.Refresh(); break; } } else if (sender == this.buttonResetAll) { DialogResult dialogResult = MessageBox.Show( Resources.TEXT_RESET_ALL_TABS_WARNING, Resources.TEXT_ARCDIAGRAMMER, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3, MessageBoxOptions.DefaultDesktopOnly); switch (dialogResult) { case DialogResult.Cancel: case DialogResult.No: break; case DialogResult.Yes: // Get Property Grids List <PropertyGrid> propertyGrids = this.GetPropertyGrids(this.tabControlOptions); // Loop for each Grid foreach (PropertyGrid propertyGrid in propertyGrids) { // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Reset Application Settings settings.Reset(); // Refresh Application Settings propertyGrid.Refresh(); } // Disable Edited Button this.m_edited = false; break; } } else if (sender == this.buttonOK) { // Get Property Grids List <PropertyGrid> propertyGrids = this.GetPropertyGrids(this.tabControlOptions); // Loop for each Grid foreach (PropertyGrid propertyGrid in propertyGrids) { // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Save Application Settings settings.Save(); } //Close this.Close(); } } catch (Exception ex) { ExceptionDialog.HandleException(ex); } }
/// <summary> /// 設定を再度読み込む /// </summary> /// <param name="settings"></param> public static void ReloadSettings(ApplicationSettingsBase settings) { settings.Reload(); }