Beispiel #1
0
        public override bool Equals(object obj)
        {
            CompositeFilter compositeFilter = obj as CompositeFilter;

            if (compositeFilter != null && compositeFilter.filters.Length == this.filters.Length && compositeFilter.GetType() == base.GetType() && compositeFilter.GetHashCode() == this.GetHashCode())
            {
                for (int i = 0; i < this.filters.Length; i++)
                {
                    if (Array.IndexOf <QueryFilter>(compositeFilter.filters, this.filters[i]) == -1)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
Beispiel #2
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);
            }
        }
Beispiel #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());
         }
     }
 }