private void AddExpression(HermesModel expression) { if (this.QueryExpressions == null) { this.QueryExpressions = new ObservableCollection <SelectStatementViewModel>(); } if (expression is SelectStatement) { SelectStatement statement = (SelectStatement)expression; SelectStatementViewModel select = new SelectStatementViewModel(this, statement); this.QueryExpressions.Add(select); } }
private void VisitExpression(HermesModel expression) { if (expression is SelectStatement) { VisitSelectStatement((SelectStatement)expression); } else if (expression is PropertyReference) { VisitPropertyReference((PropertyReference)expression); } else if (expression is ParameterExpression) { VisitParameterExpression((ParameterExpression)expression); } }
public HermesViewModel(HermesViewModel parent, HermesModel model) : this(parent) { this.Model = model; }
private void AddOuterBooleanOperator() { BooleanOperator model = this.Model as BooleanOperator; if (model == null) { return; } // 0. Remember the parent of this node HermesModel consumer = model.Consumer; HermesViewModel parentVM = this.Parent; int index_to_replace = -1; if (consumer is BooleanOperator) { index_to_replace = ((BooleanOperator)consumer).Operands.IndexOf(model); if (index_to_replace == -1) { throw new ArgumentOutOfRangeException("Model is broken!"); } } // 1. Create new node and it's VM which will substitute this current node BooleanOperator substitute = new BooleanOperator(consumer) { Name = BooleanFunction.OR }; substitute.AddChild(model); BooleanOperatorViewModel substituteVM = new BooleanOperatorViewModel(parentVM, substitute); this.Parent = substituteVM; // 2. Create new child and it's VM consumed by substitute BooleanOperator child = new BooleanOperator(substitute); substitute.AddChild(child); BooleanOperatorViewModel childVM = new BooleanOperatorViewModel(substituteVM, child); // 3. Add new comparison operator and it's VM to new born child ComparisonOperator gift = new ComparisonOperator(child); child.AddChild(gift); ComparisonOperatorViewModel giftVM = new ComparisonOperatorViewModel(childVM, gift); childVM.Operands = new ObservableCollection <BooleanFunctionViewModel>() { giftVM }; // 4. Fill substitute VM with operands substituteVM.Operands = new ObservableCollection <BooleanFunctionViewModel>() { this, childVM }; // 5. Substitute this current node at parent VM and it's model if (consumer is BooleanOperator) { ((BooleanOperator)consumer).Operands.RemoveAt(index_to_replace); ((BooleanOperator)consumer).Operands.Insert(index_to_replace, substitute); index_to_replace = ((BooleanOperatorViewModel)parentVM).Operands.IndexOf(this); if (index_to_replace > -1) { ((BooleanOperatorViewModel)parentVM).Operands.RemoveAt(index_to_replace); ((BooleanOperatorViewModel)parentVM).Operands.Insert(index_to_replace, substituteVM); } } else if (parentVM is BooleanExpressionViewModel) { ((BooleanExpressionViewModel)parentVM).SetBooleanExpression(substituteVM); } }