示例#1
0
        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);
        }
示例#2
0
        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;
        }
示例#3
0
 public static void SaveConfiguration(AliasConfiguration configuration)
 {
     CheckLoaded();
     _aliases.Clear();
     foreach (ServerAlias alias in configuration.Aliases.Values)
     {
         _aliases.Add(alias);
     }
     _defaultAliasName = configuration.DefaultAliasName;
     Save();
 }
示例#4
0
        public static AliasConfiguration LoadConfiguration()
        {
            AliasConfiguration configuration = new AliasConfiguration();

            Load();
            configuration.DefaultAliasName = _defaultAliasName;
            foreach (ServerAlias alias in _aliases.Values)
            {
                configuration.Aliases.Add(alias);
            }
            return(configuration);
        }
示例#5
0
        /// <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);
        }
示例#6
0
        private static AliasConfiguration LoadMachineAliasConfiguration()
        {
            var fileName = GetMachineAliasConfigurationFileName();

            if (File.Exists(fileName))
            {
                _machineConfigurationFileDate = File.GetLastWriteTimeUtc(fileName);
            }
            else
            {
                _machineConfigurationFileDate = default(DateTime);
            }
            return(AliasConfiguration.Load(fileName));
        }
示例#7
0
        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
                }
            }
        }
示例#8
0
 private static void SaveUserAliasConfiguration(AliasConfiguration configuration)
 {
     configuration.Save(GetUserAliasConfigurationFileName());
 }
示例#9
0
 private static AliasConfiguration LoadUserAliasConfiguration()
 {
     return(AliasConfiguration.Load(GetUserAliasConfigurationFileName()));
 }