public ElementRepository(IElementFactory elementFactory, ITreeOfLifeSession session)
        {
            _session = session;

            _elements = new ReadOnlyCollection<Element>(new List<Element>
            {
                elementFactory.Create("Elements/1", 11, "Air", "\U0001F701"),
                elementFactory.Create("Elements/2", 23, "Water", "\U0001F704"),
                elementFactory.Create("Elements/3", 31, "Fire", "\U0001F702"),
                elementFactory.Create("Elements/4", 33, "Earth", "\U0001F703"),
                elementFactory.Create("Elements/5", 34, "Spirit", "\U0001F700")
            });
        }
Beispiel #2
0
        public void SerializeTextTest()
        {
            var element = elementFactory.Create(x => x.Div)
                          .AddAttribute(a => a.Id).Setup(i => i.SetValue("selector"))
                          .AddChild(e => e.Div, out var child)
                          .AddAttribute(a => a.Class).Setup(c => c.SetValue("child_class"))
                          .AddChild(e => e.A)
                          .AddAttribute(a => a.HRef).Setup(r => r.SetValue("https://host.com"))
                          .AddContent("The link")
                          .Root;

            var result = string.Empty;

            using (var sw = new StringWriter())
            {
                var serializer = serializerFactory.Create(element);
                serializer.Serialize(sw);
                result = sw.ToString();
            }
            var testResult =
                @"<div id=""selector"">
    <div class=""child_class"">
        <a href=""https://host.com"">The link</a>
    </div>
</div>";

            Assert.AreEqual(result, testResult);
        }
Beispiel #3
0
        public static IElement CreateElement(this IElementOwner owner, IElementFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            var context = new ElementCreationContext(owner, null, factory);

            return(factory.Create(context));
        }
        public HtmlElement Create(Document document, string localName, string prefix = null)
        {
            if (localName == "rock:zone")
            {
                return(new RockZoneElement(document, prefix));
            }
            else if (localName == "rock:block")
            {
                return(new RockBlockElement(document, prefix));
            }

            return(_baseFactory.Create(document, localName, prefix));
        }
Beispiel #5
0
        private void CreateElement(IList <string> lines, string line, IDictionary <string, IJoint> joints)
        {
            string[] parts   = line.Split(' ');
            IElement element = elementFactory.Create(PopLine(lines));

            AddElementPoints(element, PopLine(lines));
            AddElementColors(element, PopLine(lines));
            element.ZIndex = Convert.ToSingle(PopLine(lines));
            string parentName  = GetParentName(parts[1]);
            IJoint parentJoint = joints[parentName];

            parentJoint.AddElement(element);
        }
Beispiel #6
0
        public void HtmlElementFactoryTest()
        {
            var element = elementFactory.Create(e => e.Div)
                          .AddAttribute(a => a.Id).Setup(i => i.SetValue("selector"))
                          .AddChild(e => e.Div)
                          .AddAttribute(a => a.Class).Setup(c => c.SetValue("custom_class"))
                          .Root;

            var text = element.ToString();

            var testText =
                @"<div id=""selector"">
    <div class=""custom_class""/>
</div>";

            Assert.IsNotNull(element);
            Assert.IsNotNull(element.Root);
            Assert.IsNull(element.Parent);
            Assert.AreEqual(text, testText);
        }
        public void CustomSerialaizeAttributeTest()
        {
            var element = elementFactory.Create(e => e.Div, serializerFactory)
                          .AddAttribute(a => a.Id).Setup(i => i.SetValue("selector"))
                          .AddChild(e => e.Div)
                          .AddAttribute(a => a.Class).Setup(c => c.SetValue(new[] { "custom_class", "custom_class2" }))
                          .Root;

            var text = element.ToString();

            var testText =
                @"<div id=""selector"">
    <div class=""CUSTOM_CLASS CUSTOM_CLASS2""/>
</div>";

            Assert.IsNotNull(element);
            Assert.IsNotNull(element.Root);
            Assert.IsNull(element.Parent);
            Assert.AreEqual(text, testText);
        }
Beispiel #8
0
        /// <summary>
        /// Gets the next element if it fits within the given constraint without removing it from the buffer.
        /// </summary>
        /// <param name="constraint">The constraint the resulting element should fit in.</param>
        /// <returns>The resulting element.</returns>
        public IElement Peek(IDimensionConstraint constraint)
        {
            this.ThrowIfBufferIsEmpty();

            if (constraint.MaxWidth == null)
            {
                throw new Exception("A max width must be provided in the constraint.");
            }

            if (constraint.MaxHeight == null)
            {
                throw new Exception("A max height must be provided in the constraint.");
            }

            var first = this.elements.First();

            if (first.Flags != null)
            {
                var text = this.Peek(constraint, first.Flags);
                if (text == String.Empty)
                {
                    return(null);
                }

                var formattedText = (IFormattedText)elementFactory.Create(first.Flags);
                formattedText.SetText(text);
                return(formattedText);
            }

            if (first.Element == null || first.Element.GetWidth() > constraint.MaxWidth || first.Element.GetHeight() > constraint.MaxHeight)
            {
                return(null);
            }

            return(first.Element);
        }
Beispiel #9
0
 public HtmlElement CreateHtmlElement(String name, String prefix = null, NodeFlags flags = NodeFlags.None) => _htmlFactory.Create(this, name, prefix, flags);
Beispiel #10
0
 public SvgElement CreateSvgElement(String name, String prefix = null)
 {
     return(_svgFactory.Create(this, name, prefix));
 }
Beispiel #11
0
 public MathElement CreateMathElement(String name, String prefix = null)
 {
     return(_mathFactory.Create(this, name, prefix));
 }
Beispiel #12
0
 public HtmlElement CreateHtmlElement(String name, String prefix = null)
 {
     return(_htmlFactory.Create(this, name, prefix));
 }
Beispiel #13
0
        public static Element?Read(XmlReader reader, IElementFactory elementFactory)
        {
            var elements = new List <Element>();
            var stack    = new Stack <Element>();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.None:
                    break;

                case XmlNodeType.Element:
                {
                    string  localName = reader.LocalName;
                    Element element;

                    if (string.IsNullOrEmpty(reader.NamespaceURI) || elementFactory.Namespaces.Contains(reader.NamespaceURI))
                    {
                        var parent = stack.Count > 0 ? stack.Peek() : null;

                        element        = elementFactory.Create(localName, parent);
                        element.Parent = parent;

                        if (reader.MoveToFirstAttribute())
                        {
                            do
                            {
                                if (string.IsNullOrEmpty(reader.NamespaceURI) || elementFactory.Namespaces.Contains(reader.NamespaceURI))
                                {
                                    string attributeName = reader.LocalName;
                                    element.Attributes.Add(attributeName, reader.Value);
                                }
                            }while (reader.MoveToNextAttribute());
                            reader.MoveToElement();
                        }

                        var children = parent != null ? parent.Children : elements;
                        children.Add(element);
                    }
                    else
                    {
                        element = new UnknownElement()
                        {
                            Tag = localName, Parent = null
                        };
                    }

                    if (!reader.IsEmptyElement)
                    {
                        stack.Push(element);
                    }
                }
                break;

                case XmlNodeType.Attribute:
                    break;

                case XmlNodeType.Text:
                {
                    var element = stack.Peek();
                    var content = new ContentElement()
                    {
                        Content = reader.Value
                    };
                    element.Children.Add(content);
                }
                break;

                case XmlNodeType.CDATA:
                {
                    var element = stack.Peek();
                    var content = new ContentElement()
                    {
                        Content = reader.Value
                    };
                    element.Children.Add(content);
                }
                break;

                case XmlNodeType.EntityReference:
                {
                    reader.ResolveEntity();
                    var element = stack.Peek();
                    var content = new ContentElement()
                    {
                        Content = reader.Value
                    };
                    element.Children.Add(content);
                }
                break;

                case XmlNodeType.Entity:
                    break;

                case XmlNodeType.ProcessingInstruction:
                    break;

                case XmlNodeType.Comment:
                    break;

                case XmlNodeType.Document:
                    break;

                case XmlNodeType.DocumentType:
                    break;

                case XmlNodeType.DocumentFragment:
                    break;

                case XmlNodeType.Notation:
                    break;

                case XmlNodeType.Whitespace:
                    break;

                case XmlNodeType.SignificantWhitespace:
                    break;

                case XmlNodeType.EndElement:
                {
                    var element = stack.Pop();

                    foreach (var child in element.Children)
                    {
                        if (child is ContentElement content)
                        {
                            element.Content += content.Content;
                        }
                    }
                }
                break;

                case XmlNodeType.EndEntity:
                    break;

                case XmlNodeType.XmlDeclaration:
                    break;

                default:
                    break;
                }
            }
            if (elements.Count == 1)
            {
                return(elements[0]);
            }
            return(null);
        }
 public override Element CreateElementFrom(String name, String prefix)
 {
     return(_factory.Create(this, name, prefix) as Element);
 }
Beispiel #15
0
 public MathElement CreateMathElement(String name, String prefix = null, NodeFlags flags = NodeFlags.None) => _mathFactory.Create(this, name, prefix, flags);
Beispiel #16
0
 internal override Element CreateElementFrom(String name, String prefix)
 {
     return(_factory.Create(this, name, prefix));
 }
Beispiel #17
0
 public SvgElement CreateSvgElement(String name, String prefix = null, NodeFlags flags = NodeFlags.None) => _svgFactory.Create(this, name, prefix, flags);
 public SvgElement CreateSvgElement(String name, String prefix = null) => _svgFactory.Create(this, name, prefix);