/// <summary> /// Creates the elementManager style as provided by the QLS node by inserting /// the manager objects provided by the QLS and insterts the given children into /// the tree on the positions defined in the QLS /// </summary> /// <param name="collection">Collection element to be reconstructed</param> /// <param name="children">Children that can occur as a child of the collection element</param> /// <param name="qlsChildren">Children of the QLS node that mached the collection node</param> /// <param name="controller">ElementManagerController for element creation</param> /// <returns>Element manager collection that contains all QLS defined children</returns> private static ElementManagerCollection ReconstructElementCollection(ElementManagerCollection collection, ref List <ElementManagerLeaf> children, QLSNode qlsNode, ElementManagerController controller) { collection.Children.Clear(); foreach (QLSNode node in qlsNode.Children) { switch (node.NodeType) { case QLSNodeType.Page: case QLSNodeType.Section: ElementManagerCollection collectionChild = AddQLSToCollection(node, collection, controller); collectionChild = ReconstructElementCollection(collectionChild, ref children, node, controller); collection.AddChild(collectionChild); break; case QLSNodeType.Question: IEnumerable <ElementManagerLeaf> foundMatches = children.Where(o => o.Identifier == node.ID).Select(o => o as ElementManagerLeaf); if (foundMatches.Count() != 1) { throw new InvalidOperationException(string.Format("Identifier: {0}, used in QLS, was found {1} times in QL!", node.ID, foundMatches.Count())); } ElementManagerLeaf child = foundMatches.First(); children.Remove(child); collection.AddChild(AddQLSToLeaf(node, child)); break; } } collection.AddStyle(qlsNode.NodeStyles.ToArray()); return(collection); }
private static WidgetBuilder <Control> GetCollectionBuilder(ElementManagerCollection elementManagerCollection) { WidgetCollectionBuilder <Control> builder = null; switch (elementManagerCollection) { case FormManager formManager: builder = new FormBuilderWindows(formManager); break; case PageManager pageManager: builder = new PageBuilderWindows(pageManager); break; case SectionManager sectionManager: builder = new SectionBuilderWindows(sectionManager); break; default: throw new NotImplementedException(); } foreach (ElementManager child in elementManagerCollection.Children) { builder.AddChild(GetBuilder(child, builder)); } return(builder); }
public WidgetCollectionBuilder(ElementManagerCollection elementManagerCollection) : base(elementManagerCollection) { _children = new List <WidgetBuilder <T> >(); _elementManagerCollection = elementManagerCollection; _styleValues = new Dictionary <QValueType, QLSStyle>(); AddStyles(elementManagerCollection.GetStyles().ToArray()); }
private static ElementManagerCollection AddQLSToCollection(QLSNode qlsNode, ElementManagerCollection parent, ElementManagerController controller) { switch (qlsNode.NodeType) { case QLSNodeType.Page: return(new PageManager(qlsNode.ID, qlsNode.ID, parent, controller)); case QLSNodeType.Section: return(new SectionManager(qlsNode.ID, qlsNode.ID, parent, controller)); } throw new NotImplementedException(); }
public HexQuestionManager(string identifier, string text, ElementManagerCollection parent, ElementManagerController controller, ExpressionBool activationExpression = null, TypedExpressionValue <Hexadecimal> answerExpression = null) : base(identifier, text, parent, controller, activationExpression, answerExpression) { }
public SectionManager(string identifier, string text, ElementManagerCollection parent, ElementManagerController controller, ExpressionBool activationExpression = null) : base(identifier, text, "section", parent, controller, activationExpression) { }
/// <summary> /// Parses (AST)Node recursively /// </summary> /// <param name="node">Node to parse</param> /// <param name="condition">Base condition, optional</param> /// <returns>Collection of widgets</returns> public static ElementManager ParseChildNode(Node node, ElementManagerController elementManagerController, ElementManagerCollection parent, ExpressionBool condition = null) { switch (node.Type) { case NodeType.CONDITIONAL: ExpressionFactory expressionFactory = new ExpressionFactory(elementManagerController); // Parse condition ExpressionBool newCondition = expressionFactory.GetCondition(node as ConditionalNode); newCondition = (condition == null) ? newCondition : condition.Combine(newCondition, ExpressionOperator.And) as ExpressionBool; // Add children with new condition parent.AddChildren(node.Children.Select(o => ParseChildNode(o, elementManagerController, parent, newCondition)).Where(o => o != null)); // return parent return(null); case NodeType.FORM: throw new InvalidOperationException("Cannot stack form nodes"); case NodeType.QUESTION: return(CreateElementManager(node as QuestionNode, condition, parent, elementManagerController)); case NodeType.COMPUTED: return(CreateComputedWidget(node as ComputedNode, condition, parent, elementManagerController)); } throw new NotImplementedException(); }
private static ElementManagerLeaf CreateElementManager(IQuestionable identifiedNode, ExpressionBool condition, ElementManagerCollection parent, ElementManagerController elementManagerController, ExpressionValue activationExpression) { switch (identifiedNode.ValueType) { case QValueType.Boolean: return(new BoolQuestionManager(identifiedNode.ID, identifiedNode.Text, parent, elementManagerController, condition, activationExpression as ExpressionBool)); case QValueType.Integer: return(new IntQuestionManager(identifiedNode.ID, identifiedNode.Text, parent, elementManagerController, condition, activationExpression as ExpressionInt)); case QValueType.Text: return(new StringQuestionManager(identifiedNode.ID, identifiedNode.Text, parent, elementManagerController, condition, activationExpression as ExpressionText)); case QValueType.Money: return(new MoneyQuestionManager(identifiedNode.ID, identifiedNode.Text, parent, elementManagerController, condition, activationExpression as ExpressionDouble)); case QValueType.Hex: return(new HexQuestionManager(identifiedNode.ID, identifiedNode.Text, parent, elementManagerController, condition, activationExpression as ExpressionHex)); } throw new InvalidOperationException("Unsupported type: " + identifiedNode.ValueType); }
/// <summary> /// Parses Node recursively /// </summary> /// <param name="node">Node to parse</param> /// <param name="condition">Base condition, optional</param> /// <returns>Collection of widgets</returns> public static ElementManager ParseChildNode(QLNode node, ElementManagerController elementManagerController, ElementManagerCollection parent, ExpressionBool condition = null) { ExpressionFactory expressionFactory = new ExpressionFactory(elementManagerController); switch (node) { case ConditionalNode conditionalNode: // Parse condition ExpressionBool newCondition = expressionFactory.GetCondition(conditionalNode); newCondition = (condition == null) ? newCondition : condition.Combine(newCondition, ExpressionOperator.And) as ExpressionBool; // Add children with new condition parent.AddChildren(conditionalNode.Children.Select(o => ParseChildNode(o, elementManagerController, parent, newCondition)).Where(o => o != null)); return(null); case QuestionNode questionNode: return(CreateElementManager(questionNode, condition, parent, elementManagerController, null)); case ComputedNode computedNode: ExpressionValue expression = expressionFactory.ParseExpressionNode(computedNode.Expression); return(CreateElementManager(computedNode, condition, parent, elementManagerController, expression)); } throw new NotImplementedException(); }
public ElementManagerSubCollection(string identifier, string text, string xmlName, ElementManagerCollection parent, ElementManagerController controller, ExpressionBool activationExpression = null) : base(identifier, text, xmlName, controller, activationExpression) { Parent = parent; }