// 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;
 }
예제 #2
0
 // Token: 0x06006E1E RID: 28190 RVA: 0x001FB183 File Offset: 0x001F9383
 internal BamlTreeNode MapKeyToBamlTreeNode(BamlLocalizableResourceKey key, BamlTree tree)
 {
     if (this._keyToBamlNodeIndexMap.Contains(key))
     {
         return(tree[(int)this._keyToBamlNodeIndexMap[key]]);
     }
     return(null);
 }
예제 #3
0
 // Token: 0x06006E1F RID: 28191 RVA: 0x001FB1AC File Offset: 0x001F93AC
 internal BamlStartElementNode MapUidToBamlTreeElementNode(string uid, BamlTree tree)
 {
     if (this._uidToBamlNodeIndexMap.Contains(uid))
     {
         return(tree[(int)this._uidToBamlNodeIndexMap[uid]] as BamlStartElementNode);
     }
     return(null);
 }
        //-----------------------------
        // 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
                    );
            }
        }
예제 #5
0
        //-----------------------------
        // 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
                    ); 
            }
        } 
예제 #6
0
        // create a deep copy of the tree
        internal BamlTree Copy()
        {
            // create new root and new list
            BamlTreeNode newTreeRoot = _root;
            List<BamlTreeNode> newNodeList = new List<BamlTreeNode>(Size);

            // create a new copy of the tree.
            CreateInternalIndex(ref newTreeRoot, ref newNodeList, true);

            BamlTree newTree  = new BamlTree();
            newTree._root     = newTreeRoot;
            newTree._nodeList = newNodeList;
            
            return newTree;
        }
        // create a deep copy of the tree
        internal BamlTree Copy()
        {
            // create new root and new list
            BamlTreeNode        newTreeRoot = _root;
            List <BamlTreeNode> newNodeList = new List <BamlTreeNode>(Size);

            // create a new copy of the tree.
            CreateInternalIndex(ref newTreeRoot, ref newNodeList, true);

            BamlTree newTree = new BamlTree();

            newTree._root     = newTreeRoot;
            newTree._nodeList = newNodeList;

            return(newTree);
        }
        //----------------------------------
        // 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.            
        }
예제 #9
0
        //----------------------------------
        // internal Constructor
        //----------------------------------

        /// <summary>
        /// BamlTreeMap.
        /// </summary>
        internal BamlTreeMap(
            BamlLocalizer localizer,
            BamlTree tree,
            BamlLocalizabilityResolver resolver,
            TextReader comments
            )
        {
            Debug.Assert(tree != null, "Baml Tree is empty");
            Debug.Assert(localizer != null, "BamlLocalizer is null");

            _tree = tree;

            // creates an internal resolver which willd delegate calls to client's resolver intelligently.
            _resolver = new InternalBamlLocalizabilityResolver(localizer, resolver, comments);

            // create a LocalizableResourceBuilder to build localizable resources
            _localizableResourceBuilder = new LocalizableResourceBuilder(_resolver);
        }
예제 #10
0
        //----------------------------------
        // internal Constructor
        //----------------------------------

        /// <summary>
        /// BamlTreeMap.
        /// </summary>
        internal BamlTreeMap(
            BamlLocalizer               localizer,
            BamlTree                    tree, 
            BamlLocalizabilityResolver  resolver,
            TextReader                  comments
            )
        {
            Debug.Assert(tree!= null, "Baml Tree is empty");
            Debug.Assert(localizer!= null, "BamlLocalizer is null");            

            _tree = tree;
            
            // creates an internal resolver which willd delegate calls to client's resolver intelligently.
            _resolver = new InternalBamlLocalizabilityResolver(localizer, resolver, comments);

            // create a LocalizableResourceBuilder to build localizable resources
            _localizableResourceBuilder = new LocalizableResourceBuilder(_resolver);
        }        
예제 #11
0
        //----------------------------------
        // 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.
        }
        // 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);
            }
        }
예제 #13
0
 // 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));
             }
         }
     }
 }
 //-------------------------------
 // Internal static
 //-------------------------------
 internal static void Serialize(BamlLocalizer localizer, BamlTree tree, Stream output)
 {
     // Thread safe implementation
     (new BamlResourceSerializer()).SerializeImp(localizer, tree, output);
 }
예제 #15
0
 //-------------------------------
 // Internal static
 //-------------------------------
 internal static void Serialize(BamlLocalizer localizer, BamlTree tree, Stream output)
 {
     // Thread safe implementation
     (new BamlResourceSerializer()).SerializeImp(localizer, tree, output);
 }
예제 #16
0
 // Token: 0x06006E17 RID: 28183 RVA: 0x001FB05E File Offset: 0x001F925E
 internal static void Serialize(BamlLocalizer localizer, BamlTree tree, Stream output)
 {
     new BamlResourceSerializer().SerializeImp(localizer, tree, output);
 }
예제 #17
0
        /// <summary>
        /// Maps a uid to a baml tree node in the given tree
        /// </summary>        
        internal BamlStartElementNode MapUidToBamlTreeElementNode(string uid, BamlTree tree)
        {
            if (_uidToBamlNodeIndexMap.Contains(uid))
            {
                return tree[(int)_uidToBamlNodeIndexMap[uid]] as BamlStartElementNode;
            }

            return null;
        }
예제 #18
0
 /// <summary>
 /// Maps a key to a baml tree node in the given tree
 /// </summary>        
 internal BamlTreeNode MapKeyToBamlTreeNode(BamlLocalizableResourceKey key, BamlTree tree)
 {
     if (_keyToBamlNodeIndexMap.Contains(key))
     {
         return tree[(int)_keyToBamlNodeIndexMap[key]];
     }
     
     return null;
 }
예제 #19
0
 internal BamlTreeUpdateMap(BamlTreeMap map, BamlTree tree)
 { 
     _uidToNewBamlNodeIndexMap = new Hashtable(8); 
     _keyToNewBamlNodeIndexMap = new Hashtable(8);
     _originalMap              = map; 
     _tree                     = tree;
 }
예제 #20
0
 // Token: 0x06006E1B RID: 28187 RVA: 0x001FB13E File Offset: 0x001F933E
 internal BamlTreeMap(BamlLocalizer localizer, BamlTree tree, BamlLocalizabilityResolver resolver, TextReader comments)
 {
     this._tree     = tree;
     this._resolver = new InternalBamlLocalizabilityResolver(localizer, resolver, comments);
     this._localizableResourceBuilder = new LocalizableResourceBuilder(this._resolver);
 }