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); } }
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); }
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); }
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); }
private void setElementToParent(LaTeXElement element, LaTeXElementParser parser) { try { setElementToClosestParent(element, parser); } catch (ArgumentException) { serachForParent(element, parser); } catch (NotSupportedException) { serachForParent(element, parser); } }
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); } }
/// <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); }
/// <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); }
/// <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]; } }
/// <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); }
/// <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; }
private void setElementToClosestParent(LaTeXElement element, LaTeXElementParser parser) { _parserList[_parserList.Count - 1].SetChildElement(_elementsList[_elementsList.Count - 1], element); addElementAndParserToTracking(element, parser); }
private void addElementToList(LaTeXElement element, LaTeXElementParser parser) { _elements.Add(element); addElementAndParserToTracking(element, parser); }
/// <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); }
/// <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(); }