public void RenameFormatterConfiguration(string configurationName, string newName) { if (string.IsNullOrWhiteSpace(configurationName)) { throw new ArgumentException("Formatter configuration name cannot be null or whitespace.", "configurationName"); } if (string.IsNullOrWhiteSpace(newName)) { throw new ArgumentException("Formatter configuration name cannot be null or whitespace.", "newName"); } if (!FormatterConfigurations.ContainsKey(configurationName)) { throw new ArgumentException( string.Format("Formatter configuration named {0} does not exist.", configurationName), "configurationName"); } bool resetCurrentlySelected = AppSettings.Settings.CurrentFormatterConfigurationName == configurationName; var old = FormatterConfigurations[configurationName]; FormatterConfigurations.Remove(configurationName); FormatterConfigurations.Add(newName, old); if (resetCurrentlySelected) { AppSettings.Settings.CurrentFormatterConfigurationName = newName; } }
public void RemoveFormatterConfiguration(string configurationName, string newCurrentConfiguration) { if (string.IsNullOrWhiteSpace(configurationName)) { throw new ArgumentException("Formatter configuration name cannot be null or whitespace.", "configurationName"); } if (string.IsNullOrWhiteSpace(newCurrentConfiguration)) { throw new ArgumentException("Formatter configuration name cannot be null or whitespace.", "newCurrentConfiguration"); } if (!FormatterConfigurations.ContainsKey(configurationName)) { throw new ArgumentException( string.Format("Formatter configuration named {0} does not exist.", configurationName), "configurationName"); } if (!FormatterConfigurations.ContainsKey(newCurrentConfiguration)) { throw new ArgumentException( string.Format("Formatter configuration named {0} does not exist.", newCurrentConfiguration), "newCurrentConfiguration"); } if (FormatterConfigurations.Count == 1) { throw new InvalidOperationException( "There must be at least one formatter configuration present in the " + "application settings, cannot remove the configuration as it is the only one present."); } FormatterConfigurations.Remove(configurationName); CurrentFormatterConfigurationName = newCurrentConfiguration; }