public static XmlCoalesceDocument Load(string path) { if (path.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(path)); } var sourcePath = Path.GetFullPath(path); if (!File.Exists(sourcePath)) { Console.WriteLine($"Warning: {path} not found!"); return(null); } var doc = XDocument.Load(path); var root = doc.Root; if (root == null) { return(null); } var id = (string)root.Attribute("id"); var name = (string)root.Attribute("name"); var source = (string)root.Attribute("source"); var result = new XmlCoalesceDocument(name) { BaseUri = doc.BaseUri.IsNullOrWhiteSpace() ? doc.BaseUri : new Uri(sourcePath).AbsoluteUri, Id = id, Source = source, SourcePath = sourcePath, SourceDirectory = Path.GetDirectoryName(sourcePath) }; // Read includes before the sections //result.ReadIncludes(root); result.ReadSections(root); return(result); }
public void ReadAssets(XElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } var assetsElement = element.Element("Assets"); if (assetsElement == null) { return; } var assets = from el in assetsElement.Elements("Asset") select el; var includes = new List <XmlCoalesceInclude>(); foreach (var asset in assets) { var source = (string)asset.Attribute("source"); if (source.IsNullOrEmpty()) { continue; } var sourcePath = Path.Combine(SourceDirectory, source); sourcePath = Path.GetFullPath(sourcePath); includes.Add(new XmlCoalesceInclude(sourcePath)); } foreach (var include in includes) { var asset = XmlCoalesceDocument.Load(include.Source); if (asset != null && !asset.Source.IsNullOrEmpty()) { Documents.Add(asset); } } }