Beispiel #1
0
        /// <summary>
        /// Initialize this client environment from the specified configuration file and version
        /// using the configuration parser.
        /// </summary>
        /// <param name="parser">Configuration parser to use.</param>
        /// <param name="configfile">Configuration file path.</param>
        /// <param name="version">Configuration version (expected)</param>
        /// <param name="password">Password, if configuration has encrypted nodes.</param>
        protected void Init(AbstractConfigParser parser, string configfile,
                            Version version, string password = null)
        {
            try
            {
                LogUtils.Info(String.Format(
                                  "Initializing Client Environment : With Configuration file [{0}]...",
                                  configfile));
                Uri            path   = new Uri(NetUtils.FilePathToFileUrl(configfile));
                AbstractReader reader = ConfigProviderFactory.GetReader(path);
                if (reader == null)
                {
                    throw new ConfigurationException(String.Format("Failed to get reader. [URI={0}]", path.ToString()));
                }
                parser.Parse(ConfigName, reader,
                             version,
                             null, password);
                __configuration = parser.GetConfiguration();
                if (__configuration == null)
                {
                    throw new ConfigurationException(String.Format(
                                                         "Error parsing configuration : NULL configuration read. [file={0}]",
                                                         configfile));
                }

                PostInit();

                UpdateState(EEnvState.Initialized);
            }
            catch (Exception e)
            {
                throw new ConfigurationException(e);
            }
        }
Beispiel #2
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)
        {
            Preconditions.CheckArgument(configName);
            Preconditions.CheckArgument(configUri);
            Preconditions.CheckArgument(configType);
            Preconditions.CheckArgument(version);

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

            Uri uri = new Uri(configUri);

            using (AbstractReader reader = ConfigProviderFactory.GetReader(uri))
            {
                AbstractConfigParser parser = ConfigProviderFactory.GetParser(configType);
                Postconditions.CheckCondition(parser);

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

                return(parser.GetConfiguration());
            }
        }