示例#1
0
        /// <summary>
        /// Load a configuration from local/remote location.
        /// </summary>
        /// <param name="configName">Configuration name</param>
        /// <param name="configUri">Configuration File URI</param>
        /// <param name="configType">Configuration Type</param>
        /// <param name="version">Configuration Version (expected)</param>
        /// <param name="settings">Configuration Settings</param>
        /// <param name="password">Password (if required)</param>
        /// <returns>Loaded Configruation</returns>
        public Configuration Load(string configName, string configUri,
                                  EConfigType configType, Version version,
                                  ConfigurationSettings settings, string password = null)
        {
            Configuration config = null;

            if (!loadedConfigs.ContainsKey(configName))
            {
                lock (loadedConfigs)
                {
                    if (!loadedConfigs.ContainsKey(configName))
                    {
                        config = loader.Load(configName, configUri, configType, version, settings, password);
                        ConfigLoaded(config);
                    }
                }
            }
            config = loadedConfigs[configName];
            if (!config.Header.Version.Equals(version))
            {
                throw new ConfigurationException(String.Format("Versions not compatible. [expected=%s][actual=%s]",
                                                               version.ToString(), config.Header.Version.ToString()));
            }
            return(config);
        }
示例#2
0
        /// <summary>
        /// Load a configuration from local file.
        /// </summary>
        /// <param name="configName">Configuration name</param>
        /// <param name="configFile">Configuration File Path</param>
        /// <param name="version">Configuration Version (expected)</param>
        /// <param name="settings">Configuration Settings</param>
        /// <param name="password">Password (if required)</param>
        /// <returns>Loaded Configruation</returns>
        public Configuration Load(string configName, string configFile,
                                  Version version, ConfigurationSettings settings,
                                  string password = null)
        {
            Preconditions.CheckArgument(configName);
            Preconditions.CheckArgument(configFile);
            Preconditions.CheckArgument(version);

            LogUtils.Info(String.Format("Loading Configuration. [name={0}][version={1}][file={2}]", configName, version.ToString(), configFile));

            using (FileReader reader = new FileReader(configFile))
            {
                AbstractConfigParser parser = ConfigProviderFactory.GetParser(configFile);
                Postconditions.CheckCondition(parser);

                parser.Parse(configName, reader, version, settings, password);

                return(parser.GetConfiguration());
            }
        }