Example #1
0
 public Filter(string attributeName, string value, FilterOperation operation)
 {
     AttributeName = attributeName;
     Value = value;
     Operation = operation;
     AttributeType = AttributeTypes.Undefined;
 }
 public Qualifier(String field, FilterOperation operation, Value value1)
     : this()
 {
     internalMap[FIELD] = field;
     internalMap[OPERATION] = operation;
     internalMap[VALUE1] = value1;
 }
Example #3
0
 public FilterDescriptor(string path, string value, Condition condition, List<FilterDescriptor> children, FilterOperation filterOperation = FilterOperation.And)
 {
     this.path = path;
     this.value = value;
     this.condition = condition;
     this.operation = filterOperation;
     this.children =  children != null ? children : new List<FilterDescriptor>();
 }
Example #4
0
 protected abstract bool TryCreateExpression(
     FilterOperation operation,
     Expression property,
     Func <object> parseValue,
     [NotNullWhen(true)] out Expression?expression);
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);
        }
        public static string ToStringOperation(FilterOperation operation)
        {
            switch (operation)
            {
                case FilterOperation.EqualTo: return "=";
                case FilterOperation.DistinctTo: return "!=";
                case FilterOperation.GreaterThan: return ">";
                case FilterOperation.GreaterThanOrEqual: return ">=";
                case FilterOperation.LessThan: return "<";
                case FilterOperation.LessThanOrEqual: return "<=";
                case FilterOperation.Contains: return "*=";
                case FilterOperation.StartsWith: return "^=";
                case FilterOperation.EndsWith: return "$=";
                case FilterOperation.Like: return "%=";
                case FilterOperation.NotContains: return "!*=";
                case FilterOperation.NotStartsWith: return "!^=";
                case FilterOperation.NotEndsWith: return "!$=";
                case FilterOperation.NotLike: return "!%=";
            }

            throw new InvalidOperationException("Unexpected Filter {0}".FormatWith(operation));
        }
Example #7
0
        private static bool SatisfyFilter(T obj, IEnumerable <PropertyInfo> propertyChain, IEnumerable <string> filterValues, FilterOperation op)
        {
            var result = false;

            if (propertyChain != null)
            {
                //Find last value
                object objvalue = obj;
                foreach (var propertyInfo in propertyChain)
                {
                    if (propertyInfo != null && !Equals(objvalue, default(T)) && propertyInfo.DeclaringType != null && propertyInfo.DeclaringType.IsInstanceOfType(objvalue))
                    {
                        objvalue = propertyInfo.GetValue(objvalue, null);
                    }
                }

                if (objvalue != null && !ReferenceEquals(objvalue, obj))
                {
                    string value = Convert.ToString(objvalue);
                    foreach (var filterValue in filterValues)
                    {
                        switch (op)
                        {
                        case FilterOperation.Contains:
                            result = value.IndexOf(filterValue, StringComparison.OrdinalIgnoreCase) != -1;
                            break;

                        case FilterOperation.Equals:
                            result = value.Equals(filterValue, StringComparison.OrdinalIgnoreCase);
                            break;

                        case FilterOperation.StartsWith:
                            result = value.StartsWith(filterValue, StringComparison.OrdinalIgnoreCase);
                            break;

                        case FilterOperation.EndsWith:
                            result = value.EndsWith(filterValue, StringComparison.OrdinalIgnoreCase);
                            break;

                        case FilterOperation.Present:
                            result = value.Contains(filterValue);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException("op");
                        }
                        if (result)
                        {
                            break;//Break loop
                        }
                    }
                }
            }
            return(result);
        }
Example #8
0
 private void FilterBoolValueChanged(bool value)
 {
     actualFilterValue       = (TValue)(object)value;
     selectedFilterOperation = FilterOperation.Equal;
     AddFilterDefinition();
 }
        public bool TryHandle(
            FilterOperation operation,
            IInputType type,
            IValueNode value,
            Expression instance,
            ITypeConversion converter,
            out Expression expression)
        {
            if (operation.Type == typeof(string) && value is StringValueNode s)
            {
                MemberExpression property =
                    Expression.Property(instance, operation.Property);

                switch (operation.Kind)
                {
                case FilterOperationKind.Equals:
                    expression = FilterExpressionBuilder.Equals(
                        property, s.Value);
                    return(true);

                case FilterOperationKind.NotEquals:
                    expression = FilterExpressionBuilder.Not(
                        FilterExpressionBuilder.Equals(property, s.Value)
                        );
                    return(true);

                case FilterOperationKind.StartsWith:
                    expression = FilterExpressionBuilder.StartsWith(
                        property, s.Value);
                    return(true);

                case FilterOperationKind.EndsWith:
                    expression = FilterExpressionBuilder.EndsWith(
                        property, s.Value);
                    return(true);

                case FilterOperationKind.NotStartsWith:
                    expression = FilterExpressionBuilder.Not(
                        FilterExpressionBuilder.StartsWith(
                            property, s.Value)
                        );
                    return(true);

                case FilterOperationKind.NotEndsWith:
                    expression = FilterExpressionBuilder.Not(
                        FilterExpressionBuilder.EndsWith(property, s.Value)
                        );
                    return(true);

                case FilterOperationKind.Contains:
                    expression = FilterExpressionBuilder.Contains(
                        property, s.Value);
                    return(true);

                case FilterOperationKind.NotContains:
                    expression = FilterExpressionBuilder.Not(
                        FilterExpressionBuilder.Contains(property, s.Value)
                        );
                    return(true);
                }
            }

            if (operation.Type == typeof(string) && value is ListValueNode li)
            {
                MemberExpression property =
                    Expression.Property(instance, operation.Property);
                var parsedValue = type.ParseLiteral(value);

                switch (operation.Kind)
                {
                case FilterOperationKind.In:
                    expression = FilterExpressionBuilder.In(
                        property,
                        operation.Property.PropertyType,
                        parsedValue);
                    return(true);

                case FilterOperationKind.NotIn:
                    expression = FilterExpressionBuilder.Not(
                        FilterExpressionBuilder.In(
                            property,
                            operation.Property.PropertyType,
                            parsedValue));
                    return(true);
                }
            }

            expression = null;
            return(false);
        }
Example #10
0
 public FilterRecord(FilterInfo fi)
 {
     this.columnName = fi.ColumnName;
     this.operation = fi.Operation;
     this.testObject = fi.Value;
 }
Example #11
0
 public FilterProperty(PropertyInfo property, FilterPropertyAttribute propertyAttribute, FilterOperation operation, FuzzyMatchMode fuzzyMatchMode)
 {
     Property          = property;
     Operation         = operation;
     PropertyName      = propertyAttribute?.PropertyName ?? Property.Name;
     SplitPropertyName = PropertyName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
     Test           = propertyAttribute?.Test ?? FilterTest.Equal;
     FuzzyMatchMode = fuzzyMatchMode;
 }
Example #12
0
        public static string GetOperationByName(FilterOperation operation)
        {
            string result = "";

            switch (operation)
            {
            case FilterOperation.Contains:
                result = "LIKE";
                break;

            case FilterOperation.DoesNotContain:
                result = "NOT LIKE";
                break;

            case FilterOperation.EndsWith:
                result = "LIKE";
                break;

            case FilterOperation.IsContainedIn:
                result = "IN";
                break;

            case FilterOperation.IsEmpty:
                result = "=";
                break;

            case FilterOperation.IsEqualTo:
                result = "=";
                break;

            case FilterOperation.IsGreaterThan:
                result = ">";
                break;

            case FilterOperation.IsGreaterThanOrEqualTo:
                result = ">=";
                break;

            case FilterOperation.IsLessThan:
                result = "<";
                break;

            case FilterOperation.IsLessThanOrEqualTo:
                result = "<=";
                break;

            case FilterOperation.IsNotEmpty:
                result = "!=";
                break;

            case FilterOperation.IsNotEqualTo:
                result = "!=";
                break;

            case FilterOperation.IsNotNull:
                result = "";
                break;

            case FilterOperation.IsNull:
                result = "";
                break;

            case FilterOperation.StartsWith:
                result = "LIKE";
                break;

            case FilterOperation.IsDateEqualTo:
                result = "";
                break;

            case FilterOperation.IsDateGreaterThan:
                result = ">";
                break;

            case FilterOperation.IsDateGreaterThanOrEqualTo:
                result = ">=";
                break;

            case FilterOperation.IsDateLessThan:
                result = "<";
                break;

            case FilterOperation.IsDateLessThanOrEqualTo:
                result = "<=";
                break;

            case FilterOperation.IsDateNotEqualTo:
                result = "!=";
                break;

            default:
                break;
            }
            return(result);
        }
Example #13
0
        public static string GetOperationValue(FilterOperation operationName, object operationValue)
        {
            string result = null;

            switch (operationName)
            {
            case FilterOperation.Contains:
                result = string.Format("%{0}%", operationValue.ToString());
                break;

            case FilterOperation.DoesNotContain:
                result = string.Format("%{0}%", operationValue.ToString());
                break;

            case FilterOperation.EndsWith:
                result = string.Format("%{0}", operationValue.ToString());
                break;

            case FilterOperation.IsContainedIn:
                result = string.Format("({0})", operationValue.ToString());
                break;

            case FilterOperation.IsEmpty:
                result = "";
                break;

            case FilterOperation.IsEqualTo:
                result = operationValue.ToString();
                break;

            case FilterOperation.IsGreaterThan:
                result = operationValue.ToString();
                break;

            case FilterOperation.IsGreaterThanOrEqualTo:
                result = operationValue.ToString();
                break;

            case FilterOperation.IsLessThan:
                result = operationValue.ToString();
                break;

            case FilterOperation.IsLessThanOrEqualTo:
                result = operationValue.ToString();
                break;

            case FilterOperation.IsNotEmpty:
                result = operationValue.ToString();
                break;

            case FilterOperation.IsNotEqualTo:
                result = operationValue.ToString();
                break;

            case FilterOperation.IsNotNull:
                result = "IS NOT NULL";
                break;

            case FilterOperation.IsNull:
                result = "IS NULL";
                break;

            case FilterOperation.StartsWith:
                result = string.Format("{0}%", operationValue.ToString());
                break;

            case FilterOperation.IsDateEqualTo:
                result = GetDateTimeStringForOracle(operationValue.ToString());
                break;

            case FilterOperation.IsDateGreaterThan:
                result = GetDateTimeStringForOracle(operationValue.ToString());
                break;

            case FilterOperation.IsDateGreaterThanOrEqualTo:
                result = GetDateTimeStringForOracle(operationValue.ToString());
                break;

            case FilterOperation.IsDateLessThan:
                result = GetDateLessThanStringForOracle(operationValue.ToString());
                break;

            case FilterOperation.IsDateLessThanOrEqualTo:
                result = GetDateLessThanStringForOracle(operationValue.ToString());
                break;

            case FilterOperation.IsDateNotEqualTo:
                result = GetDateTimeStringForOracle(operationValue.ToString());
                break;

            default:
                break;
            }
            return(result);
        }
Example #14
0
        public static string GetParamExpression(FilterOperation operation, string paramName)
        {
            string paramExpression = DBFactory.SqlSign + paramName;

            switch (operation)
            {
            case FilterOperation.Contains:
                break;

            case FilterOperation.DoesNotContain:
                break;

            case FilterOperation.EndsWith:
                break;

            case FilterOperation.IsContainedIn:
                break;

            case FilterOperation.IsEmpty:
                break;

            case FilterOperation.IsEqualTo:
                break;

            case FilterOperation.IsGreaterThan:
                break;

            case FilterOperation.IsGreaterThanOrEqualTo:
                break;

            case FilterOperation.IsLessThan:
                break;

            case FilterOperation.IsLessThanOrEqualTo:
                break;

            case FilterOperation.IsNotEmpty:
                break;

            case FilterOperation.IsNotEqualTo:
                break;

            case FilterOperation.IsNotNull:
                break;

            case FilterOperation.IsNull:
                break;

            case FilterOperation.StartsWith:
                break;

            case FilterOperation.IsDateEqualTo:
                paramExpression = string.Format("- TO_DATE({0}{1},'yyyy-MM-dd') BETWEEN 0 AND 1", DBFactory.SqlSign, paramName);
                break;

            case FilterOperation.IsDateGreaterThan:
                paramExpression = string.Format("TO_DATE({0}{1},'yyyy-MM-dd')", DBFactory.SqlSign, paramName);
                break;

            case FilterOperation.IsDateGreaterThanOrEqualTo:
                paramExpression = string.Format("TO_DATE({0}{1},'yyyy-MM-dd')", DBFactory.SqlSign, paramName);
                break;

            case FilterOperation.IsDateLessThan:
                paramExpression = string.Format("TO_DATE({0}{1},'yyyy-MM-dd hh24:mi:ss')", DBFactory.SqlSign, paramName);
                break;

            case FilterOperation.IsDateLessThanOrEqualTo:
                paramExpression = string.Format("TO_DATE({0}{1},'yyyy-MM-dd hh24:mi:ss')", DBFactory.SqlSign, paramName);
                break;

            case FilterOperation.IsDateNotEqualTo:
                paramExpression = string.Format("TO_DATE({0}{1},'yyyy-MM-dd')", DBFactory.SqlSign, paramName);
                break;

            default:
                break;
            }
            return(paramExpression);
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PluginFilter"/> class.
 /// </summary>
 /// <param name="filterOp">The filter operatrion</param>
 /// <param name="operationData">The data needed for the operation</param>
 /// <param name="subFilters">The sub filters.</param>
 internal PluginFilter(FilterOperation filterOp, string operationData = null, PluginFilter[] subFilters = null)
 {
     this.Operation     = filterOp;
     this.OperationData = operationData;
     this.SubFilters    = subFilters;
 }
Example #16
0
 public FilterCondition(QueryToken token, FilterOperation operation, object value)
 {
     this.Token     = token;
     this.Operation = operation;
     this.Value     = ReflectionTools.ChangeType(value, operation.IsList() ? typeof(IEnumerable <>).MakeGenericType(Token.Type.Nullify()) : Token.Type);
 }
 public GenerationQualifier(FilterOperation op, Value value)
 {
     internalMap[Qualifier.FIELD] = QueryEngine.Meta.GENERATION;
     internalMap[OPERATION] = op;
     internalMap[VALUE1] = value;
 }
Example #18
0
 public static bool IsList(this FilterOperation fo)
 {
     return(fo == FilterOperation.IsIn || fo == FilterOperation.IsNotIn);
 }
 public FilterOperationAttribute(FilterOperation operation, FuzzyMatchMode mode)
 {
     Operation = operation;
     FuzzyMode = mode;
 }
Example #20
0
 /// <summary>
 /// Sets the next node.
 /// </summary>
 /// <param name="operation">The operation to join the nodes.</param>
 /// <param name="filter">The filter of the next node.</param>
 /// <returns>The next node.</returns>
 public ClassFilterNode SetNext(FilterOperation operation, ClassFilter filter)
 {
     this._Operation = operation;
     this._Next      = new ClassFilterNode(filter);
     return(this._Next);
 }
 protected abstract bool TryCreateExpression(
     FilterOperation operation,
     Expression property,
     Func <object> parseValue,
     out Expression expression);
Example #22
0
 public Filter(string attributeName, string value, FilterOperation operation, AttributeTypes attributeType)
     : this(attributeName, value, operation)
 {
     AttributeType = attributeType;
 }
Example #23
0
 public FilterEntity(FilterOperation filterOperation)
 {
     this.filterOperation = filterOperation;
 }
Example #24
0
 public virtual IEnumerable <T> FilterList(IEnumerable <T> items, bool sortDescending, FilterOperation operation, string[] filterValues)
 {
     return(items);
 }
Example #25
0
 public Filter(QueryToken token, FilterOperation operation, object value)
 {
     this.token     = token;
     this.operation = operation;
     this.value     = ReflectionTools.ChangeType(value, operation == FilterOperation.IsIn ? typeof(IEnumerable <>).MakeGenericType(Token.Type.Nullify()) : Token.Type);
 }
Example #26
0
 public Qualifier(String field, FilterOperation operation, Value value1, Value value2)
     : this(field, operation, value1)
 {
     internalMap[VALUE2] = value2;
 }
Example #27
0
 public ColumnFilterState(object filterValue, FilterOperation filterOperation)
 {
     FilterValue     = filterValue;
     FilterOperation = filterOperation;
 }
Example #28
0
 public static FilterExpression <T, TProperty> Create <T, TProperty>(PropertyExpression <T, TProperty> property, FilterOperation comparison, TProperty value)
 {
     return(new FilterExpression <T, TProperty>(property, comparison, value));
 }
        /// <summary>
        /// Populates an Instance of DynamicQueryOptions from parsed query string values.
        /// </summary>
        /// <param name="dynamicQueryOptions">DynamicQueryOptions ref to populate to.</param>
        /// <param name="operations">Operations array.</param>
        /// <param name="parameterNames">ParameterNames array.</param>
        /// <param name="parameterValues">ParameterValues array.</param>
        /// <param name="sortOptions">SortOptions array.</param>
        /// <param name="offsetOptions">Offset array.</param>
        /// <param name="countOptions">Count array.</param>
        /// <param name="opShortCodes">CustomOpCodes instance.</param>
        internal static void PopulateDynamicQueryOptions(
            DynamicQueryOptions dynamicQueryOptions,
            string[] operations,
            string[] parameterNames,
            string[] parameterValues,
            string[] sortOptions,
            string[] offsetOptions,
            string[] countOptions,
            CustomOpCodes opShortCodes             = null,
            DynamicQueryOptions memberQueryOptions = null)
        {
            if (dynamicQueryOptions == null)
            {
                throw new DynamicQueryException("DynamicQueryOptions should not be null");
            }

            // Check the counts for every operation, since they work in tuples they should be the same.
            if (AreCountsMatching(operations, parameterNames, parameterValues))
            {
                for (int i = 0; i < operations.Length; i++)
                {
                    FilterOperation foundOperation = default(FilterOperation);

                    // Check if we support this operation.
                    if (Enum.TryParse(operations[i], true, out FilterOperation parsedOperation))
                    {
                        foundOperation = parsedOperation;
                    }
                    else if (opShortCodes != null &&
                             opShortCodes.Count > 0 &&
                             opShortCodes.TryGetValue(operations[i], out FilterOperation shortCodeOperation)) // Whoop maybe its a short code ?
                    {
                        foundOperation = shortCodeOperation;
                    }
                    else
                    {
                        throw new OperationNotSupportedException($"Invalid operation {operations[i]}");
                    }

                    string[] splittedParameterName = parameterNames[i].Split(PARAMETER_OPTION_DELIMITER);
                    bool     isCaseSensitive       = false;
                    if (splittedParameterName.Length > 1)
                    {
                        if (splittedParameterName[1].ToLower() == CASE_SENSITIVITY_PARAMETER_OPTION)
                        {
                            isCaseSensitive = true;
                        }
                        else
                        {
                            throw new InvalidDynamicQueryException($"Invalid extra option provided for filter property {splittedParameterName[0]}. Received value was {splittedParameterName[1]}");
                        }
                    }


                    var composedFilter = new Filter
                    {
                        Operator      = foundOperation,
                        PropertyName  = splittedParameterName[0],
                        CaseSensitive = isCaseSensitive
                    };

                    if (foundOperation >= FilterOperation.Any)
                    {
                        composedFilter.Value = memberQueryOptions;
                    }
                    else
                    {
                        composedFilter.Value = parameterValues[i];
                    }

                    dynamicQueryOptions.Filters.Add(composedFilter);
                }
            }
            else
            {
                throw new QueryTripletsMismatchException("Invalid query structure. Operation, parameter name and value triplets are not matching.");
            }

            if (sortOptions != null && sortOptions.Length >= 1)
            {
                foreach (string sortOption in sortOptions)
                {
                    if (!string.IsNullOrEmpty(sortOption))
                    {
                        // Split the property name to sort and the direction.
                        string[] splittedParam = sortOption.Split(PARAMETER_OPTION_DELIMITER);

                        bool             isCaseSensitive = false;
                        SortingDirection direction       = SortingDirection.Asc;
                        if (splittedParam.Length == 2)
                        {
                            // If we get an array of 2 we have a sorting direction, try to apply it.
                            if (!Enum.TryParse(splittedParam[1], true, out direction))
                            {
                                throw new InvalidDynamicQueryException("Invalid sorting direction");
                            }
                        }
                        else if (splittedParam.Length == 3)
                        {
                            if (splittedParam[2].ToLower() == CASE_SENSITIVITY_PARAMETER_OPTION)
                            {
                                isCaseSensitive = true;
                            }
                            else
                            {
                                throw new InvalidDynamicQueryException($"Invalid extra option provided for sort property {splittedParam[0]}. Received value was {splittedParam[2]}");
                            }
                        }
                        else if (splittedParam.Length > 3) // If we get more than 3 results in the array, url must be wrong.
                        {
                            throw new InvalidDynamicQueryException("Invalid query structure. SortOption is misformed");
                        }

                        // Create the sorting option.
                        dynamicQueryOptions.SortOptions.Add(new SortOption
                        {
                            SortingDirection = direction,
                            PropertyName     = splittedParam[0],
                            CaseSensitive    = isCaseSensitive
                        });
                    }
                }
            }

            if (offsetOptions != null &&
                countOptions != null &&
                countOptions.Length > 0 &&
                offsetOptions.Length > 0 &&
                offsetOptions.Length == countOptions.Length)
            {
                if (int.TryParse(countOptions[0], out int countValue) && // We only care about the first values.
                    int.TryParse(offsetOptions[0], out int offsetValue))
                {
                    dynamicQueryOptions.PaginationOption = new PaginationOption
                    {
                        Count  = countValue,
                        Offset = offsetValue
                    };
                }
                else
                {
                    throw new DynamicQueryException("Invalid pagination options");
                }
            }
        }
Example #30
0
        /// <summary>
        /// Adds the specified filtering field.
        /// </summary>
        /// <param name="field">The filtering field.</param>
        /// <param name="value">The filtering value.</param>
        /// <param name="operation">The filtering operation.</param>
        public void Add(string field, object value, FilterOperation operation = FilterOperation.Equal)
        {
            var filterItem = new FilterItem(field, value, operation);

            Where.Add(filterItem);
        }
Example #31
0
        /// <summary>
        /// Adds the specified filtering field.
        /// </summary>
        /// <param name="field">The filtering field.</param>
        /// <param name="value">The filtering value.</param>
        /// <param name="operation">The filtering operation.</param>
        public void Add(string field, object value, FilterOperation operation = FilterOperation.Equal)
        {
            var filterItem = new FilterItem(field, value, operation);

            Where.Add(filterItem);
        }
Example #32
0
        public void Filter(FilterOperation filter)
        {
            List <ZTask> ZTaskList = new List <ZTask>();

            switch (taskView)
            {
            case TaskView.Home:
                ZTaskList = Home;
                break;

            case TaskView.Today:
                ZTaskList = Today;
                break;

            case TaskView.Upcoming:
                ZTaskList = Upcoming;
                break;

            case TaskView.Delayed:
                ZTaskList = Delayed;
                break;

            case TaskView.AssignedToOthers:
                ZTaskList = AssignedToOthers;
                break;
            }
            List <ZTask> FilteredZTaskList = new List <ZTask>();

            Task.Run(() =>
            {
                switch (filter)
                {
                case FilterOperation.open:
                    foreach (ZTask task in ZTaskList)
                    {
                        if (task.TaskDetails.TaskStatus == 2)
                        {
                            FilteredZTaskList.Add(task);
                        }
                    }
                    break;

                case FilterOperation.closed:
                    foreach (ZTask task in ZTaskList)
                    {
                        if (task.TaskDetails.TaskStatus == 3)
                        {
                            FilteredZTaskList.Add(task);
                        }
                    }
                    break;

                case FilterOperation.Low:
                    foreach (ZTask task in ZTaskList)
                    {
                        if (task.TaskDetails.Priority == 4)
                        {
                            FilteredZTaskList.Add(task);
                        }
                    }
                    break;

                case FilterOperation.Medium:
                    foreach (ZTask task in ZTaskList)
                    {
                        if (task.TaskDetails.Priority == 3)
                        {
                            FilteredZTaskList.Add(task);
                        }
                    }
                    break;

                case FilterOperation.High:
                    foreach (ZTask task in ZTaskList)
                    {
                        if (task.TaskDetails.Priority == 2)
                        {
                            FilteredZTaskList.Add(task);
                        }
                    }
                    break;
                }
            });
            OnOperationCompletion(FilteredZTaskList);
        }
 public Filter(FilterType filterType, string value, FilterOperation filterOperation)
 {
     FilterType      = filterType;
     Value           = value;
     FilterOperation = filterOperation;
 }
Example #34
0
 public ObjectTypeFilterRule(FilterOperation operation, string match, MatchType matchType) : base(operation, match, matchType)
 {
 }
 public SchemaFilterRule(FilterOperation operation, string match, MatchType matchType) : base(operation, match, matchType)
 {
 }
Example #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilterItem" /> class.
 /// </summary>
 /// <param name="field">The filtering field.</param>
 /// <param name="value">The filtering value.</param>
 /// <param name="operation">The filtering operation.</param>
 public FilterItem(string field, object value, FilterOperation operation = FilterOperation.Equal)
 {
     Field = field;
     Value = value;
     Operation = operation;
 }
 public FilterOperationAttribute(FilterOperation operation)
 {
     Operation = operation;
     FuzzyMode = FuzzyMatchMode.Contains;
 }
Example #38
0
 public static Expression GetCompareExpression(FilterOperation operation, Expression left, Expression right, bool inMemory = false)
 {
     switch (operation)
     {
         case FilterOperation.EqualTo: return Expression.Equal(left, right);
         case FilterOperation.DistinctTo: 
             {
                 var t = left.Type.UnNullify();
                 var mi = t.IsValueType ? miDistinctNullable : miDistinct;
                 return Expression.Call(mi.MakeGenericMethod(t), left.Nullify(), right.Nullify());
             }
         case FilterOperation.GreaterThan: return Expression.GreaterThan(left, right);
         case FilterOperation.GreaterThanOrEqual: return Expression.GreaterThanOrEqual(left, right);
         case FilterOperation.LessThan: return Expression.LessThan(left, right);
         case FilterOperation.LessThanOrEqual: return Expression.LessThanOrEqual(left, right);
         case FilterOperation.Contains: return Expression.Call(Fix(left, inMemory), miContains, right);
         case FilterOperation.StartsWith: return Expression.Call(Fix(left, inMemory), miStartsWith, right);
         case FilterOperation.EndsWith: return Expression.Call(Fix(left, inMemory), miEndsWith, right);
         case FilterOperation.Like: return Expression.Call(miLike, Fix(left, inMemory), right);
         case FilterOperation.NotContains: return Expression.Not(Expression.Call(Fix(left, inMemory), miContains, right));
         case FilterOperation.NotStartsWith: return Expression.Not(Expression.Call(Fix(left, inMemory), miStartsWith, right));
         case FilterOperation.NotEndsWith: return Expression.Not(Expression.Call(Fix(left, inMemory), miEndsWith, right));
         case FilterOperation.NotLike: return Expression.Not(Expression.Call(miLike, Fix(left, inMemory), right));
         default:
             throw new InvalidOperationException("Unknown operation {0}".Formato(operation));
     }
 }
Example #39
0
        public Predicate <object> MakePredicate(DataSchema dataSchema, Type columnType)
        {
            object operandValue = GetOperandValue(dataSchema, columnType);

            return(columnValue => FilterOperation.Matches(dataSchema, columnType, columnValue, operandValue));
        }
        private static Expression GetFilterExpressionLambda(Expression left, Expression right, FilterOperation operation)
        {
            Expression body;

            switch (operation)
            {
            case FilterOperation.eq:
                // {model.Id == 1}
                body = Expression.Equal(left, right);
                break;

            case FilterOperation.lt:
                // {model.Id < 1}
                body = Expression.LessThan(left, right);
                break;

            case FilterOperation.gt:
                // {model.Id > 1}
                body = Expression.GreaterThan(left, right);
                break;

            case FilterOperation.le:
                // {model.Id <= 1}
                body = Expression.LessThanOrEqual(left, right);
                break;

            case FilterOperation.ge:
                // {model.Id >= 1}
                body = Expression.GreaterThanOrEqual(left, right);
                break;

            case FilterOperation.like:
                body = Expression.Call(left, "Contains", null, right);
                break;

            // {model.Id != 1}
            case FilterOperation.ne:
                body = Expression.NotEqual(left, right);
                break;

            case FilterOperation.isnotnull:
                // {model.Id != null}
                if (left.Type.IsValueType &&
                    !(left.Type.IsGenericType && left.Type.GetGenericTypeDefinition() == typeof(Nullable <>)))
                {
                    var nullableType = typeof(Nullable <>).MakeGenericType(left.Type);
                    body = Expression.NotEqual(Expression.Convert(left, nullableType), right);
                }
                else
                {
                    body = Expression.NotEqual(left, right);
                }
                break;

            case FilterOperation.isnull:
                // {model.Id == null}
                if (left.Type.IsValueType &&
                    !(left.Type.IsGenericType && left.Type.GetGenericTypeDefinition() == typeof(Nullable <>)))
                {
                    var nullableType = typeof(Nullable <>).MakeGenericType(left.Type);
                    body = Expression.Equal(Expression.Convert(left, nullableType), right);
                }
                else
                {
                    body = Expression.Equal(left, right);
                }
                break;

            default:
                throw new JsonApiException(500, $"Unknown filter operation {operation}");
            }

            return(body);
        }
 protected abstract bool TryCreateExpression(
     FilterOperation operation,
     MemberExpression property,
     object parsedValue,
     out Expression expression);
Example #42
0
 public Filter(QueryToken token, FilterOperation operation, object value)
 {
     this.token = token;
     this.operation = operation;
     this.value = ReflectionTools.ChangeType(value, operation == FilterOperation.IsIn ? typeof(IEnumerable<>).MakeGenericType(Token.Type.Nullify()) : Token.Type);
 }