public void UpdateConfigFile(string name, string value) { try { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = configFile.AppSettings.Settings; if (settings[name] == null) { settings.Add(name, value); _messageManager.ProceedAnswer("value added"); } else { settings[name].Value = value; _messageManager.ProceedAnswer("value updated"); } ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); configFile.Save(ConfigurationSaveMode.Modified); SettingChanged?.Invoke(name); } catch (ConfigurationErrorsException e1) { _messageManager.ProceedAnswer("cannot update/write setting " + e1.Message, ConsoleColor.Red); } }
/// <summary> /// Initializes the wrapper. /// </summary> /// <param name="audioSourceDirectory">The directory of the audio source.</param> /// <returns>True if successful.</returns> public bool Initialize(string audioSourceDirectory) { try { _logger = AudioBandLogManager.GetLogger($"AudioSourceWrapper({new DirectoryInfo(audioSourceDirectory).Name})"); _logger.Debug("Initializing wrapper"); AppDomain.CurrentDomain.UnhandledException += (o, e) => _logger.Error(e.ExceptionObject as Exception, "Unhandled exception in wrapper"); _audioSource = AudioSourceLoader.LoadFromDirectory(audioSourceDirectory); _audioSource.Logger = new AudioSourceLogger(_audioSource.Name); _audioSource.SettingChanged += (o, e) => SettingChanged?.Invoke(this, e); _audioSource.TrackInfoChanged += (o, e) => TrackInfoChanged?.Invoke(this, e); _audioSource.IsPlayingChanged += (o, e) => IsPlayingChanged?.Invoke(this, e); _audioSource.TrackProgressChanged += (o, e) => TrackProgressChanged?.Invoke(this, e); _audioSource.VolumeChanged += (o, e) => VolumeChanged?.Invoke(this, e); _audioSource.ShuffleChanged += (o, e) => ShuffleChanged?.Invoke(this, e); _audioSource.RepeatModeChanged += (o, e) => RepeatModeChanged?.Invoke(this, e); _audioSourceSettingsList = _audioSource.GetSettings(); foreach (AudioSourceSetting setting in _audioSourceSettingsList) { _audioSourceSettings.Add(setting.Attribute.Name, setting); } _logger.Debug("Wrapper initialization complete"); return(true); } catch (Exception e) { _logger.Error(e); return(false); } }
private void Link_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox combo = (ComboBox)sender; if (combo.SelectedItem != null) { if (ParentSnapshot != null) { if (SelectedType == "Collected") { ParentSnapshot.Link = ((Page.CollectedItem)combo.SelectedItem).Id; } else if (SelectedType == "Generated") { ParentSnapshot.Link = ((Page.GeneratedEventItem)combo.SelectedItem).Id; } else { ParentSnapshot.Link = combo.Text; } } } if (combo.IsKeyboardFocusWithin) { SettingChanged?.Invoke(); } }
void event_bt_SettingChanged() { if (!loading) { SettingChanged?.Invoke(null, null, null); } }
public void SetSetting(string settingName, object value) { if (string.IsNullOrWhiteSpace(settingName)) { throw new ArgumentNullException(nameof(settingName)); } if (!Enum.GetNames(typeof(AppSettings)).Contains(settingName)) { throw new ArgumentOutOfRangeException(paramName: nameof(settingName), message: "Setting not found."); } if (!ApplicationData.Current.LocalSettings.Values.ContainsKey(settingName)) { ApplicationData.Current.LocalSettings.Values.Add(settingName, value); } else { ApplicationData.Current.LocalSettings.Values[settingName] = value; } SettingChanged?.Invoke(this, new NepAppSettingChangedEventArgs() { ChangedSetting = (AppSettings)Enum.Parse(typeof(AppSettings), settingName), NewValue = value }); }
public void set(string key, string value) { UserSetting setting; if (!settingsDictionary.TryGetValue(key, out setting)) { // If the setting for the given key doesn't exist, create it setting = new UserSetting() { Name = key }; settingsDictionary[key] = setting; } // Special case to propagate Language to local property on assignment if (key == "Language") { this.Language = value; } setting.Value = value; setting.Commit(); SettingChanged?.Invoke(this, new StringEventArgs(key)); }
private void ParentContainer_SettingChanging(object sender, SettingChangeEventArgs e) { if (e.Key.StartsWith(KeyPrefix)) { var rawKey = e.Key.Substring(KeyPrefix.Length); SettingChanged?.Invoke(this, new SettingChangeEventArgs(Tag, rawKey, e.OldValue, e.NewValue)); } }
private void Link_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox combo = (ComboBox)sender; if (combo.IsKeyboardFocusWithin) { SettingChanged?.Invoke(); } }
private void productionType_COMBO_TextChanged(object sender, TextChangedEventArgs e) { ComboBox combo = (ComboBox)sender; if (combo.IsKeyboardFocusWithin || combo.IsMouseCaptured) { SettingChanged?.Invoke(); } }
public void LoadFrom <TLookup>(ConfigManager <TLookup> configManager) where TLookup : struct, Enum { foreach (var value in this) { value.LoadFrom(configManager); value.SettingChanged += d => SettingChanged?.Invoke(d); } }
private void Item_RemoveClicked(Controls.PartCountEventItem item) { int i = PartCountItems.ToList().FindIndex(o => o.Id == item.Id); if (i >= 0) { PartCountItems.RemoveAt(i); SettingChanged?.Invoke(null, null, null); } }
void ChangeSetting(string name, string val) { if (!Loading) { string newVal = val; string oldVal = null; SettingChanged?.Invoke(name, oldVal, newVal); } }
private void Add_Clicked(TrakHound_UI.Button bt) { var snapshot = new Controls.SnapshotItem(this); snapshot.SettingChanged += Snapshot_SettingChanged; snapshot.RemoveClicked += Snapshot_RemoveClicked; SnapshotItems.Add(snapshot); SettingChanged?.Invoke(null, null, null); }
public void Update(DatabasedSetting setting) { using (ContextFactory.GetForWrite()) { var newValue = setting.Value; Refresh(ref setting); setting.Value = newValue; } SettingChanged?.Invoke(); }
private void Snapshot_RemoveClicked(Controls.SnapshotItem item) { int index = SnapshotItems.ToList().FindIndex(x => x.Id == item.Id); if (index >= 0) { SnapshotItems.RemoveAt(index); } SettingChanged?.Invoke(null, null, null); }
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\ #region --Constructors-- #endregion //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\ #region --Set-, Get- Methods-- /// <summary> /// Sets a setting with the given token. /// </summary> /// <param name="token">The token for saving.</param> /// <param name="value">The value that should get stored.</param> public static void SetSetting(string token, object value) { if (value is DateTime d) { SetSetting(token, d.ToFileTimeUtc()); return; } ApplicationData.Current.LocalSettings.Values[token] = value; SettingChanged?.Invoke(value, new PropertyChangedEventArgs(token)); }
public void Set <T>(string key, T value) { SetValue( value, actBeforeChange: (oldValue, newValue) => { SettingChanging?.Invoke(this, new SettingChangeEventArgs(Tag, key, oldValue, newValue)); }, actAfterChange: (oldValue, newValue) => { SettingChanged?.Invoke(this, new SettingChangeEventArgs(Tag, key, oldValue, newValue)); }, propertyName: key); }
internal ConfigWrapper(ConfigEntry <T> configEntry) { ConfigEntry = configEntry ?? throw new ArgumentNullException(nameof(configEntry)); configEntry.ConfigFile.SettingChanged += (sender, args) => { if (args.ChangedSetting == configEntry) { SettingChanged?.Invoke(sender, args); } }; }
private void EightWay_CheckBox_Checked(object sender, RoutedEventArgs e) { bool newVal = (bool)EightWayCheckBox.IsChecked; if (newVal != Properties.Settings.Default.EightWay) { // TODO: Разобраться с файлом настроек и не городить такие безобразные строчки PathfindingLib.GlobalSettings.EightWay = Properties.Settings.Default.EightWay = newVal; Properties.Settings.Default.Save(); SettingChanged?.Invoke(); } }
private void _renderSettings() { foreach (var setting in Settings.Values) { // don't show unnecessary settings if (_unnecessarySettings.Contains(setting.Name)) { continue; } var p = new Panel { Width = gbSettings.Width, Height = 20, Dock = DockStyle.Top }; // p.BorderStyle = BorderStyle.FixedSingle; gbSettings.Controls.Add(p); var l = new Label { Text = setting.LabelText ?? "", Location = new Point(10, 4) }; p.Controls.Add(l); var tb = new TextBox { Text = (setting.Value ?? "").ToString(), Dock = DockStyle.Right }; //tb.Location = new Point(10, 4); tb.LostFocus += (sender, e) => { if ((setting.Value?.ToString() ?? "") != tb.Text) { SettingChanged?.Invoke(setting, new SettingChangedEventArgs(setting.Name, tb.Text)); } }; var pTextBoxWrapper = new Panel { Dock = DockStyle.Right, Padding = new Padding(4), Width = tb.Width + 10 }; p.AutoSize = true; //pTextBoxWrapper.BorderStyle = BorderStyle.FixedSingle; p.Controls.Add(pTextBoxWrapper); pTextBoxWrapper.Controls.Add(tb); } }
public void SetSetting(string key, object value) { XAttribute setting = FindAttribute(configFile, key); if (setting.Value == value.ToString()) { return; } setting.Value = value.ToString(); SettingChanged?.Invoke(this, key); }
public void Set <T>(string key, T value) { if (value is string) { WriteSetting <T>(key, value); } else { WriteSetting(key, Serializer.ToString(key, value)); } SettingChanged?.Invoke(this, key); }
void Event_AddCaptureItemClicked(Controls.Event e) { CaptureItem ci = new CaptureItem(); if (e.ParentEvent != null) { Controls.CaptureItem item = CreateCaptureItem(ci, e.ParentEvent); e.ParentEvent.captureItems.Add(ci); e.CaptureItems.Add(item); } SettingChanged?.Invoke(null, null, null); }
private void EventValue_COMBO_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox combo = (ComboBox)sender; string val = (string)combo.SelectedValue; GetPreviousGeneratedEventValues(val); if (combo.IsKeyboardFocusWithin || combo.IsMouseCaptured) { SettingChanged?.Invoke(); } }
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { TextBox txt = (TextBox)sender; if (ParentResult != null) { ParentResult.value = txt.Text; } if (txt.IsKeyboardFocused) { SettingChanged?.Invoke(); } }
private void Link_TextChanged(object sender, TextChangedEventArgs e) { var combo = (ComboBox)sender; if (ParentTrigger != null) { ParentTrigger.link = combo.Text; } if (combo.IsKeyboardFocusWithin) { SettingChanged?.Invoke(); } }
private void name_TXT_TextChanged(object sender, TextChangedEventArgs e) { TextBox txt = (TextBox)sender; if (ParentSnapshot != null) { ParentSnapshot.Name = txt.Text; } if (txt.IsKeyboardFocusWithin) { SettingChanged?.Invoke(); } }
private void ComboBox_TextChanged(object sender, TextChangedEventArgs e) { ComboBox combo = (ComboBox)sender; if (ParentSnapshot != null) { ParentSnapshot.Link = combo.Text; } if (combo.IsKeyboardFocusWithin || combo.IsMouseCaptured) { SettingChanged?.Invoke(); } }
private void variable_TXT_TextChanged(object sender, TextChangedEventArgs e) { TextBox txt = (TextBox)sender; if (ParentSnapshot != null) { ParentSnapshot.Link = txt.Text; } if (txt.IsKeyboardFocused || txt.IsMouseCaptured) { SettingChanged?.Invoke(); } }
public void Update(DatabasedSetting setting) { var context = GetContext(); var newValue = setting.Value; Refresh(ref setting); setting.Value = newValue; context.SaveChanges(); SettingChanged?.Invoke(); }