Example #1
0
        static Expression <Func <object, bool> > GetWhereExpression(BuildExpressionContext context, List <Filter> filters)
        {
            if (filters == null || filters.Count == 0)
            {
                return(null);
            }

            string str = filters.Select(f => QueryUtils.CanFilter(f.Token)).NotNull().ToString("\r\n");

            if (str == null)
            {
                throw new ApplicationException(str);
            }

            FilterBuildExpressionContext filterContext = new FilterBuildExpressionContext(context);

            foreach (var f in filters)
            {
                f.GenerateCondition(filterContext);
            }

            Expression body = filterContext.Filters.Select(f => f.ToExpression(filterContext)).AggregateAnd();

            return(Expression.Lambda <Func <object, bool> >(body, context.Parameter));
        }
Example #2
0
        protected override string PropertyValidation(PropertyInfo pi)
        {
            if (token != null && token.ParseException == null)
            {
                if (pi.Name == nameof(Token))
                {
                    return(QueryUtils.CanFilter(token.Token));
                }

                if (pi.Name == nameof(Operation))
                {
                    FilterType?filterType = QueryUtils.TryGetFilterType(Token.Token.Type);

                    if (filterType == null)
                    {
                        return(UserQueryMessage._0IsNotFilterable.NiceToString().FormatWith(token));
                    }

                    if (!QueryUtils.GetFilterOperations(filterType.Value).Contains(Operation))
                    {
                        return(UserQueryMessage.TheFilterOperation0isNotCompatibleWith1.NiceToString().FormatWith(Operation, filterType));
                    }
                }

                if (pi.Name == nameof(ValueString))
                {
                    return(FilterValueConverter.TryParse(ValueString, Token.Token.Type, out object val, Operation.IsList()));
                }
            }

            return(null);
        }
Example #3
0
        public static void CanFilterDecorator(QueryToken qt, HtmlTag option)
        {
            string canFilter = QueryUtils.CanFilter(qt);

            if (canFilter.HasText())
            {
                option.Attr("data-filter", canFilter);
            }
        }
Example #4
0
        List <QueryToken> tokenBuilder_SubTokensEvent(QueryToken arg)
        {
            string canColumn = QueryUtils.CanColumn(arg);

            btCreateColumn.IsEnabled = string.IsNullOrEmpty(canColumn);
            btCreateColumn.ToolTip   = canColumn;


            string canFilter = QueryUtils.CanFilter(arg);

            btCreateFilter.IsEnabled = string.IsNullOrEmpty(canFilter);
            btCreateFilter.ToolTip   = canFilter;

            return(arg.SubTokens(Description, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement));
        }
Example #5
0
        protected IEnumerable <OmniboxFilterResult> GetFilterQueries(string rawQuery, QueryDescription queryDescription, FilterSyntax syntax, List <OmniboxToken> tokens)
        {
            List <OmniboxFilterResult> result = new List <OmniboxFilterResult>();

            int operatorIndex = syntax.Index + syntax.TokenLength;

            List <(QueryToken token, ImmutableStack <OmniboxMatch> stack)> ambiguousTokens = GetAmbiguousTokens(null, ImmutableStack <OmniboxMatch> .Empty,
                                                                                                                queryDescription, tokens, syntax.Index, operatorIndex).ToList();

            foreach ((QueryToken token, ImmutableStack <OmniboxMatch> stack)pair in ambiguousTokens)
            {
                var distance     = pair.stack.Sum(a => a.Distance);
                var tokenMatches = pair.stack.Reverse().ToArray();
                var token        = pair.token;

                if (syntax.Completion == FilterSyntaxCompletion.Token)
                {
                    if (tokens[operatorIndex - 1].Next(rawQuery) == '.' && pair.stack.All(a => ((QueryToken)a.Value).ToString().ToOmniboxPascal() == a.Text))
                    {
                        foreach (var qt in QueryUtils.SubTokens(pair.token, queryDescription, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement))
                        {
                            result.Add(new OmniboxFilterResult(distance, syntax, qt, tokenMatches));
                        }
                    }
                    else
                    {
                        result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches));
                    }
                }
                else
                {
                    string?canFilter = QueryUtils.CanFilter(pair.token);

                    if (canFilter.HasText())
                    {
                        result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches)
                        {
                            CanFilter = canFilter,
                        });
                    }
                    else
                    {
                        FilterOperation operation = FilterValueConverter.ParseOperation(tokens[operatorIndex].Value);

                        if (syntax.Completion == FilterSyntaxCompletion.Operation)
                        {
                            var suggested = SugestedValues(pair.token);

                            if (suggested == null)
                            {
                                result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches)
                                {
                                    Operation = operation,
                                });
                            }
                            else
                            {
                                foreach (var item in suggested)
                                {
                                    result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches)
                                    {
                                        Operation = operation,
                                        Value     = item.Value
                                    });
                                }
                            }
                        }
                        else
                        {
                            var values = GetValues(pair.token, tokens[operatorIndex + 1]);

                            foreach (var value in values)
                            {
                                result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches)
                                {
                                    Operation  = operation,
                                    Value      = value.Value,
                                    ValueMatch = value.Match,
                                });
                            }
                        }
                    }
                }
            }

            return(result);
        }
Example #6
0
        protected override string?PropertyValidation(PropertyInfo pi)
        {
            if (IsGroup)
            {
                if (pi.Name == nameof(GroupOperation) && GroupOperation == null)
                {
                    return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName()));
                }


                if (token != null && token.ParseException == null)
                {
                    if (pi.Name == nameof(Token))
                    {
                        return(QueryUtils.CanFilter(token.Token));
                    }
                }
            }
            else
            {
                if (pi.Name == nameof(Operation) && Operation == null)
                {
                    return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName()));
                }

                if (pi.Name == nameof(Token) && Token == null)
                {
                    return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName()));
                }

                if (token != null && token.ParseException == null)
                {
                    if (pi.Name == nameof(Token))
                    {
                        return(QueryUtils.CanFilter(token.Token));
                    }

                    if (pi.Name == nameof(Operation) && Operation != null)
                    {
                        FilterType?filterType = QueryUtils.TryGetFilterType(Token !.Token.Type);

                        if (filterType == null)
                        {
                            return(UserQueryMessage._0IsNotFilterable.NiceToString().FormatWith(token));
                        }

                        if (!QueryUtils.GetFilterOperations(filterType.Value).Contains(Operation.Value))
                        {
                            return(UserQueryMessage.TheFilterOperation0isNotCompatibleWith1.NiceToString().FormatWith(Operation, filterType));
                        }
                    }

                    if (pi.Name == nameof(ValueString))
                    {
                        var result = FilterValueConverter.TryParse(ValueString, Token !.Token.Type, Operation !.Value.IsList());
                        return(result is Result <object> .Error e ? e.ErrorText : null);
                    }
                }
            }

            return(null);
        }