Ejemplo n.º 1
0
        internal string GetStringComment(
            BamlStartElementNode node,
            string localName
            )
        {
            // get all the comments declares on this node
            ElementComments comment = LookupCommentForElement(node);

            for (int i = 0; i < comment.LocalizationComments.Length; i++)
            {
                if (comment.LocalizationComments[i].PropertyName == localName)
                {
                    return((string)comment.LocalizationComments[i].Value);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        // Grab the comments on a BamlTreeNode for the value.
        internal LocalizabilityGroup GetLocalizabilityComment(
            BamlStartElementNode node,
            string localName
            )
        {
            // get all the comments declares on this node
            ElementComments comment = LookupCommentForElement(node);

            for (int i = 0; i < comment.LocalizationAttributes.Length; i++)
            {
                if (comment.LocalizationAttributes[i].PropertyName == localName)
                {
                    return((LocalizabilityGroup)comment.LocalizationAttributes[i].Value);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
 private void SetLocalizationComments(
     BamlStartElementNode node,
     ElementComments comments,
     string stringComment
     )
 {
     if (!string.IsNullOrEmpty(stringComment))
     {
         try {
             comments.LocalizationComments = LocComments.ParsePropertyComments(stringComment);
         }
         catch (FormatException)
         {
             RaiseErrorNotifyEvent(
                 new BamlLocalizerErrorNotifyEventArgs(
                     BamlTreeMap.GetKey(node),
                     BamlLocalizerError.InvalidLocalizationComments
                     )
                 );
         }
     }
 }
Ejemplo n.º 4
0
        private ElementComments LookupCommentForElement(BamlStartElementNode node)
        {
            Debug.Assert(node.NodeType == BamlNodeType.StartElement);

            if (node.Uid == null)
            {
                return(new ElementComments()); // return empty comments for null Uid
            }

            for (int i = 0; i < _comments.Length; i++)
            {
                if (_comments[i] != null && _comments[i].ElementId == node.Uid)
                {
                    return(_comments[i]);
                }
            }

            ElementComments comment = new ElementComments();

            comment.ElementId = node.Uid;

            if (_commentsDocument != null)
            {
                // select the xmlNode containing the comments
                XmlElement element = FindElementByID(_commentsDocument, node.Uid);

                if (element != null)
                {
                    // parse the comments
                    string locAttribute = element.GetAttribute(LocComments.LocLocalizabilityAttribute);
                    SetLocalizationAttributes(node, comment, locAttribute);

                    locAttribute = element.GetAttribute(LocComments.LocCommentsAttribute);
                    SetLocalizationComments(node, comment, locAttribute);
                }
            }

            if (node.Children != null)
            {
                //
                // The baml itself might contain comments too
                // Grab the missing comments from Baml if there is any.
                //

                for (int i = 0;
                     i < node.Children.Count && (comment.LocalizationComments.Length == 0 || comment.LocalizationAttributes.Length == 0);
                     i++)
                {
                    BamlTreeNode child = (BamlTreeNode)node.Children[i];
                    if (child.NodeType == BamlNodeType.Property)
                    {
                        BamlPropertyNode propertyNode = (BamlPropertyNode)child;

                        if (LocComments.IsLocCommentsProperty(propertyNode.OwnerTypeFullName, propertyNode.PropertyName) &&
                            comment.LocalizationComments.Length == 0)
                        {
                            // grab comments from Baml
                            SetLocalizationComments(node, comment, propertyNode.Value);
                        }
                        else if (LocComments.IsLocLocalizabilityProperty(propertyNode.OwnerTypeFullName, propertyNode.PropertyName) &&
                                 comment.LocalizationAttributes.Length == 0)
                        {
                            // grab comments from Baml
                            SetLocalizationAttributes(node, comment, propertyNode.Value);
                        }
                    }
                }
            }

            // cached it
            _comments[_commentsIndex] = comment;
            _commentsIndex            = (_commentsIndex + 1) % _comments.Length;

            return(comment);
        }
Ejemplo n.º 5
0
 private void SetLocalizationComments(            
     BamlStartElementNode node, 
     ElementComments      comments, 
     string               stringComment
     )
 {
     if (!string.IsNullOrEmpty(stringComment))
     {
         try {
             comments.LocalizationComments = LocComments.ParsePropertyComments(stringComment);
         }
         catch (FormatException)
         {
             RaiseErrorNotifyEvent(
                 new BamlLocalizerErrorNotifyEventArgs(
                     BamlTreeMap.GetKey(node),
                     BamlLocalizerError.InvalidLocalizationComments
                     )
                 );                   
         }
     }
 }
Ejemplo n.º 6
0
        private ElementComments LookupCommentForElement(BamlStartElementNode node)
        {
            Debug.Assert(node.NodeType == BamlNodeType.StartElement);

            if (node.Uid == null)
            {
                return new ElementComments(); // return empty comments for null Uid
            }
            
            for (int i = 0; i < _comments.Length; i++)
            {
                if (_comments[i] != null && _comments[i].ElementId == node.Uid)                    
                {
                   return _comments[i];
                }
            }

            ElementComments comment = new ElementComments();
            comment.ElementId       = node.Uid;

            if (_commentsDocument != null)
            {
                // select the xmlNode containing the comments
                XmlElement element = FindElementByID(_commentsDocument, node.Uid);

                if (element != null)
                {
                    // parse the comments
                    string locAttribute = element.GetAttribute(LocComments.LocLocalizabilityAttribute);
                    SetLocalizationAttributes(node, comment, locAttribute);

                    locAttribute = element.GetAttribute(LocComments.LocCommentsAttribute);
                    SetLocalizationComments(node, comment, locAttribute);
                }
            }                   

            if (node.Children != null)
            {
                //
                // The baml itself might contain comments too
                // Grab the missing comments from Baml if there is any.
                //    

                for (int i = 0; 
                     i < node.Children.Count  && (comment.LocalizationComments.Length == 0 || comment.LocalizationAttributes.Length == 0); 
                     i++)
                {                    
                    BamlTreeNode child = (BamlTreeNode) node.Children[i];
                    if (child.NodeType == BamlNodeType.Property)
                    {
                        BamlPropertyNode propertyNode = (BamlPropertyNode) child;

                        if (LocComments.IsLocCommentsProperty(propertyNode.OwnerTypeFullName, propertyNode.PropertyName)
                         && comment.LocalizationComments.Length == 0)
                        {
                            // grab comments from Baml
                            SetLocalizationComments(node, comment, propertyNode.Value);
                        }
                        else if (LocComments.IsLocLocalizabilityProperty(propertyNode.OwnerTypeFullName, propertyNode.PropertyName)
                            && comment.LocalizationAttributes.Length == 0)
                        {
                            // grab comments from Baml                            
                            SetLocalizationAttributes(node, comment, propertyNode.Value);                                                                
                        }
                    }
                }
            }            
            
            // cached it 
            _comments[_commentsIndex] = comment;
            _commentsIndex = (_commentsIndex + 1) % _comments.Length;            
            
            return comment;
        }