Пример #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()));
 }