Example #1
0
        private void AddExpressionGroup(QueryExpressionGroup group = null, int atIndex = -1)
        {
            if (group == null)
            {
                group = new QueryExpressionGroup(Builder);
            }
            group.AddExpression();
            if (group.NestedExpressions.Count == 1)
            {
                group.AddExpression();
            }
            group.Deleting += NestedGroupOnDeleting;
            group.ConvertingToExpression += GroupOnConvertingToExpression;
            group.ExpressionChanged      += (sender, args) => ExpressionChanged?.Invoke(sender, args);

            if (atIndex >= 0)
            {
                NestedExpressions.Insert(atIndex, group);
                ExpressionStackPanel.Children.Insert(atIndex, group);
            }
            else
            {
                NestedExpressions.Add(group);
                ExpressionStackPanel.Children.Add(group);
            }
            OnNestedExpressionsChanged();
        }
        internal string ExpandString(IEnumerable <object> expandedValues)
        {
            expandedValues = expandedValues.Reverse();
            var exValEnumerator = expandedValues.GetEnumerator();

            var    resultStr = new StringBuilder();
            string rest      = Value;

            // we expand this string in reversed order so we don't need to adjust start indexes
            foreach (var item in NestedExpressions.Reverse())
            {
                if (!exValEnumerator.MoveNext())
                {
                    break;
                }
                // first find the relative position of the expandable part inside our string
                string value    = LanguagePrimitives.ConvertTo <string>(exValEnumerator.Current);
                var    relStart = item.Extent.StartOffset - Extent.StartOffset - 1;
                var    relEnd   = item.Extent.EndOffset - Extent.StartOffset - 1;
                // the end are constant words between this expression and the last resolved expression
                // we need to resolve escape constants before adding it
                var resolvedEnd = StringExpressionHelper.ResolveEscapeCharacters(rest.Substring(relEnd), StringConstantType);
                // as we do it in reverse order: insert at the beginning, in reverse order
                resultStr.Insert(0, resolvedEnd).Insert(0, value);
                // finally strip the rest which needs to be expanded
                rest = rest.Substring(0, relStart);
            }
            // now insert the rest at the beginning (other constant string)
            resultStr.Insert(0, StringExpressionHelper.ResolveEscapeCharacters(rest, StringConstantType));
            return(resultStr.ToString());
        }
Example #3
0
        /// <summary>
        /// Converts an expression to a group
        /// </summary>
        private void ExpressionOnConvertToGroupClicked(object sender, EventArgs eventArgs)
        {
            try
            {
                // Get the expression that wants to convert
                var expression = sender as QueryExpression;
                if (expression == null)
                {
                    return;
                }

                int index = NestedExpressions.IndexOf(expression);

                RemoveExpression(expression);

                expression.RemoveButton.IsEnabled = true;

                var group = new QueryExpressionGroup(Builder);
                group.AddExpression(expression);
                AddExpressionGroup(group, index);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Example #4
0
        public QueryExpression AddExpression(QueryExpression expression = null, int atIndex = -1)
        {
            if (expression == null)
            {
                expression = new QueryExpression(this);
            }
            else
            {
                expression.ParentGroup = this;
            }
            expression.SetFields(Builder.Fields);

            expression.RemoveClicked         += ExpressionOnRemoveClicked;
            expression.ConvertToGroupClicked += ExpressionOnConvertToGroupClicked;
            expression.ExpressionChanged     += (sender, args) => ExpressionChanged?.Invoke(sender, args);

            if (atIndex >= 0)
            {
                NestedExpressions.Insert(atIndex, expression);
                ExpressionStackPanel.Children.Insert(atIndex, expression);
            }
            else
            {
                NestedExpressions.Add(expression);
                ExpressionStackPanel.Children.Add(expression);
            }

            OnNestedExpressionsChanged();

            return(expression);
        }
Example #5
0
        /// <summary>
        /// Handles a group within this group being deleted
        /// </summary>
        private void NestedGroupOnDeleting(object sender, EventArgs eventArgs)
        {
            var group = sender as QueryExpressionGroup;

            if (group == null)
            {
                return;
            }
            NestedExpressions.Remove(group);
            ExpressionStackPanel.Children.Remove(group);
            OnNestedExpressionsChanged();
        }
Example #6
0
        private void RemoveExpressionGroup(QueryExpressionGroup group)
        {
            group.RemoveHandlers();

            group.NestedExpressions.Clear();
            group.ExpressionStackPanel.Children.Clear();

            NestedExpressions.Remove(group);
            ExpressionStackPanel.Children.Remove(group);

            OnNestedExpressionsChanged();
        }
Example #7
0
        /// <summary>
        /// Converts a group to an expression
        /// </summary>
        private void GroupOnConvertingToExpression(object sender, EventArgs eventArgs)
        {
            try
            {
                var groupToRemove   = (QueryExpressionGroup)sender;
                var expressionToAdd = groupToRemove.NestedExpressions[0] as QueryExpression;
                int index           = NestedExpressions.IndexOf(groupToRemove);

                RemoveExpressionGroup(groupToRemove);
                AddExpression(expressionToAdd, index);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Example #8
0
        private QueryExpressionGroup AddSingleExpressionGroup(QueryExpressionGroup group = null)
        {
            if (group == null)
            {
                group = new QueryExpressionGroup(Builder);
            }
            group.Deleting += NestedGroupOnDeleting;
            group.ConvertingToExpression += GroupOnConvertingToExpression;
            group.ExpressionChanged      += (sender, args) => ExpressionChanged?.Invoke(sender, args);

            NestedExpressions.Add(group);
            ExpressionStackPanel.Children.Add(group);

            OnNestedExpressionsChanged();

            return(group);
        }
Example #9
0
        private void ExpressionOnRemoveClicked(object sender, EventArgs eventArgs)
        {
            var expression = sender as QueryExpression;

            if (expression == null)
            {
                return;
            }
            NestedExpressions.Remove(expression);
            ExpressionStackPanel.Children.Remove(expression);
            OnNestedExpressionsChanged();

            // Convert this group to an expression if there is only one item after removing
            if (!IsRootGroup && NestedExpressions.Count == 1)
            {
                var handler = ConvertingToExpression;
                handler?.Invoke(this, eventArgs);
            }
        }