// Token: 0x06002507 RID: 9479 RVA: 0x000B2D74 File Offset: 0x000B0F74
        internal BamlLocalizationDictionary Copy()
        {
            BamlLocalizationDictionary bamlLocalizationDictionary = new BamlLocalizationDictionary();

            foreach (KeyValuePair <BamlLocalizableResourceKey, BamlLocalizableResource> keyValuePair in this._dictionary)
            {
                BamlLocalizableResource value = (keyValuePair.Value == null) ? null : new BamlLocalizableResource(keyValuePair.Value);
                bamlLocalizationDictionary.Add(keyValuePair.Key, value);
            }
            bamlLocalizationDictionary._rootElementKey = this._rootElementKey;
            return(bamlLocalizationDictionary);
        }
コード例 #2
0
        //------------------------------
        // internal functions
        //------------------------------
        internal BamlLocalizationDictionary Copy()
        {
            BamlLocalizationDictionary newDictionary = new BamlLocalizationDictionary();

            foreach (KeyValuePair <BamlLocalizableResourceKey, BamlLocalizableResource> pair in _dictionary)
            {
                BamlLocalizableResource resourceCopy =
                    pair.Value == null ?
                    null :
                    new BamlLocalizableResource(pair.Value);

                newDictionary.Add(pair.Key, resourceCopy);
            }

            newDictionary._rootElementKey = _rootElementKey;

            // return the new dictionary
            return(newDictionary);
        }
コード例 #3
0
        private static void GenerateBamlStream(Stream input, Stream output, BamlLocalizationDictionary dictionary, LocBamlOptions options)
        {
            string commentFile = Path.ChangeExtension(options.Input, "loc");
            TextReader commentStream = null;

            try
            {
                if (File.Exists(commentFile))
                {
                    commentStream = new StreamReader(commentFile);
                }

                // create a localizabilty resolver based on reflection
                BamlLocalizabilityByReflection localizabilityReflector =
                    new BamlLocalizabilityByReflection(options.Assemblies);

                // create baml localizer
                BamlLocalizer mgr = new BamlLocalizer(
                    input,
                    localizabilityReflector,
                    commentStream
                    );

                // get the resources
                BamlLocalizationDictionary source = mgr.ExtractResources();
                BamlLocalizationDictionary translations = new BamlLocalizationDictionary();

                foreach (DictionaryEntry entry in dictionary)
                {
                    BamlLocalizableResourceKey key = (BamlLocalizableResourceKey) entry.Key;
                    // filter out unchanged items
                    if (!source.Contains(key)
                      || entry.Value == null
                      || source[key].Content != ((BamlLocalizableResource)entry.Value).Content)
                    {
                        translations.Add(key, (BamlLocalizableResource)entry.Value);
                    }
                }

                // update baml
                mgr.UpdateBaml(output, translations);
            }
            finally
            {
                if (commentStream != null)
                {
                    commentStream.Close();
                }
            }
        }
コード例 #4
0
        //--------------------------------------
        // Private methods
        //--------------------------------------
        // construct the maps for enumeration
        internal void EnsureMap() 
        {                        
            if (_localizableResources != null) 
                return; // map is already created.
                
            // create the table based on the treesize passed in
            // the hashtable is for look-up during update
            _resolver.InitLocalizabilityCache();            
            _keyToBamlNodeIndexMap = new Hashtable(_tree.Size);
            _uidToBamlNodeIndexMap = new Hashtable(_tree.Size / 2);            
            _localizableResources  = new BamlLocalizationDictionary();
            
            for (int i = 0; i < _tree.Size; i++)
            {
                BamlTreeNode currentNode = _tree[i];

                // a node may be marked as unidentifiable if it or its parent has a duplicate uid. 
                if (currentNode.Unidentifiable) continue; // skip unidentifiable nodes

                if (currentNode.NodeType == BamlNodeType.StartElement)
                {
                    // remember classes encountered in this baml
                    BamlStartElementNode elementNode = (BamlStartElementNode) currentNode;
                    _resolver.AddClassAndAssembly(elementNode.TypeFullName, elementNode.AssemblyName);
                }

                // find the Uid of the current node
                BamlLocalizableResourceKey key = GetKey(currentNode);                    
                
                if (key != null)
                {    
                    if (currentNode.NodeType == BamlNodeType.StartElement)
                    {
                        // store uid mapping to the corresponding element node
                        if (_uidToBamlNodeIndexMap.ContainsKey(key.Uid))
                        {                        
                            _resolver.RaiseErrorNotifyEvent(
                                new BamlLocalizerErrorNotifyEventArgs(
                                    key, 
                                    BamlLocalizerError.DuplicateUid
                                    )
                            );           

                            // Mark this element and its properties unidentifiable. 
                            currentNode.Unidentifiable = true;
                            if (currentNode.Children != null)
                            {
                                foreach (BamlTreeNode child in currentNode.Children)
                                {
                                    if (child.NodeType != BamlNodeType.StartElement)
                                        child.Unidentifiable = true;
                                }
                            }
                            
                            continue; // skip the duplicate node                                
                        }
                        else
                        {
                            _uidToBamlNodeIndexMap.Add(key.Uid, i);
                        }   
                    }                   
                    
                    _keyToBamlNodeIndexMap.Add(key, i);                    

                    if (_localizableResources.RootElementKey == null
                     && currentNode.NodeType == BamlNodeType.StartElement
                     && currentNode.Parent != null
                     && currentNode.Parent.NodeType == BamlNodeType.StartDocument)
                    {                            
                        // remember the key to the root element so that 
                        // users can further add modifications to the root that would have a global impact.
                        // such as FlowDirection or CultureInfo
                        _localizableResources.SetRootElementKey(key);
                    }                    
                    
                    // create the resource and add to the dictionary
                    BamlLocalizableResource resource = _localizableResourceBuilder.BuildFromNode(key, currentNode);
                    
                    if (resource != null)
                    {  
                        _localizableResources.Add(key, resource);                        
                    }
                }
            }                        

            _resolver.ReleaseLocalizabilityCache();
        }    
コード例 #5
0
        //------------------------------
        // internal functions
        //------------------------------
        internal BamlLocalizationDictionary Copy()
        {
            BamlLocalizationDictionary newDictionary = new BamlLocalizationDictionary();
            foreach (KeyValuePair<BamlLocalizableResourceKey, BamlLocalizableResource> pair in _dictionary)
            {
                BamlLocalizableResource resourceCopy = 
                    pair.Value == null ?
                    null :
                    new BamlLocalizableResource(pair.Value);

                newDictionary.Add(pair.Key, resourceCopy);
            }            

            newDictionary._rootElementKey = _rootElementKey;

            // return the new dictionary
            return newDictionary;
        }