// Token: 0x06006EAB RID: 28331 RVA: 0x001FC55C File Offset: 0x001FA75C private static void CreateMissingBamlTreeNode(BamlLocalizationDictionary dictionary, BamlTreeUpdater.BamlTreeUpdateMap treeMap) { BamlLocalizationDictionaryEnumerator enumerator = dictionary.GetEnumerator(); while (enumerator.MoveNext()) { BamlLocalizableResourceKey key = enumerator.Key; BamlLocalizableResource value = enumerator.Value; if (treeMap.MapKeyToBamlTreeNode(key) == null) { if (key.PropertyName == "$Content") { if (treeMap.MapUidToBamlTreeElementNode(key.Uid) == null) { BamlStartElementNode bamlStartElementNode = new BamlStartElementNode(treeMap.Resolver.ResolveAssemblyFromClass(key.ClassName), key.ClassName, false, false); bamlStartElementNode.AddChild(new BamlDefAttributeNode("Uid", key.Uid)); BamlTreeUpdater.TryAddContentPropertyToNewElement(treeMap, bamlStartElementNode); bamlStartElementNode.AddChild(new BamlEndElementNode()); treeMap.AddBamlTreeNode(key.Uid, key, bamlStartElementNode); } } else { BamlTreeNode node; if (key.PropertyName == "$LiteralContent") { node = new BamlLiteralContentNode(value.Content); } else { node = new BamlPropertyNode(treeMap.Resolver.ResolveAssemblyFromClass(key.ClassName), key.ClassName, key.PropertyName, value.Content, BamlAttributeUsage.Default); } treeMap.AddBamlTreeNode(null, key, node); } } } }
// Token: 0x06006EB0 RID: 28336 RVA: 0x001FCA0C File Offset: 0x001FAC0C private static IList <BamlTreeNode> SplitXmlContent(BamlLocalizableResourceKey key, string content, BamlTreeUpdater.BamlTreeUpdateMap bamlTreeMap) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<ROOT>"); stringBuilder.Append(content); stringBuilder.Append("</ROOT>"); IList <BamlTreeNode> list = new List <BamlTreeNode>(4); XmlDocument xmlDocument = new XmlDocument(); bool flag = true; try { xmlDocument.LoadXml(stringBuilder.ToString()); XmlElement xmlElement = xmlDocument.FirstChild as XmlElement; if (xmlElement != null && xmlElement.HasChildNodes) { int num = 0; while (num < xmlElement.ChildNodes.Count && flag) { flag = BamlTreeUpdater.GetBamlTreeNodeFromXmlNode(key, xmlElement.ChildNodes[num], bamlTreeMap, list); num++; } } } catch (XmlException) { bamlTreeMap.Resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(key, BamlLocalizerError.SubstitutionAsPlaintext)); flag = BamlTreeUpdater.GetBamlTreeNodeFromText(key, content, bamlTreeMap, list); } if (!flag) { return(null); } return(list); }
// 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); } }
// Token: 0x06006EAC RID: 28332 RVA: 0x001FC674 File Offset: 0x001FA874 private static bool ApplyChangeToBamlTree(BamlLocalizableResourceKey key, BamlLocalizableResource resource, BamlTreeUpdater.BamlTreeUpdateMap treeMap) { if (resource == null || resource.Content == null || !resource.Modifiable) { return(true); } if (!treeMap.LocalizationDictionary.Contains(key) && !treeMap.IsNewBamlTreeNode(key)) { return(true); } BamlTreeNode bamlTreeNode = treeMap.MapKeyToBamlTreeNode(key); Invariant.Assert(bamlTreeNode != null); BamlNodeType nodeType = bamlTreeNode.NodeType; if (nodeType != BamlNodeType.StartElement) { if (nodeType != BamlNodeType.Property) { if (nodeType == BamlNodeType.LiteralContent) { BamlLiteralContentNode bamlLiteralContentNode = (BamlLiteralContentNode)bamlTreeNode; bamlLiteralContentNode.Content = BamlResourceContentUtil.UnescapeString(resource.Content); if (bamlLiteralContentNode.Parent == null) { BamlTreeNode bamlTreeNode2 = treeMap.MapUidToBamlTreeElementNode(key.Uid); if (bamlTreeNode2 == null) { return(false); } bamlTreeNode2.AddChild(bamlLiteralContentNode); } } } else { BamlPropertyNode bamlPropertyNode = (BamlPropertyNode)bamlTreeNode; bamlPropertyNode.Value = BamlResourceContentUtil.UnescapeString(resource.Content); if (bamlPropertyNode.Parent == null) { BamlStartElementNode bamlStartElementNode = treeMap.MapUidToBamlTreeElementNode(key.Uid); if (bamlStartElementNode == null) { return(false); } bamlStartElementNode.InsertProperty(bamlTreeNode); } } } else { string b = null; if (treeMap.LocalizationDictionary.Contains(key)) { b = treeMap.LocalizationDictionary[key].Content; } if (resource.Content != b) { BamlTreeUpdater.ReArrangeChildren(key, bamlTreeNode, resource.Content, treeMap); } } return(true); }
// Token: 0x06006EB1 RID: 28337 RVA: 0x001FCAE4 File Offset: 0x001FACE4 private static bool GetBamlTreeNodeFromXmlNode(BamlLocalizableResourceKey key, XmlNode node, BamlTreeUpdater.BamlTreeUpdateMap bamlTreeMap, IList <BamlTreeNode> newChildrenList) { if (node.NodeType == XmlNodeType.Text) { return(BamlTreeUpdater.GetBamlTreeNodeFromText(key, node.Value, bamlTreeMap, newChildrenList)); } if (node.NodeType != XmlNodeType.Element) { return(true); } XmlElement xmlElement = node as XmlElement; string text = bamlTreeMap.Resolver.ResolveFormattingTagToClass(xmlElement.Name); bool flag = string.IsNullOrEmpty(text); string text2 = null; if (!flag) { text2 = bamlTreeMap.Resolver.ResolveAssemblyFromClass(text); flag = string.IsNullOrEmpty(text2); } if (flag) { bamlTreeMap.Resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(key, BamlLocalizerError.UnknownFormattingTag)); return(false); } string text3 = null; if (xmlElement.HasAttributes) { text3 = xmlElement.GetAttribute("Uid"); if (!string.IsNullOrEmpty(text3)) { text3 = BamlResourceContentUtil.UnescapeString(text3); } } BamlStartElementNode bamlStartElementNode = null; if (text3 != null) { bamlStartElementNode = bamlTreeMap.MapUidToBamlTreeElementNode(text3); } if (bamlStartElementNode == null) { bamlStartElementNode = new BamlStartElementNode(text2, text, false, false); if (text3 != null) { bamlTreeMap.AddBamlTreeNode(text3, new BamlLocalizableResourceKey(text3, text, "$Content", text2), bamlStartElementNode); bamlStartElementNode.AddChild(new BamlDefAttributeNode("Uid", text3)); } BamlTreeUpdater.TryAddContentPropertyToNewElement(bamlTreeMap, bamlStartElementNode); bamlStartElementNode.AddChild(new BamlEndElementNode()); } else if (bamlStartElementNode.TypeFullName != text) { bamlTreeMap.Resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(key, BamlLocalizerError.DuplicateUid)); return(false); } newChildrenList.Add(bamlStartElementNode); bool flag2 = true; if (xmlElement.HasChildNodes) { IList <BamlTreeNode> list = new List <BamlTreeNode>(); int num = 0; while (num < xmlElement.ChildNodes.Count && flag2) { flag2 = BamlTreeUpdater.GetBamlTreeNodeFromXmlNode(key, xmlElement.ChildNodes[num], bamlTreeMap, list); num++; } if (flag2) { BamlTreeUpdater.MergeChildrenList(key, bamlTreeMap, bamlStartElementNode, list); } } return(flag2); }
// Token: 0x06006EAE RID: 28334 RVA: 0x001FC7C0 File Offset: 0x001FA9C0 private static void MergeChildrenList(BamlLocalizableResourceKey key, BamlTreeUpdater.BamlTreeUpdateMap treeMap, BamlTreeNode parent, IList <BamlTreeNode> newChildren) { if (newChildren == null) { return; } List <BamlTreeNode> children = parent.Children; int i = 0; StringBuilder stringBuilder = new StringBuilder(); if (children != null) { Hashtable hashtable = new Hashtable(newChildren.Count); foreach (BamlTreeNode bamlTreeNode in newChildren) { if (bamlTreeNode.NodeType == BamlNodeType.StartElement) { BamlStartElementNode bamlStartElementNode = (BamlStartElementNode)bamlTreeNode; if (bamlStartElementNode.Uid != null) { if (hashtable.ContainsKey(bamlStartElementNode.Uid)) { treeMap.Resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(key, BamlLocalizerError.DuplicateElement)); return; } hashtable[bamlStartElementNode.Uid] = null; } } } parent.Children = null; for (int j = 0; j < children.Count - 1; j++) { BamlTreeNode bamlTreeNode2 = children[j]; BamlNodeType nodeType = bamlTreeNode2.NodeType; if (nodeType != BamlNodeType.StartElement) { if (nodeType != BamlNodeType.Text) { parent.AddChild(bamlTreeNode2); } } else { BamlStartElementNode bamlStartElementNode2 = (BamlStartElementNode)bamlTreeNode2; if (bamlStartElementNode2.Uid != null) { if (!hashtable.ContainsKey(bamlStartElementNode2.Uid)) { parent.Children = children; treeMap.Resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(key, BamlLocalizerError.MismatchedElements)); return; } hashtable.Remove(bamlStartElementNode2.Uid); } while (i < newChildren.Count) { BamlTreeNode bamlTreeNode3 = newChildren[i++]; Invariant.Assert(bamlTreeNode3 != null); if (bamlTreeNode3.NodeType == BamlNodeType.Text) { stringBuilder.Append(((BamlTextNode)bamlTreeNode3).Content); } else { BamlTreeUpdater.TryFlushTextToBamlNode(parent, stringBuilder); parent.AddChild(bamlTreeNode3); if (bamlTreeNode3.NodeType == BamlNodeType.StartElement) { break; } } } } } } while (i < newChildren.Count) { BamlTreeNode bamlTreeNode4 = newChildren[i]; Invariant.Assert(bamlTreeNode4 != null); if (bamlTreeNode4.NodeType == BamlNodeType.Text) { stringBuilder.Append(((BamlTextNode)bamlTreeNode4).Content); } else { BamlTreeUpdater.TryFlushTextToBamlNode(parent, stringBuilder); parent.AddChild(bamlTreeNode4); } i++; } BamlTreeUpdater.TryFlushTextToBamlNode(parent, stringBuilder); parent.AddChild(new BamlEndElementNode()); }
// Token: 0x06006EAD RID: 28333 RVA: 0x001FC7A0 File Offset: 0x001FA9A0 private static void ReArrangeChildren(BamlLocalizableResourceKey key, BamlTreeNode node, string translation, BamlTreeUpdater.BamlTreeUpdateMap treeMap) { IList <BamlTreeNode> newChildren = BamlTreeUpdater.SplitXmlContent(key, translation, treeMap); BamlTreeUpdater.MergeChildrenList(key, treeMap, node, newChildren); }