示例#1
0
 public static ConfigFile Load(ConfigFile root, string[] macros, Logger logger, params KeyValue[] variables)
 {
     root.PostLoad(null, null, macros, variables, logger);
     root.Verify(logger);
     root.ExpandVariables(false, logger);
     return(root);
 }
示例#2
0
        /// <summary>
        /// Loads the specified config file attached to a parent config file.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="file">The file.</param>
        /// <returns>The loaded config</returns>
        private static ConfigFile Load(ConfigFile parent, string file, string[] macros, IEnumerable <KeyValue> variables)
        {
            var        deserializer = new XmlSerializer(typeof(ConfigFile));
            ConfigFile config       = null;

            try
            {
                Logger.PushLocation(file);
                config = (ConfigFile)deserializer.Deserialize(new StringReader(Preprocessor.Preprocess(File.ReadAllText(file), macros)));

                if (config != null)
                {
                    config.PostLoad(parent, file, macros, variables);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Unable to parse file [{0}]", ex, file);
            }
            finally
            {
                Logger.PopLocation();
            }
            return(config);
        }
示例#3
0
        /// <summary>
        /// Loads the specified config file attached to a parent config file.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="file">The file.</param>
        /// <returns>The loaded config</returns>
        private static ConfigFile Load(ConfigFile parent, string file, string[] macros, IEnumerable <KeyValue> variables, Logger logger)
        {
            if (!File.Exists(file))
            {
                logger.Error(LoggingCodes.ConfigNotFound, "Configuration file {0} not found.", file);
                return(null);
            }

            var        deserializer = new XmlSerializer(typeof(ConfigFile));
            ConfigFile config       = null;

            try
            {
                logger.PushLocation(file);

                config = (ConfigFile)deserializer.Deserialize(new StringReader(Preprocessor.Preprocess(File.ReadAllText(file), macros)));

                if (config != null)
                {
                    config.PostLoad(parent, file, macros, variables, logger);
                }
            }
            catch (Exception ex)
            {
                logger.Error(LoggingCodes.UnableToParseConfig, "Unable to parse file [{0}]", ex, file);
            }
            finally
            {
                logger.PopLocation();
            }
            return(config);
        }