// Token: 0x06008D3F RID: 36159 RVA: 0x00258F8A File Offset: 0x0025718A internal BamlTreeUpdateMap(BamlTreeMap map, BamlTree tree) { this._uidToNewBamlNodeIndexMap = new Hashtable(8); this._keyToNewBamlNodeIndexMap = new Hashtable(8); this._originalMap = map; this._tree = tree; }
//----------------------------- // internal methods //----------------------------- internal static void UpdateTree( BamlTree tree, BamlTreeMap treeMap, BamlLocalizationDictionary dictionary ) { Debug.Assert(tree != null && tree.Root != null, "Empty Tree!"); Debug.Assert(treeMap != null, "Empty map!"); Debug.Assert(dictionary != null, "Empty dictionary"); // no changes to do to the tree. if (dictionary.Count <= 0) { return; } // create a tree map to be used for update BamlTreeUpdateMap updateMap = new BamlTreeUpdateMap(treeMap, tree); // // a) Create baml tree nodes for missing child place holders and properties. // Translations may require new nodes to be constructed. For example // translation contains new child place holders // CreateMissingBamlTreeNode(dictionary, updateMap); // // b) Look through each translation and make modification to the tree // At this step, new nodes are linked to the tree if applicable. // BamlLocalizationDictionaryEnumerator enumerator = dictionary.GetEnumerator(); ArrayList deferredResources = new ArrayList(); while (enumerator.MoveNext()) { if (!ApplyChangeToBamlTree(enumerator.Key, enumerator.Value, updateMap)) { deferredResources.Add(enumerator.Entry); } } // // c) Hook up the property nodes that aren't hooked up yet // Formatting tags inserted in the translation will only be created the // previous step. Hook up properties to those nodes now if applicable // for (int i = 0; i < deferredResources.Count; i++) { DictionaryEntry entry = (DictionaryEntry)deferredResources[i]; ApplyChangeToBamlTree( (BamlLocalizableResourceKey)entry.Key, (BamlLocalizableResource)entry.Value, updateMap ); } }
//----------------------------- // internal methods //----------------------------- internal static void UpdateTree( BamlTree tree, BamlTreeMap treeMap, BamlLocalizationDictionary dictionary ) { Debug.Assert(tree != null && tree.Root != null, "Empty Tree!"); Debug.Assert(treeMap != null, "Empty map!"); Debug.Assert(dictionary != null, "Empty dictionary"); // no changes to do to the tree. if (dictionary.Count <= 0) return; // create a tree map to be used for update BamlTreeUpdateMap updateMap = new BamlTreeUpdateMap(treeMap, tree); // // a) Create baml tree nodes for missing child place holders and properties. // Translations may require new nodes to be constructed. For example // translation contains new child place holders // CreateMissingBamlTreeNode(dictionary, updateMap); // // b) Look through each translation and make modification to the tree // At this step, new nodes are linked to the tree if applicable. // BamlLocalizationDictionaryEnumerator enumerator = dictionary.GetEnumerator(); ArrayList deferredResources = new ArrayList(); while (enumerator.MoveNext()) { if (!ApplyChangeToBamlTree(enumerator.Key, enumerator.Value, updateMap)) { deferredResources.Add(enumerator.Entry); } } // // c) Hook up the property nodes that aren't hooked up yet // Formatting tags inserted in the translation will only be created the // previous step. Hook up properties to those nodes now if applicable // for(int i = 0; i < deferredResources.Count; i++) { DictionaryEntry entry = (DictionaryEntry) deferredResources[i]; ApplyChangeToBamlTree( (BamlLocalizableResourceKey) entry.Key, (BamlLocalizableResource) entry.Value, updateMap ); } }
// Token: 0x06006E31 RID: 28209 RVA: 0x001FBBD4 File Offset: 0x001F9DD4 private void SetLocalizationComments(BamlStartElementNode node, InternalBamlLocalizabilityResolver.ElementComments comments, string stringComment) { if (!string.IsNullOrEmpty(stringComment)) { try { comments.LocalizationComments = LocComments.ParsePropertyComments(stringComment); } catch (FormatException) { this.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(BamlTreeMap.GetKey(node), BamlLocalizerError.InvalidLocalizationComments)); } } }
/// <summary> /// constructor /// </summary> /// <param name="source">source baml straem to be localized</param> /// <param name="resolver">Localizability resolver implemented by client</param> /// <param name="comments">TextReader to read localization comments XML </param> public BamlLocalizer( Stream source, BamlLocalizabilityResolver resolver, TextReader comments ) { if (source == null) { throw new ArgumentNullException("source"); } _tree = BamlResourceDeserializer.LoadBaml(source); // create a Baml Localization Enumerator _bamlTreeMap = new BamlTreeMap(this, _tree, resolver, comments); }
//---------------------------------- // private method //---------------------------------- /// <summary> /// Serialize the tree out to the stream. /// </summary> private void SerializeImp( BamlLocalizer localizer, BamlTree tree, Stream output ) { Debug.Assert(output != null, "The output stream given is null"); Debug.Assert(tree != null && tree.Root != null, "The tree to be serialized is null."); _writer = new BamlWriter(output); _bamlTreeStack = new Stack <BamlTreeNode>(); // intialize the stack. _bamlTreeStack.Push(tree.Root); while (_bamlTreeStack.Count > 0) { BamlTreeNode currentNode = _bamlTreeStack.Pop(); if (!currentNode.Visited) { // Mark this node so that it won't be serialized again. currentNode.Visited = true; currentNode.Serialize(_writer); PushChildrenToStack(currentNode.Children); } else { BamlStartElementNode elementNode = currentNode as BamlStartElementNode; Debug.Assert(elementNode != null); if (elementNode != null) { localizer.RaiseErrorNotifyEvent( new BamlLocalizerErrorNotifyEventArgs( BamlTreeMap.GetKey(elementNode), BamlLocalizerError.DuplicateElement ) ); } } } // do not close stream as we don't own it. }
private void SetLocalizationAttributes( BamlStartElementNode node, ElementComments comments, string attributes ) { if (!string.IsNullOrEmpty(attributes)) { try { comments.LocalizationAttributes = LocComments.ParsePropertyLocalizabilityAttributes(attributes); } catch (FormatException) { RaiseErrorNotifyEvent( new BamlLocalizerErrorNotifyEventArgs( BamlTreeMap.GetKey(node), BamlLocalizerError.InvalidLocalizationAttributes ) ); } } }
// Token: 0x06006EAA RID: 28330 RVA: 0x001FC4B8 File Offset: 0x001FA6B8 internal static void UpdateTree(BamlTree tree, BamlTreeMap treeMap, BamlLocalizationDictionary dictionary) { if (dictionary.Count <= 0) { return; } BamlTreeUpdater.BamlTreeUpdateMap treeMap2 = new BamlTreeUpdater.BamlTreeUpdateMap(treeMap, tree); BamlTreeUpdater.CreateMissingBamlTreeNode(dictionary, treeMap2); BamlLocalizationDictionaryEnumerator enumerator = dictionary.GetEnumerator(); ArrayList arrayList = new ArrayList(); while (enumerator.MoveNext()) { if (!BamlTreeUpdater.ApplyChangeToBamlTree(enumerator.Key, enumerator.Value, treeMap2)) { arrayList.Add(enumerator.Entry); } } for (int i = 0; i < arrayList.Count; i++) { DictionaryEntry dictionaryEntry = (DictionaryEntry)arrayList[i]; BamlTreeUpdater.ApplyChangeToBamlTree((BamlLocalizableResourceKey)dictionaryEntry.Key, (BamlLocalizableResource)dictionaryEntry.Value, treeMap2); } }
internal BamlTreeUpdateMap(BamlTreeMap map, BamlTree tree) { _uidToNewBamlNodeIndexMap = new Hashtable(8); _keyToNewBamlNodeIndexMap = new Hashtable(8); _originalMap = map; _tree = tree; }
// Token: 0x06006E19 RID: 28185 RVA: 0x001FB070 File Offset: 0x001F9270 private void SerializeImp(BamlLocalizer localizer, BamlTree tree, Stream output) { this._writer = new BamlWriter(output); this._bamlTreeStack = new Stack <BamlTreeNode>(); this._bamlTreeStack.Push(tree.Root); while (this._bamlTreeStack.Count > 0) { BamlTreeNode bamlTreeNode = this._bamlTreeStack.Pop(); if (!bamlTreeNode.Visited) { bamlTreeNode.Visited = true; bamlTreeNode.Serialize(this._writer); this.PushChildrenToStack(bamlTreeNode.Children); } else { BamlStartElementNode bamlStartElementNode = bamlTreeNode as BamlStartElementNode; if (bamlStartElementNode != null) { localizer.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(BamlTreeMap.GetKey(bamlStartElementNode), BamlLocalizerError.DuplicateElement)); } } } }
// Token: 0x06006E20 RID: 28192 RVA: 0x001FB1DC File Offset: 0x001F93DC internal void EnsureMap() { if (this._localizableResources != null) { return; } this._resolver.InitLocalizabilityCache(); this._keyToBamlNodeIndexMap = new Hashtable(this._tree.Size); this._uidToBamlNodeIndexMap = new Hashtable(this._tree.Size / 2); this._localizableResources = new BamlLocalizationDictionary(); for (int i = 0; i < this._tree.Size; i++) { BamlTreeNode bamlTreeNode = this._tree[i]; if (!bamlTreeNode.Unidentifiable) { if (bamlTreeNode.NodeType == BamlNodeType.StartElement) { BamlStartElementNode bamlStartElementNode = (BamlStartElementNode)bamlTreeNode; this._resolver.AddClassAndAssembly(bamlStartElementNode.TypeFullName, bamlStartElementNode.AssemblyName); } BamlLocalizableResourceKey key = BamlTreeMap.GetKey(bamlTreeNode); if (key != null) { if (bamlTreeNode.NodeType == BamlNodeType.StartElement) { if (this._uidToBamlNodeIndexMap.ContainsKey(key.Uid)) { this._resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(key, BamlLocalizerError.DuplicateUid)); bamlTreeNode.Unidentifiable = true; if (bamlTreeNode.Children == null) { goto IL_1AB; } using (List <BamlTreeNode> .Enumerator enumerator = bamlTreeNode.Children.GetEnumerator()) { while (enumerator.MoveNext()) { BamlTreeNode bamlTreeNode2 = enumerator.Current; if (bamlTreeNode2.NodeType != BamlNodeType.StartElement) { bamlTreeNode2.Unidentifiable = true; } } goto IL_1AB; } } this._uidToBamlNodeIndexMap.Add(key.Uid, i); } this._keyToBamlNodeIndexMap.Add(key, i); if (this._localizableResources.RootElementKey == null && bamlTreeNode.NodeType == BamlNodeType.StartElement && bamlTreeNode.Parent != null && bamlTreeNode.Parent.NodeType == BamlNodeType.StartDocument) { this._localizableResources.SetRootElementKey(key); } BamlLocalizableResource bamlLocalizableResource = this._localizableResourceBuilder.BuildFromNode(key, bamlTreeNode); if (bamlLocalizableResource != null) { this._localizableResources.Add(key, bamlLocalizableResource); } } } IL_1AB :; } this._resolver.ReleaseLocalizabilityCache(); }