예제 #1
0
        private void serachForParent(LaTeXElement element, LaTeXElementParser parser)
        {
            var parentFound = false;

            for (var i = _parserList.Count - 2; i > -1; i--)
            {
                try
                {
                    _parserList[i].SetChildElement(_elementsList[i], element);

                    parentFound = true;
                    _elementsList.RemoveRange(i + 1, _elementsList.Count - i - 1);
                    _parserList.RemoveRange(i + 1, _parserList.Count - i - 1);
                    addElementAndParserToTracking(element, parser);

                    break;
                }
                catch (ArgumentException)
                {
                }
                catch (NotSupportedException)
                {
                }
            }

            if (!parentFound)
            {
                _parserList.Clear();
                _elementsList.Clear();

                addElementToList(element, parser);
            }
        }
예제 #2
0
 private void addElementAndParserToTracking(LaTeXElement element, LaTeXElementParser parser)
 {
     if (parser != null)
     {
         _parserList.Add(parser);
         _elementsList.Add(element);
     }
 }
        public void setChildElement_should_throw_if_child_is_higher_hirarcy(LaTeXElement element)
        {
            // Given

            // Then
            var ex = Assert.Throws <ArgumentException>(() => SUT.SetChildElement(new Section(), element));

            Assert.AreEqual("A Section can't have a DocumentClass, Document or Chapter as a child", ex.Message);
        }
예제 #4
0
 public static bool ElementIsMainContentDevider(LaTeXElement element)
 {
     return(element is DocumentClass ||
            element is Document ||
            element is Chapter ||
            element is Section ||
            element is Subsection ||
            element is Subsubsection);
 }
예제 #5
0
        public void setChildElement_should_throw_if_hirarcy_is_higher(LaTeXElement element)
        {
            // When
            var item = new Item();

            // Then
            var ex = Assert.Throws <ArgumentException>(() => SUT.SetChildElement(item, element));

            Assert.AreEqual("An Item can't have a DocumentClass, Document Chapter or other element that is concidered to organize information", ex.Message);
        }
예제 #6
0
 private void setElementToParent(LaTeXElement element, LaTeXElementParser parser)
 {
     try
     {
         setElementToClosestParent(element, parser);
     }
     catch (ArgumentException)
     {
         serachForParent(element, parser);
     }
     catch (NotSupportedException)
     {
         serachForParent(element, parser);
     }
 }
예제 #7
0
 private void setElementInHierarchy(LaTeXElement element, LaTeXElementParser parser)
 {
     if (element != null && _elements.Count == 0)
     {
         addElementToList(element, parser);
     }
     else if (element != null)
     {
         setElementToParent(element, parser);
     }
     else
     {
         backofElement(parser);
     }
 }
예제 #8
0
        /// <summary>
        /// Sets the child elements of a given element
        /// </summary>
        /// <param name="element">The element to set the children to</param>
        /// <param name="children">The elements to set</param>
        /// <exception cref="NotSupportedException">Thrown if the element isn't supported or the element doesn't support child items</exception>
        /// <exception cref="ArgumentException">Thrown if the any element in the list isn't a supported child element</exception>
        public void SetChildElement(LaTeXElement element, params LaTeXElement[] children)
        {
            if (children.Any(x => x is DocumentClass))
            {
                throw new ArgumentException("A Document can't have a DocumentClass as a child");
            }
            else if (!(element is Document))
            {
                throw new ArgumentException("The supplied element wasn't a Document, only Document is allowed");
            }
            else if (!children.Any())
            {
                throw new ArgumentException("No child elements supplied to set as child");
            }

            var doc = (Document)element;

            doc.Elements.AddRange(children);
        }
예제 #9
0
        /// <summary>
        /// Sets the child elements of a given element
        /// </summary>
        /// <param name="element">The element to set the children to</param>
        /// <param name="children">The elements to set</param>
        /// <exception cref="NotSupportedException">Thrown if the element isn't supported or the element doesn't support child items</exception>
        /// <exception cref="ArgumentException">Thrown if the any element in the list isn't a supported child element</exception>
        public void SetChildElement(LaTeXElement element, params LaTeXElement[] children)
        {
            if (children.Any(x => x is DocumentClass) || children.Any(x => x is Document) ||
                children.Any(x => x is Chapter) || children.Any(x => x is Section))
            {
                throw new ArgumentException("A Section can't have a DocumentClass, Document or Chapter as a child");
            }
            else if (!(element is Section))
            {
                throw new ArgumentException("The supplied element wasn't a Section, only Section is allowed");
            }
            else if (!children.Any())
            {
                throw new ArgumentException("No child elements supplied to set as child");
            }

            var doc = (Section)element;

            doc.Elements.AddRange(children);
        }
예제 #10
0
 /// <summary>
 /// Sets the child elements of a given element
 /// </summary>
 /// <param name="element">The element to set the children to</param>
 /// <param name="children">The elements to set</param>
 /// <exception cref="NotSupportedException">Thrown if the element doesn't support child items</exception>
 /// <exception cref="ArgumentException">Thrown if the any element in the list isn't a supported child element</exception>
 public void SetChildElement(LaTeXElement element, params LaTeXElement[] children)
 {
     if (!children.Any())
     {
         throw new ArgumentException("No child document supplied to set as child");
     }
     else if (children.Length > 1)
     {
         throw new ArgumentException("More than one child element supplied, not accepted");
     }
     else if (!(children[0] is Document))
     {
         throw new ArgumentException("The supplied child wasn't a Document, only Document is allowed");
     }
     else if (!(element is DocumentClass))
     {
         throw new ArgumentException("The supplied element wasn't a Document, only Document is allowed");
     }
     else
     {
         ((DocumentClass)element).Document = (Document)children[0];
     }
 }
예제 #11
0
 /// <summary>
 /// Sets the child elements of a given element
 /// </summary>
 /// <param name="element">The element to set the children to</param>
 /// <param name="children">The elements to set</param>
 /// <exception cref="NotSupportedException">Thrown if the element isn't supported or the element doesn't support child items</exception>
 /// <exception cref="ArgumentException">Thrown if the any element in the list isn't a supported child element</exception>
 void LaTeXElementParser.SetChildElement(LaTeXElement element, params LaTeXElement[] children)
 {
     SetChildElement(element as Enumerate, children);
 }
예제 #12
0
 /// <summary>
 /// Creates a new pair
 /// </summary>
 /// <param name="element">The element of the pair</param>
 /// <param name="parser">The parser for the element</param>
 public LaTeXElementElementParserPair(LaTeXElement element, LaTeXElementParser parser)
 {
     Element = element;
     Parser  = parser;
 }
예제 #13
0
 private void setElementToClosestParent(LaTeXElement element, LaTeXElementParser parser)
 {
     _parserList[_parserList.Count - 1].SetChildElement(_elementsList[_elementsList.Count - 1], element);
     addElementAndParserToTracking(element, parser);
 }
예제 #14
0
 private void addElementToList(LaTeXElement element, LaTeXElementParser parser)
 {
     _elements.Add(element);
     addElementAndParserToTracking(element, parser);
 }
예제 #15
0
 /// <summary>
 /// Sets the child elements of a given element
 /// </summary>
 /// <param name="element">The element to set the children to</param>
 /// <param name="children">The elements to set</param>
 /// <exception cref="NotSupportedException">Thrown if the element isn't supported or the element doesn't support child items</exception>
 /// <exception cref="ArgumentException">Thrown if the any element in the list isn't a supported child element</exception>
 void LaTeXElementParser.SetChildElement(LaTeXElement element, params LaTeXElement[] children)
 {
     SetChildElement(element as Item, children);
 }
예제 #16
0
 /// <summary>
 /// Sets the child elements of a given element
 /// </summary>
 /// <param name="element">The element to set the children to</param>
 /// <param name="children">The elements to set</param>
 /// <exception cref="NotSupportedException">Thrown if the element isn't supported or the element doesn't support child items</exception>
 /// <exception cref="ArgumentException">Thrown if the any element in the list isn't a supported child element</exception>
 void LaTeXElementParser.SetChildElement(LaTeXElement element, params LaTeXElement[] children)
 {
     throw new NotSupportedException();
 }