private void ProcessMergedDictionariesElement(XamlFile xamlFile, XElement list, string indent) { int nMergedDictionary = 0; var children = list.Elements().ToArray(); foreach (var child in children) { ++nMergedDictionary; _log.Write(indent + nMergedDictionary + ": "); var source = child.Attribute("Source")?.Value.Trim(); if (source == null) { MergeCustomDictionary(child); } else { _log.Write("'" + source + "' => "); var sourceUri = new SourceUri(source); if (!IsKnownAssembly(sourceUri.Assembly)) { _log.WriteLine("UNKNOWN PATH"); Error(indent, $"Assembly {sourceUri.Assembly} is not listed. Please specify its path in the assembly list or add line {sourceUri.Assembly}=@xternal"); continue; } MergeDictionary(xamlFile, child, sourceUri, indent); } child.Remove(); } }
private void MergeDictionary(XamlFile parentXaml, XNode mdElement, SourceUri source, string indent) { if (_assemblyList.IsExternal(source.Assembly)) { // external assembly; add this merged dictionary to the md list of the root file _log.WriteLine("external dictionary"); if (IsAlreadyMerged(source.Uri, indent)) { return; } _mdInserter.Insert(mdElement); } else { // known assembly; read XAML file and copy its contents to the root resource dictionary var path = Path.GetFullPath(GetPathFromSourceUri(parentXaml.Path, source)); _log.WriteLine(path); if (IsAlreadyMerged(path, indent)) { return; } var assembly = source.Assembly ?? parentXaml.Assembly; var mergedXaml = new XamlFile(_fs, assembly).Read(path); MergeXamlFile(mergedXaml, indent + " "); } }
public XamlMerger(Options options, AssemblyList assemblyList, TextWriter log, IFileSystem fs) { _assemblyList = assemblyList; _options = options; _log = log; _fs = fs; _xaml = new XamlFile(fs).Read(options.XamlPath); }
private void MergeXamlFile(XamlFile mergedXaml, string indent) { _log.WriteLine(indent + mergedXaml.Path); try { var documentRoot = mergedXaml.Xml.Root; if (documentRoot == null) { Warning(indent, "No root element"); return; } if (documentRoot.Name != ResourceDictionaryName) { Error(indent, $"Root element is not resource dictionarty: <{documentRoot.Name.LocalName}>"); return; } var firstChild = documentRoot.Elements().FirstOrDefault(); if (firstChild == null) { Warning(indent, "No child elements. Empty dictionary?"); return; } _nsManager.CopyNamespaces(mergedXaml); XNode toMerge = firstChild; if (firstChild.Name == MergedDictionariesName) { ProcessMergedDictionariesElement(mergedXaml, firstChild, indent + " "); // recursive call toMerge = firstChild.NextNode; } // merge content of the file into the root file if (toMerge != null) { _resourceInserter.Insert(new XComment(" Merged from " + mergedXaml.Path + " ")); while (toMerge != null) { _resourceInserter.Insert(toMerge); toMerge = toMerge.NextNode; } _resourceInserter.Insert(new XComment(" End merged from " + mergedXaml.Path + " ")); } } catch (NamespaceManager.ClashException ex) { Error(indent, ex.Message); } }
public void CopyNamespaces(XamlFile xaml) { LoadNamespaces(xaml.Xml.Root, xaml.Assembly, xaml.Path, true); }