Beispiel #1
0
 public virtual IEnumerable <XmlRenderGroup> ReadElement(XElement element, ComponentDescription description, XmlRenderGroup groupContext)
 {
     if (element.Name == GroupElementName || (description.Metadata.FormatVersion >= Version1_5 && element.Name == GElementName))
     {
         return(ReadRenderGroup(description, element, groupContext));
     }
     else if (renderCommandReaders.TryGetValue($"{XmlLoader.ComponentNamespace.NamespaceName}:{element.Name.LocalName}", out var renderCommandReader))
     {
         if (renderCommandReader.ReadRenderCommand(element, description, out var command))
         {
             groupContext.Value.Add(command);
         }
         return(Enumerable.Empty <XmlRenderGroup>());
     }
     else if (element.Name == LineElementName)
     {
         if (ReadLineCommand(element, out var line))
         {
             groupContext.Value.Add(line);
         }
         return(Enumerable.Empty <XmlRenderGroup>());
     }
     else if (element.Name == EllipseElementName)
     {
         if (ReadEllipseCommand(description.Metadata.FormatVersion, element, out var ellipse))
         {
             groupContext.Value.Add(ellipse);
         }
         return(Enumerable.Empty <XmlRenderGroup>());
     }
     else if (element.Name == PathElementName)
     {
         if (ReadPathCommand(element, out var path))
         {
             groupContext.Value.Add(path);
         }
         return(Enumerable.Empty <XmlRenderGroup>());
     }
     else if (element.HasElements)
     {
         if (element.Name.Namespace == XmlLoader.ComponentNamespace)
         {
             logger.LogWarning(element, $"Descending unknown render element '{element.Name.LocalName}'");
         }
         return(element.Elements().SelectMany(x => ReadElement(x, description, groupContext)));
     }
     else
     {
         if (element.Name.Namespace == XmlLoader.ComponentNamespace)
         {
             logger.LogWarning(element, $"Unknown render element '{element.Name.LocalName}'");
         }
         return(Enumerable.Empty <XmlRenderGroup>());
     }
 }
Beispiel #2
0
 public virtual IEnumerable <XmlConnectionGroup> ReadElement(XElement element, ComponentDescription description, XmlConnectionGroup groupContext)
 {
     if (element.Name == GroupElementName || element.Name == GElementName)
     {
         return(ReadConnectionGroup(description, element, groupContext));
     }
     else if (element.Name == ConnectionElementName)
     {
         if (ReadConnection(element, out var connection))
         {
             groupContext.Value.Add(connection);
         }
         return(Enumerable.Empty <XmlConnectionGroup>());
     }
     else
     {
         if (element.Name.Namespace == XmlLoader.ComponentNamespace)
         {
             logger.LogWarning(element, $"Unknown connection element '{element.Name.LocalName}'");
         }
         return(Enumerable.Empty <XmlConnectionGroup>());
     }
 }
Beispiel #3
0
        public bool ReadRenderCommand(XElement element, ComponentDescription description, out IXmlRenderCommand command)
        {
            var textCommand = new XmlRenderTextWithDefinitions();

            command = textCommand;

            if (!ReadTextLocation(element, textCommand))
            {
                return(false);
            }

            if (!TryParseTextAlignment(element.Attribute("align"), out ConditionalCollection <TextAlignment> alignment))
            {
                return(false);
            }
            textCommand.Alignment = alignment;

            var tRotation = "0";

            if (description.Metadata.FormatVersion >= TextRotationMinFormatVersion && element.Attribute("rotate") != null)
            {
                tRotation = element.Attribute("rotate").Value;
            }

            var rotation = TextRotation.None;

            switch (tRotation)
            {
            case "0":
                rotation = TextRotation.None;
                break;

            case "90":
                rotation = TextRotation.Rotate90;
                break;

            case "180":
                rotation = TextRotation.Rotate180;
                break;

            case "270":
                rotation = TextRotation.Rotate270;
                break;

            default:
                logger.LogError(element.Attribute("rotate"), $"Invalid value for text rotation: '{tRotation}'");
                break;
            }
            textCommand.Rotation = new ConditionalCollection <TextRotation>
            {
                new Conditional <TextRotation>(rotation, ConditionTree.Empty),
            };

            double size = 11d;

            if (element.Attribute("size") != null)
            {
                if (element.Attribute("size").Value.ToLowerInvariant() == "large")
                {
                    size = 12d;
                }
            }

            var textValueNode = element.Element(XmlLoader.ComponentNamespace + "value");

            if (textValueNode != null)
            {
                foreach (var spanNode in textValueNode.Elements())
                {
                    string nodeValue  = spanNode.Value;
                    var    formatting = TextRunFormatting.Normal;

                    if (spanNode.Name.LocalName == "sub")
                    {
                        formatting = TextRunFormatting.Subscript;
                    }
                    else if (spanNode.Name.LocalName == "sup")
                    {
                        formatting = TextRunFormatting.Superscript;
                    }
                    else if (spanNode.Name.LocalName != "span")
                    {
                        logger.LogWarning(spanNode, $"Unknown node '{spanNode.Name}' will be treated as <span>");
                    }

                    var textRun = new TextRun(nodeValue, formatting);

                    if (!ValidateText(element, description, textRun.Text))
                    {
                        return(false);
                    }

                    textCommand.TextRuns.Add(textRun);
                }
            }
            else if (element.GetAttribute("value", logger, out var value))
            {
                var textRun = new TextRun(value.Value, new TextRunFormatting(TextRunFormattingType.Normal, size));

                if (!ValidateText(value, description, textRun.Text))
                {
                    return(false);
                }

                textCommand.TextRuns.Add(textRun);
            }
            else
            {
                return(false);
            }

            return(true);
        }
        protected virtual bool ReadTextCommand(XElement element, ComponentDescription description, out RenderText command)
        {
            command = new RenderText();

            ReadTextLocation(element, command);

            string tAlignment = "TopLeft";

            if (element.Attribute("align") != null)
            {
                tAlignment = element.Attribute("align").Value;
            }

            if (!Enum.TryParse(tAlignment, out TextAlignment alignment))
            {
                logger.LogError(element.Attribute("align"), $"Invalid value for text alignment: '{tAlignment}'");
            }
            command.Alignment = alignment;

            double size = 11d;

            if (element.Attribute("size") != null)
            {
                if (element.Attribute("size").Value.ToLowerInvariant() == "large")
                {
                    size = 12d;
                }
            }

            var textValueNode = element.Element(XmlLoader.ComponentNamespace + "value");

            if (textValueNode != null)
            {
                foreach (var spanNode in textValueNode.Elements())
                {
                    string nodeValue  = spanNode.Value;
                    var    formatting = TextRunFormatting.Normal;

                    if (spanNode.Name.LocalName == "sub")
                    {
                        formatting = TextRunFormatting.Subscript;
                    }
                    else if (spanNode.Name.LocalName == "sup")
                    {
                        formatting = TextRunFormatting.Superscript;
                    }
                    else if (spanNode.Name.LocalName != "span")
                    {
                        logger.LogWarning(spanNode, $"Unknown node '{spanNode.Name}' will be treated as <span>");
                    }

                    var textRun = new TextRun(nodeValue, formatting);

                    if (!ValidateText(element, description, textRun.Text))
                    {
                        return(false);
                    }

                    command.TextRuns.Add(textRun);
                }
            }
            else if (element.GetAttribute("value", logger, out var value))
            {
                var textRun = new TextRun(value.Value, new TextRunFormatting(TextRunFormattingType.Normal, size));

                if (!ValidateText(value, description, textRun.Text))
                {
                    return(false);
                }

                command.TextRuns.Add(textRun);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        public bool ReadRenderCommand(XElement element, ComponentDescription description, out IXmlRenderCommand command)
        {
            var textCommand = new XmlRenderText();

            command = textCommand;

            if (!ReadTextLocation(element, textCommand))
            {
                return(false);
            }

            string tAlignment = "TopLeft";

            if (element.Attribute("align") != null)
            {
                tAlignment = element.Attribute("align").Value;
            }

            if (!Enum.TryParse(tAlignment, out TextAlignment alignment))
            {
                logger.LogError(element.Attribute("align"), $"Invalid value for text alignment: '{tAlignment}'");
                return(false);
            }
            textCommand.Alignment = alignment;

            var tRotation = "0";

            if (description.Metadata.FormatVersion >= TextRotationMinFormatVersion && element.Attribute("rotate") != null)
            {
                tRotation = element.Attribute("rotate").Value;
            }

            var rotation = TextRotation.None;

            switch (tRotation)
            {
            case "0":
                rotation = TextRotation.None;
                break;

            case "90":
                rotation = TextRotation.Rotate90;
                break;

            case "180":
                rotation = TextRotation.Rotate180;
                break;

            case "270":
                rotation = TextRotation.Rotate270;
                break;

            default:
                logger.LogError(element.Attribute("rotate"), $"Invalid value for text rotation: '{tRotation}'");
                break;
            }
            textCommand.Rotation = rotation;

            double size = 11d;

            if (element.Attribute("size") != null)
            {
                switch (element.Attribute("size").Value.ToLowerInvariant())
                {
                case "large":
                    size = 12.0;
                    break;

                case "sm":
                case "small":
                    size = 10.0;
                    break;

                case "xs":
                    size = 9.0;
                    break;

                case "xxs":
                    size = 8.0;
                    break;

                default:
                    logger.LogWarning(element.Attribute("size"), $"Invalid value for size attribute: '{element.Attribute("size").Value}'");
                    break;
                }
            }

            var textValueNode = element.Element(XmlLoader.ComponentNamespace + "value");

            if (textValueNode != null)
            {
                foreach (var spanNode in textValueNode.Elements())
                {
                    string nodeValue  = spanNode.Value;
                    var    formatting = new TextRunFormatting(TextRunFormattingType.Normal, size);

                    if (spanNode.Name.LocalName == "sub")
                    {
                        formatting.FormattingType = TextRunFormattingType.Subscript;
                    }
                    else if (spanNode.Name.LocalName == "sup")
                    {
                        formatting.FormattingType = TextRunFormattingType.Superscript;
                    }
                    else if (spanNode.Name.LocalName != "span")
                    {
                        logger.LogWarning(spanNode, $"Unknown node '{spanNode.Name}' will be treated as <span>");
                    }

                    var textRun = new TextRun(nodeValue, formatting);

                    if (!ValidateText(element, description, textRun.Text))
                    {
                        return(false);
                    }

                    textCommand.TextRuns.Add(textRun);
                }
            }
            else if (element.GetAttribute("value", logger, out var value))
            {
                var textRun = new TextRun(value.Value, new TextRunFormatting(TextRunFormattingType.Normal, size));

                if (!ValidateText(value, description, textRun.Text))
                {
                    return(false);
                }

                textCommand.TextRuns.Add(textRun);
            }
            else
            {
                return(false);
            }

            return(true);
        }