Ejemplo n.º 1
0
        // Builds tree and parses each element
        private static ElementTree BuildTree(DataElementDTO data, RenderOptions options, RenderAccumulator accumulator = null)
        {
            var tree = new ElementTree();

            var acc = accumulator;

            if (accumulator == null)
            {
                acc = new RenderAccumulator();
            }

            if (!string.IsNullOrEmpty(data.Value))
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.Value;

                tree.Add(new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                });
            }

            else if (data.Childs.Any())
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.OpenTag;

                var elementNode = new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                };

                RenderManager.AddTab(acc);

                foreach (var item in data.Childs)
                {
                    var temp = BuildTree(item, options, acc);

                    foreach (var node in temp.Elements)
                    {
                        elementNode.Childs.Add(node);
                        elementNode.Data += node.Data;
                    }
                }

                options.TargetType = RenderTargetTypes.ClosedTag;

                elementNode.Data += RenderManager.Render(tag, options, acc);
                tree.Add(elementNode);
            }

            else
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.BodylessTag;

                tree.Add(new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                });
            }

            RenderManager.RemoveTab(acc);

            return(tree);
        }
Ejemplo n.º 2
0
        // Builds tree and parses each element
        private static ElementTree BuildTree(DataElementDTO data, RenderOptions options, RenderAccumulator accumulator = null)
        {
            // Tree, that will exported to SdmlGenerator and will be containing all elements
            var tree = new ElementTree();

            // Recursion accumulator. Allows to render tabulations, based on layer count
            var acc = accumulator;

            if (accumulator == null)
            {
                acc = new RenderAccumulator();
            }

            // If data has value that means this element donesn't have childs
            if (!string.IsNullOrEmpty(data.Value))
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.Value;

                tree.Add(new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                });
            }

            // If data contains at least one child it has to be serialized in a different way than value element
            else if (data.Childs.Any())
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.OpenTag;

                var elementNode = new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                };

                // Add tab to accumulator
                RenderManager.AddTab(acc);

                foreach (var item in data.Childs)
                {
                    var temp = BuildTree(item, options, acc);

                    foreach (var node in temp.Elements)
                    {
                        elementNode.Childs.Add(node);
                        elementNode.Data += node.Data;
                    }
                }

                options.TargetType = RenderTargetTypes.ClosedTag;

                elementNode.Data += RenderManager.Render(tag, options, acc);
                tree.Add(elementNode);
            }

            // If data has no value and no childs it will be rendered as bodyless tag
            else
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.BodylessTag;

                tree.Add(new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                });
            }

            // Removes tabs from accumulator
            RenderManager.RemoveTab(acc);

            return(tree);
        }