public void AddMergedDictionaries( BamlDocument document, IEnumerable <string> importedFiles) { BamlRecord mergedDictionaryRecord = document.FirstOrDefault(IsMergedDictionaryAttribute); if (mergedDictionaryRecord != null) { HandleMergedDictionary(document, importedFiles, mergedDictionaryRecord as AttributeInfoRecord); } else { if (document.FindIndex(IsResourceDictionaryElementStart) == -1) { //TODO: throw? (Let's hope people read the logs ^_^) _logger.Error(string.Format( "Existing 'Themes/generic.xaml' in {0} is *not* a ResourceDictionary. " + "This will prevent proper WPF application merging.", _mainAssemblyName)); return; } int attributeInfosStartIndex = document.FindLastIndex(r => r is AssemblyInfoRecord); if (attributeInfosStartIndex == -1) { _logger.Error("Invalid BAML detected. (no AssemblyInfoRecord)"); return; } var extraAttributes = GetMergedDictionariesAttributes().ToList(); AdjustAttributeIds(document, (ushort)extraAttributes.Count); document.InsertRange(attributeInfosStartIndex + 1, extraAttributes); int defferableRecordIndex = document.FindIndex(r => r is DeferableContentStartRecord); if (attributeInfosStartIndex == -1) { _logger.Error("Invalid BAML detected. (No DeferableContentStartRecord)"); } document.InsertRange(defferableRecordIndex, GetDictionariesList(importedFiles)); } }
private void HandleMergedDictionary( BamlDocument document, IEnumerable <string> importedFiles, AttributeInfoRecord mergedDictionariesRecord) { int indexStart = document.FindIndex( r => r is PropertyListStartRecord && ((PropertyListStartRecord)r).AttributeId == mergedDictionariesRecord.AttributeId); int insertIndex = indexStart + 1; if (document[insertIndex] is LineNumberAndPositionRecord) { insertIndex++; } List <string> existingUris = document.Skip(indexStart) .TakeWhile(r => !(r is PropertyListEndRecord)) .OfType <PropertyWithConverterRecord>() .Select(GetFileNameFromPropertyRecord) .ToList(); document.InsertRange(insertIndex, GetImportRecords(importedFiles.Except(existingUris))); }
public void AddMergedDictionaries( BamlDocument document, IEnumerable<string> importedFiles) { BamlRecord mergedDictionaryRecord = document.FirstOrDefault(IsMergedDictionaryAttribute); if (mergedDictionaryRecord != null) { HandleMergedDictionary(document, importedFiles, mergedDictionaryRecord as AttributeInfoRecord); } else { if (document.FindIndex(IsResourceDictionaryElementStart) == -1) { //TODO: throw? (Let's hope people read the logs ^_^) _logger.Error(string.Format( "Existing 'Themes/generic.xaml' in {0} is *not* a ResourceDictionary. " + "This will prevent proper WPF application merging.", _mainAssemblyName)); return; } int attributeInfosStartIndex = document.FindLastIndex(r => r is AssemblyInfoRecord); if (attributeInfosStartIndex == -1) { _logger.Error("Invalid BAML detected. (no AssemblyInfoRecord)"); return; } var extraAttributes = GetMergedDictionariesAttributes().ToList(); AdjustAttributeIds(document, (ushort)extraAttributes.Count); document.InsertRange(attributeInfosStartIndex + 1, extraAttributes); int defferableRecordIndex = document.FindIndex(r => r is DeferableContentStartRecord); if (attributeInfosStartIndex == -1) { _logger.Error("Invalid BAML detected. (No DeferableContentStartRecord)"); } document.InsertRange(defferableRecordIndex, GetDictionariesList(importedFiles)); } }
private void HandleMergedDictionary( BamlDocument document, IEnumerable<string> importedFiles, AttributeInfoRecord mergedDictionariesRecord) { int indexStart = document.FindIndex( r => r is PropertyListStartRecord && ((PropertyListStartRecord)r).AttributeId == mergedDictionariesRecord.AttributeId); int insertIndex = indexStart + 1; if (document[insertIndex] is LineNumberAndPositionRecord) insertIndex++; List<string> existingUris = document.Skip(indexStart) .TakeWhile(r => !(r is PropertyListEndRecord)) .OfType<PropertyWithConverterRecord>() .Select(GetFileNameFromPropertyRecord) .ToList(); document.InsertRange(insertIndex, GetImportRecords(importedFiles.Except(existingUris))); }