Exemplo n.º 1
0
        public void AddColumnsFromFilter(QueryFilter filter)
        {
            SinglePropertyFilter singlePropertyFilter = filter as SinglePropertyFilter;

            if (singlePropertyFilter != null)
            {
                this.AddColumn(singlePropertyFilter.Property);
                return;
            }
            CompositeFilter compositeFilter = filter as CompositeFilter;

            if (compositeFilter != null)
            {
                foreach (QueryFilter filter2 in compositeFilter.Filters)
                {
                    this.AddColumnsFromFilter(filter2);
                }
                return;
            }
            NotFilter notFilter = filter as NotFilter;

            if (notFilter != null)
            {
                this.AddColumnsFromFilter(notFilter.Filter);
                return;
            }
            PropertyComparisonFilter propertyComparisonFilter = filter as PropertyComparisonFilter;

            if (propertyComparisonFilter != null)
            {
                this.AddColumn(propertyComparisonFilter.Property1);
                this.AddColumn(propertyComparisonFilter.Property2);
                return;
            }
            CommentFilter commentFilter = filter as CommentFilter;

            if (commentFilter != null)
            {
                this.AddColumnsFromFilter(commentFilter.Filter);
                return;
            }
            if (filter is FalseFilter || filter is TrueFilter)
            {
                return;
            }
            throw new NotSupportedException();
        }
Exemplo n.º 2
0
        private static bool EvaluatePropertyComparisonFilter(PropertyComparisonFilter propertyComparisonFilter, IReadOnlyPropertyBag propertyBag, bool shouldThrow)
        {
            object obj  = propertyBag[propertyComparisonFilter.Property1];
            object obj2 = propertyBag[propertyComparisonFilter.Property2];

            if (obj is PropertyError || obj2 is PropertyError)
            {
                if (shouldThrow)
                {
                    throw PropertyErrorException.FromPropertyErrorsInternal(new PropertyError[]
                    {
                        obj as PropertyError,
                        obj2 as PropertyError
                    });
                }
                return(false);
            }
            else
            {
                switch (propertyComparisonFilter.ComparisonOperator)
                {
                case ComparisonOperator.Equal:
                    return(obj.Equals(obj2));

                case ComparisonOperator.NotEqual:
                    return(!obj.Equals(obj2));

                case ComparisonOperator.LessThan:
                    if (obj is ExDateTime)
                    {
                        return((ExDateTime)obj < (ExDateTime)obj2);
                    }
                    if (obj is int)
                    {
                        return((int)obj < (int)obj2);
                    }
                    if (obj is long)
                    {
                        return((long)obj < (long)obj2);
                    }
                    throw new InvalidOperationException("Only int, long, and ExDateTime supported for PropertyComparisonFilter <");

                case ComparisonOperator.LessThanOrEqual:
                    if (obj is ExDateTime)
                    {
                        return((ExDateTime)obj <= (ExDateTime)obj2);
                    }
                    if (obj is int)
                    {
                        return((int)obj <= (int)obj2);
                    }
                    if (obj is long)
                    {
                        return((long)obj <= (long)obj2);
                    }
                    throw new InvalidOperationException("Only int, long, and ExDateTime supported for PropertyComparisonFilter <=");

                case ComparisonOperator.GreaterThan:
                    if (obj is ExDateTime)
                    {
                        return((ExDateTime)obj > (ExDateTime)obj2);
                    }
                    if (obj is int)
                    {
                        return((int)obj > (int)obj2);
                    }
                    if (obj is long)
                    {
                        return((long)obj > (long)obj2);
                    }
                    throw new InvalidOperationException("Only int, long, and ExDateTime supported for PropertyComparisonFilter >");

                case ComparisonOperator.GreaterThanOrEqual:
                    if (obj is ExDateTime)
                    {
                        return((ExDateTime)obj >= (ExDateTime)obj2);
                    }
                    if (obj is int)
                    {
                        return((int)obj >= (int)obj2);
                    }
                    if (obj is long)
                    {
                        return((long)obj >= (long)obj2);
                    }
                    throw new InvalidOperationException("Only int, long, and ExDateTime supported for PropertyComparisonFilter >=");

                default:
                    throw new InvalidOperationException("Unsupported ComparisonOperator: " + ((int)propertyComparisonFilter.ComparisonOperator).ToString());
                }
            }
        }
Exemplo n.º 3
0
 internal ComparePropertyRestrictionData(StoreSession storeSession, PropertyComparisonFilter filter)
 {
     this.RelOp    = base.GetRelOpFromComparisonOperator(filter.ComparisonOperator);
     this.TagLeft  = base.GetPropTagFromDefinition(storeSession, filter.Property1);
     this.TagRight = base.GetPropTagFromDefinition(storeSession, filter.Property2);
 }
Exemplo n.º 4
0
        public static bool Evaluate(QueryFilter filter, IReadOnlyPropertyBag propertyBag, bool shouldThrow)
        {
            AndFilter andFilter = filter as AndFilter;

            if (andFilter != null)
            {
                return(EvaluatableFilter.EvaluateAndFilter(andFilter, propertyBag, shouldThrow));
            }
            OrFilter orFilter = filter as OrFilter;

            if (orFilter != null)
            {
                return(EvaluatableFilter.EvaluateOrFilter(orFilter, propertyBag, shouldThrow));
            }
            NotFilter notFilter = filter as NotFilter;

            if (notFilter != null)
            {
                return(!EvaluatableFilter.Evaluate(notFilter.Filter, propertyBag, shouldThrow));
            }
            TextFilter textFilter = filter as TextFilter;

            if (textFilter != null)
            {
                return(EvaluatableFilter.EvaluateTextFilter(textFilter, propertyBag, shouldThrow));
            }
            ComparisonFilter comparisonFilter = filter as ComparisonFilter;

            if (comparisonFilter != null)
            {
                return(EvaluatableFilter.EvaluateComparisonFilter(comparisonFilter, propertyBag, shouldThrow));
            }
            if (filter is TrueFilter)
            {
                return(true);
            }
            if (filter is FalseFilter)
            {
                return(false);
            }
            CommentFilter commentFilter = filter as CommentFilter;

            if (commentFilter != null)
            {
                return(EvaluatableFilter.Evaluate(commentFilter.Filter, propertyBag, shouldThrow));
            }
            BitMaskFilter bitMaskFilter = filter as BitMaskFilter;

            if (bitMaskFilter != null)
            {
                return(EvaluatableFilter.EvaluateBitMaskFilter(bitMaskFilter, propertyBag, shouldThrow));
            }
            ExistsFilter existsFilter = filter as ExistsFilter;

            if (existsFilter != null)
            {
                return(EvaluatableFilter.EvaluateExistsFilter(existsFilter, propertyBag));
            }
            PropertyComparisonFilter propertyComparisonFilter = filter as PropertyComparisonFilter;

            if (propertyComparisonFilter != null)
            {
                return(EvaluatableFilter.EvaluatePropertyComparisonFilter(propertyComparisonFilter, propertyBag, shouldThrow));
            }
            throw new NotImplementedException();
        }