예제 #1
0
파일: SortBuilder.cs 프로젝트: zxbe/squidex
        public static SortDefinition <T> BuildSort <T>(this ODataUriParser query, ConvertProperty propertyCalculator = null)
        {
            var orderBy = query.ParseOrderBy();

            if (orderBy != null)
            {
                var sorts = new List <SortDefinition <T> >();

                while (orderBy != null)
                {
                    sorts.Add(OrderBy <T>(orderBy, propertyCalculator));

                    orderBy = orderBy.ThenBy;
                }

                if (sorts.Count > 1)
                {
                    return(Builders <T> .Sort.Combine(sorts));
                }
                else
                {
                    return(sorts[0]);
                }
            }

            return(null);
        }
예제 #2
0
        public static string BuildFieldDefinition(this QueryNode node, ConvertProperty convertProperty)
        {
            convertProperty = convertProperty ?? Default;

            var propertyParts = node.Accept(PropertyNameVisitor.Instance).ToArray();
            var propertyName  = convertProperty(propertyParts);

            return(propertyName);
        }
예제 #3
0
파일: SortBuilder.cs 프로젝트: zxbe/squidex
        public static SortDefinition <T> OrderBy <T>(OrderByClause clause, ConvertProperty propertyCalculator = null)
        {
            var propertyName = clause.Expression.BuildFieldDefinition(propertyCalculator);

            if (clause.Direction == OrderByDirection.Ascending)
            {
                return(Builders <T> .Sort.Ascending(propertyName));
            }
            else
            {
                return(Builders <T> .Sort.Descending(propertyName));
            }
        }
예제 #4
0
 public static (FilterDefinition <T> Filter, bool Last) BuildFilter <T>(this ODataUriParser query, ConvertProperty convertProperty = null, ConvertValue convertValue = null, bool supportsSearch = true)
 {
예제 #5
0
        public static FilterDefinition <MongoContentEntity> BuildQuery(ODataUriParser query, Guid schemaId, Status[] status, ConvertProperty propertyCalculator)
        {
            var filters = new List <FilterDefinition <MongoContentEntity> >
            {
                Filter.Eq(x => x.IndexedSchemaId, schemaId),
            };

            if (status != null)
            {
                filters.Add(Filter.Ne(x => x.IsDeleted, true));
                filters.Add(Filter.In(x => x.Status, status));
            }

            var filter = query.BuildFilter <MongoContentEntity>(propertyCalculator);

            if (filter.Filter != null)
            {
                if (filter.Last)
                {
                    filters.Add(filter.Filter);
                }
                else
                {
                    filters.Insert(0, filter.Filter);
                }
            }

            if (filters.Count == 1)
            {
                return(filters[0]);
            }
            else
            {
                return(Filter.And(filters));
            }
        }
예제 #6
0
        public static IFindFluent <MongoContentEntity, MongoContentEntity> ContentSort(this IFindFluent <MongoContentEntity, MongoContentEntity> cursor, ODataUriParser query, ConvertProperty propertyCalculator)
        {
            var sort = query.BuildSort <MongoContentEntity>(propertyCalculator);

            return(sort != null?cursor.Sort(sort) : cursor.SortByDescending(x => x.LastModified));
        }
예제 #7
0
        public static FilterDefinition <T> Visit(QueryNode node, ConvertProperty propertyCalculator, ConvertValue convertValue)
        {
            var visitor = new FilterVisitor <T>(propertyCalculator, convertValue);

            return(node.Accept(visitor));
        }
예제 #8
0
 private FilterVisitor(ConvertProperty convertProperty, ConvertValue convertValue)
 {
     this.convertProperty = convertProperty;
     this.convertValue    = convertValue;
 }