private void PostLoad(ConfigMapping parent, string file, IEnumerable <VariableMapping> variables) { FilePath = file; Parent = parent; Variables.Add(new VariableMapping("CONFIG_PATH", Path.GetDirectoryName(AbsoluteFilePath))); Variables.AddRange(variables); // Load all dependencies foreach (string dependFile in Files) { string dependFilePath = dependFile; if (!Path.IsPathRooted(dependFilePath)) { dependFilePath = Path.Combine(Path.GetDirectoryName(AbsoluteFilePath), dependFilePath); } ConfigMapping subMapping = Load(this, dependFilePath, variables); if (subMapping != null) { subMapping.FilePath = dependFile; References.Add(subMapping); } } // Clear all depends file Files.Clear(); // Add this mapping file GetRoot().IdToConfigMapping.Add(Id, this); }
/// <summary> /// Loads a specified config file. /// </summary> public static ConfigMapping Load(string file, params VariableMapping[] variables) { ConfigMapping root = Load(null, file, variables); root.Verify(); return(root); }
/// <summary> /// Get the root mapping config. /// </summary> /// <returns></returns> public ConfigMapping GetRoot() { ConfigMapping root = this; while (root.Parent != null) { root = root.Parent; } return(root); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> public bool Equals(ConfigMapping other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.Id, Id)); }
/// <summary> /// Loads the specified config file attached to a parent config file. /// </summary> private static ConfigMapping Load(ConfigMapping parent, string file, IEnumerable <VariableMapping> variables) { var deserializer = new XmlSerializer(typeof(ConfigMapping)); ConfigMapping config = null; try { config = (ConfigMapping)deserializer.Deserialize(new StringReader(File.ReadAllText(file))); if (config != null) { config.PostLoad(parent, file, variables); } } catch (Exception ex) { log.Error("Unable to parse " + file, ex); } return(config); }