public static void Save() { CheckLoaded(); AliasConfiguration userConfiguration = new AliasConfiguration(); AliasConfiguration machineConfiguration = new AliasConfiguration(); userConfiguration.DefaultAliasName = _defaultAliasName; foreach (ServerAlias alias in _aliases.Values) { if (alias.IsUserAlias) { userConfiguration.Aliases.Add(alias); } else { machineConfiguration.Aliases.Add(alias); } } foreach (ServerAlias alias in _overriddenAliases.Values) { if (!machineConfiguration.Aliases.ContainsKey(alias.Name)) { machineConfiguration.Aliases.Add(alias); } } SaveUserAliasConfiguration(userConfiguration); SaveMachineAliasConfiguration(machineConfiguration); }
public static void Load() { Reset(); // Load Machine Aliases AliasConfiguration machineConfiguration = LoadMachineAliasConfiguration(); foreach (ServerAlias alias in machineConfiguration.Aliases.Values) { _aliases.Add(alias); } // Load User Aliases AliasConfiguration userConfiguration = LoadUserAliasConfiguration(); foreach (ServerAlias alias in userConfiguration.Aliases.Values) { ServerAlias machineAlias = _aliases[alias.Name]; if (machineAlias != null) { _overriddenAliases.Add(machineAlias); _aliases.Remove(alias.Name); } _aliases.Add(alias); } _defaultAliasName = userConfiguration.DefaultAliasName; }
public static void SaveConfiguration(AliasConfiguration configuration) { CheckLoaded(); _aliases.Clear(); foreach (ServerAlias alias in configuration.Aliases.Values) { _aliases.Add(alias); } _defaultAliasName = configuration.DefaultAliasName; Save(); }
public static AliasConfiguration LoadConfiguration() { AliasConfiguration configuration = new AliasConfiguration(); Load(); configuration.DefaultAliasName = _defaultAliasName; foreach (ServerAlias alias in _aliases.Values) { configuration.Aliases.Add(alias); } return(configuration); }
/// <summary> Loads a new alias configuration. </summary> /// <remarks> Creates a default alias configuration if the file doesn't exist. </remarks> public static AliasConfiguration Load(string fileName) { AliasConfiguration configuration = new AliasConfiguration(); if (File.Exists(fileName)) { using (Stream stream = File.OpenRead(fileName)) { new Deserializer().Deserialize(stream, configuration); } } return(configuration); }
private static AliasConfiguration LoadMachineAliasConfiguration() { var fileName = GetMachineAliasConfigurationFileName(); if (File.Exists(fileName)) { _machineConfigurationFileDate = File.GetLastWriteTimeUtc(fileName); } else { _machineConfigurationFileDate = default(DateTime); } return(AliasConfiguration.Load(fileName)); }
private static void SaveMachineAliasConfiguration(AliasConfiguration configuration) { var fileName = GetMachineAliasConfigurationFileName(); if ( _machineConfigurationFileDate == default(DateTime) || !File.Exists(fileName) || (File.GetLastWriteTimeUtc(fileName) <= _machineConfigurationFileDate) ) { try { configuration.Save(fileName); } catch (UnauthorizedAccessException) { // Don't throw if machine level saving fails due to permission error } } }
private static void SaveUserAliasConfiguration(AliasConfiguration configuration) { configuration.Save(GetUserAliasConfigurationFileName()); }
private static AliasConfiguration LoadUserAliasConfiguration() { return(AliasConfiguration.Load(GetUserAliasConfigurationFileName())); }