Esempio n. 1
0
        internal static QueryFilter SimplifyFilter(QueryFilter filter)
        {
            if (filter == null)
            {
                return(null);
            }
            if (filter.IsAtomic)
            {
                return(filter);
            }
            if (!(filter is NotFilter) && !(filter is CompositeFilter))
            {
                return(filter);
            }
            NotFilter notFilter = filter as NotFilter;

            if (notFilter != null)
            {
                QueryFilter filter2 = notFilter.Filter;
                if (filter2.IsAtomic)
                {
                    return(filter);
                }
                if (filter2 is NotFilter)
                {
                    return(QueryFilter.SimplifyFilter(((NotFilter)filter2).Filter));
                }
                if (filter2 is CompositeFilter)
                {
                    CompositeFilter compositeFilter = (CompositeFilter)filter2;
                    QueryFilter[]   array           = new QueryFilter[compositeFilter.Filters.Count];
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = QueryFilter.NotFilter(compositeFilter.Filters[i]);
                    }
                    if (filter2 is AndFilter)
                    {
                        return(QueryFilter.SimplifyFilter(QueryFilter.OrTogether(array)));
                    }
                    if (filter2 is OrFilter)
                    {
                        return(QueryFilter.SimplifyFilter(QueryFilter.AndTogether(array)));
                    }
                }
                if (filter2 is ComparisonFilter)
                {
                    ComparisonFilter   comparisonFilter = (ComparisonFilter)filter2;
                    ComparisonOperator comparisonOperator;
                    switch (comparisonFilter.ComparisonOperator)
                    {
                    case ComparisonOperator.Equal:
                        comparisonOperator = ComparisonOperator.NotEqual;
                        break;

                    case ComparisonOperator.NotEqual:
                        comparisonOperator = ComparisonOperator.Equal;
                        break;

                    case ComparisonOperator.LessThan:
                        comparisonOperator = ComparisonOperator.GreaterThanOrEqual;
                        break;

                    case ComparisonOperator.LessThanOrEqual:
                        comparisonOperator = ComparisonOperator.GreaterThan;
                        break;

                    case ComparisonOperator.GreaterThan:
                        comparisonOperator = ComparisonOperator.LessThanOrEqual;
                        break;

                    case ComparisonOperator.GreaterThanOrEqual:
                        comparisonOperator = ComparisonOperator.LessThan;
                        break;

                    default:
                        return(filter);
                    }
                    return(new ComparisonFilter(comparisonOperator, comparisonFilter.Property, comparisonFilter.PropertyValue));
                }
                return(QueryFilter.NotFilter(QueryFilter.SimplifyFilter(filter2)));
            }
            else
            {
                AndFilter andFilter = filter as AndFilter;
                if (andFilter != null)
                {
                    return(QueryFilter.SimplifyCompositeFilter <AndFilter, OrFilter>(andFilter));
                }
                OrFilter orFilter = filter as OrFilter;
                if (orFilter != null)
                {
                    return(QueryFilter.SimplifyCompositeFilter <OrFilter, AndFilter>(orFilter));
                }
                return(filter);
            }
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            ComparisonFilter comparisonFilter = obj as ComparisonFilter;

            return(comparisonFilter != null && this.comparisonOperator == comparisonFilter.comparisonOperator && comparisonFilter.GetType() == base.GetType() && ComparisonFilter.PropertyValueEquals(this.propertyValue, comparisonFilter.propertyValue) && base.Equals(obj));
        }
Esempio n. 3
0
 private static void GenerateInfixString(QueryFilter filter, StringBuilder sb, FilterSchema filterSchema)
 {
     if (filter is CompositeFilter)
     {
         sb.Append("(");
         CompositeFilter compositeFilter = (CompositeFilter)filter;
         int             filterCount     = compositeFilter.FilterCount;
         for (int i = 0; i < filterCount - 1; i++)
         {
             sb.Append("(");
             QueryFilter.GenerateInfixString(compositeFilter.Filters[i], sb, filterSchema);
             sb.Append(") ");
             if (filter is AndFilter)
             {
                 sb.Append(filterSchema.And);
             }
             else if (filter is OrFilter)
             {
                 sb.Append(filterSchema.Or);
             }
             sb.Append(" ");
         }
         sb.Append("(");
         QueryFilter.GenerateInfixString(compositeFilter.Filters[filterCount - 1], sb, filterSchema);
         sb.Append("))");
         return;
     }
     if (filter is NotFilter)
     {
         NotFilter notFilter = filter as NotFilter;
         sb.Append(filterSchema.Not);
         sb.Append("(");
         QueryFilter.GenerateInfixString(notFilter.Filter, sb, filterSchema);
         sb.Append(")");
         return;
     }
     if (filter is TextFilter)
     {
         TextFilter textFilter   = filter as TextFilter;
         string     propertyName = filterSchema.GetPropertyName(textFilter.Property.Name);
         if (!string.IsNullOrEmpty(propertyName))
         {
             sb.Append(propertyName);
             sb.Append(filterSchema.Like);
         }
         if (textFilter.MatchOptions == MatchOptions.FullString || textFilter.MatchOptions == MatchOptions.ExactPhrase || filterSchema.SupportQuotedPrefix)
         {
             sb.Append(filterSchema.QuotationMark);
         }
         if (textFilter.MatchOptions == MatchOptions.Suffix || textFilter.MatchOptions == MatchOptions.SubString)
         {
             sb.Append("*");
         }
         sb.Append(filterSchema.EscapeStringValue(textFilter.Text));
         if (textFilter.MatchOptions == MatchOptions.Prefix || textFilter.MatchOptions == MatchOptions.SubString || textFilter.MatchOptions == MatchOptions.PrefixOnWords)
         {
             sb.Append("*");
         }
         if (textFilter.MatchOptions == MatchOptions.FullString || textFilter.MatchOptions == MatchOptions.ExactPhrase || filterSchema.SupportQuotedPrefix)
         {
             sb.Append(filterSchema.QuotationMark);
             return;
         }
     }
     else
     {
         if (filter is ComparisonFilter)
         {
             ComparisonFilter comparisonFilter = filter as ComparisonFilter;
             sb.Append(filterSchema.GetPropertyName(comparisonFilter.Property.Name));
             sb.Append(filterSchema.GetRelationalOperator(comparisonFilter.ComparisonOperator));
             sb.Append(filterSchema.QuotationMark);
             sb.Append(filterSchema.EscapeStringValue(comparisonFilter.PropertyValue));
             sb.Append(filterSchema.QuotationMark);
             return;
         }
         if (filter is ExistsFilter)
         {
             sb.Append(filterSchema.GetExistsFilter(filter as ExistsFilter));
             return;
         }
         if (filter is FalseFilter)
         {
             sb.Append(filterSchema.GetFalseFilter());
         }
     }
 }
Esempio n. 4
0
        private static bool FilterMatchesValue(SinglePropertyFilter filter, object value)
        {
            if (filter is ExistsFilter)
            {
                return(null != value);
            }
            if (filter is GenericBitMaskFilter)
            {
                ulong num;
                try
                {
                    num = Convert.ToUInt64(value);
                }
                catch (InvalidCastException)
                {
                    return(false);
                }
                GenericBitMaskFilter genericBitMaskFilter = filter as GenericBitMaskFilter;
                if (genericBitMaskFilter is BitMaskOrFilter)
                {
                    return(0UL != (genericBitMaskFilter.Mask & num));
                }
                if (genericBitMaskFilter is BitMaskAndFilter)
                {
                    return(genericBitMaskFilter.Mask == (genericBitMaskFilter.Mask & num));
                }
            }
            if (filter is TextFilter)
            {
                TextFilter textFilter = filter as TextFilter;
                string     text       = textFilter.Text ?? string.Empty;
                string     text2      = (value == null) ? string.Empty : value.ToString();
                if (string.IsNullOrEmpty(text2))
                {
                    return(string.IsNullOrEmpty(text));
                }
                StringComparison stringComparison = OpathFilterEvaluator.GetStringComparison(textFilter.MatchFlags);
                switch (textFilter.MatchOptions)
                {
                case MatchOptions.FullString:
                    return(text2.Equals(text, stringComparison));

                case MatchOptions.SubString:
                case MatchOptions.ExactPhrase:
                    return(-1 != text2.IndexOf(text, stringComparison));

                case MatchOptions.Prefix:
                    return(text2.StartsWith(text, stringComparison));

                case MatchOptions.Suffix:
                    return(text2.EndsWith(text, stringComparison));

                case MatchOptions.WildcardString:
                    return(OpathFilterEvaluator.MatchesWildcardString(text, text2, stringComparison));
                }
                throw new NotSupportedException("Not a currently supported Match Option: " + textFilter.MatchOptions);
            }
            else
            {
                if (!(filter is ComparisonFilter))
                {
                    throw new NotSupportedException("The specified filter type \"" + filter.GetType().Name + "\" is currently not supported.");
                }
                ComparisonFilter comparisonFilter = filter as ComparisonFilter;
                object           obj = ValueConvertor.ConvertValue(comparisonFilter.PropertyValue, comparisonFilter.Property.Type, null);
                switch (comparisonFilter.ComparisonOperator)
                {
                case ComparisonOperator.Equal:
                    return(OpathFilterEvaluator.Equals(obj, value, StringComparison.OrdinalIgnoreCase));

                case ComparisonOperator.NotEqual:
                    return(!OpathFilterEvaluator.Equals(obj, value, StringComparison.OrdinalIgnoreCase));

                case ComparisonOperator.LessThan:
                    return(0 < Comparer.Default.Compare(obj, value));

                case ComparisonOperator.LessThanOrEqual:
                    return(0 <= Comparer.Default.Compare(obj, value));

                case ComparisonOperator.GreaterThan:
                    return(0 > Comparer.Default.Compare(obj, value));

                case ComparisonOperator.GreaterThanOrEqual:
                    return(0 >= Comparer.Default.Compare(obj, value));

                default:
                    throw new NotSupportedException("Not a currently supported comparison operator: " + comparisonFilter.ComparisonOperator);
                }
            }
        }