Ejemplo n.º 1
0
        /// <summary>
        /// Adds sort by a property which describes by <paramref name="func"/> in <paramref name="direction"/> order.
        /// </summary>
        public SortSettingsBuilder <TEntity> AddOrderBy(LambdaExpression func, SortOrder direction)
        {
            var rule = new SortRule(direction, func);

            sortRules.Add(rule);
            return(this);
        }
 public void Setup(string name, SortRule sortRule, Action <string> onElementDoubleClick)
 {
     m_foldoutName = name;
     SetFoldoutName(name);
     m_sortRule             = sortRule;
     m_onElementDoubleClick = onElementDoubleClick;
 }
Ejemplo n.º 3
0
        public void Orders_Test()
        {
            var ci = GetContainer();
            IOrderRepository rep      = ci.Resolve <IOrderRepository>();
            bool             isExists = rep.Exists(o => o.OrderNo.Equals("66666588888"));

            Console.WriteLine(isExists);

            int total = 0;
            var sorts = new SortRule[1];

            sorts[0] = new SortRule()
            {
                PropertyName = "OrderNo",
                IsDesc       = false
            };

            var pagedList = rep.FindPageList(new PagedQuery()
            {
                PageIndex = 2, PageSize = 2
            }, null, sorts);
            var orders = pagedList.Rows;

            foreach (var order in orders)
            {
                Console.WriteLine(order.OrderNo);
            }
            Console.WriteLine("total:" + total);
        }
Ejemplo n.º 4
0
        private SelectQueryDefinition BuildSort(Select select)
        {
            var sort = Sort.RELEVANCE;

            if (!select.Sort.Any())
            {
                SortRule sortOneCreateDate = new SortRule
                {
                    Field      = "createdondate",
                    FieldType  = FieldTypeEnum.DATETIME,
                    Descending = false
                };
                select.Sort.Add(sortOneCreateDate);
            }

            var sortFields = new List <SortField>();

            foreach (var rule in select.Sort)
            {
                int    sortfieldtype;
                string sortFieldPrefix = "";
                Sortfieldtype(rule.FieldType, out sortfieldtype, ref sortFieldPrefix);

                if (rule.Field == "createdondate")
                {
                    rule.Field = "$createdondate";
                }

                sortFields.Add(new SortField(sortFieldPrefix + rule.Field, sortfieldtype, rule.Descending));
            }
            sort = new Sort(sortFields.ToArray());

            Sort = sort;
            return(this);
        }
Ejemplo n.º 5
0
        private static Sort BuildSort(Select select)
        {
            var sortFields = new List <SortField>();

            if (!select.Sort.Any())
            {
                // if no sorting is specified, then sort on score and on sortOnCreateDate
                sortFields.Add(SortField.FIELD_SCORE);

                var sortOnCreateDate = new SortRule
                {
                    Field      = "createdondate",
                    FieldType  = FieldTypeEnum.DATETIME,
                    Descending = false
                };
                select.Sort.Add(sortOnCreateDate);
            }

            foreach (var rule in select.Sort)
            {
                int    sortfieldtype;
                string sortFieldPrefix = "";
                Sortfieldtype(rule.FieldType, out sortfieldtype, ref sortFieldPrefix);

                if (rule.Field == "createdondate")
                {
                    rule.Field = "$createdondate";
                }

                sortFields.Add(new SortField(sortFieldPrefix + rule.Field, sortfieldtype, rule.Descending));
            }
            var sort = new Sort(sortFields.ToArray());

            return(sort);
        }
Ejemplo n.º 6
0
 public void SortOrder_Success <TKey>(
     SortRule <IEntity <TKey>, TKey> sortRule,
     SortOrder expectedSortOrder)
 {
     // Arrange & Act & Assert
     Assert.Equal(expectedSortOrder, sortRule?.SortOrder);
 }
Ejemplo n.º 7
0
        public List <Item> Sort(List <Item> source, List <POINT> used, int length)
        {
            SortRule    rule  = new SortRule(Config);
            List <Item> clone = new List <Item>();

            source.ForEach(x => clone.Add((Item)x.Clone()));
            List <Item> item_1x1 = clone.Where(x => x.w * x.h == 1).ToList();

            item_1x1 = item_1x1.OrderBy(s => s, rule).ToList();

            List <POINT> free = new List <POINT>();
            var          temp = item_1x1.Select(x => x.point).ToList();

            foreach (POINT _temp in temp)
            {
                used.Remove(_temp);
            }
            int index = 0;

            for (int x = 0; x < length; x++)
            {
                for (int y = 0; y < length; y++)
                {
                    if (Config.Direction == "Vertical")
                    {
                        if (used.Where(a => a.X == x && a.Y == y).Any())
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (used.Where(a => a.X == y && a.Y == x).Any())
                        {
                            continue;
                        }
                    }
                    if (index < item_1x1.Count)
                    {
                        if (Config.Direction == "Vertical")
                        {
                            item_1x1[index].point = new POINT(x, y);
                        }
                        else
                        {
                            item_1x1[index].point = new POINT(y, x);
                        }
                        index++;
                    }
                }
            }
            List <Item> resoult = new List <Item>();

            resoult.AddRange(item_1x1);
            resoult.AddRange(source.Where(x => x.w * x.h != 1).ToList());


            return(resoult);
        }
Ejemplo n.º 8
0
 public void IsValid_Success <TEntity, TKey>(
     SortRule <TEntity, TKey> sortRule,
     bool expectedResult)
     where TEntity : class, IEntity <TKey>
 {
     // Arrange & Act & Assert
     Assert.Equal(expectedResult, sortRule?.IsValid);
 }
Ejemplo n.º 9
0
        private static string GetSortingMethodName(SortRule sortRule, bool initialSorting)
        {
            if (initialSorting)
            {
                return(sortRule.SortDirection == Shared.Framework.DataSource.SortOrder.Desc ? OrderByDescendingMethod : OrderByMethod);
            }

            return(sortRule.SortDirection == Shared.Framework.DataSource.SortOrder.Desc ? ThenByDescendingMethod : ThenByMethod);
        }
Ejemplo n.º 10
0
        public void explicit_default_sort()
        {
            var definition = new GridDefinition <Case>();

            definition.ShowViewLink(x => x.Condition);
            definition.SortBy = SortRule <Case> .Descending(x => x.Created);

            definition.SortBy.FieldName.ShouldEqual("Created");
            definition.SortBy.IsAscending.ShouldBeFalse();
        }
        public void Sort_Success()
        {
            // Arrange
            var sort = new SortRule <FakeEntity, int>();

            // Act
            _queryParameters.Sort = sort;

            // Assert
            Assert.Equal(sort, _queryParameters.Sort);
        }
Ejemplo n.º 12
0
        public DrawScheduler()
            : base(new LinearScheduler <IDrawTask>(), x => new DrawTask(x))
        {
            _scheduler = (LinearScheduler <IDrawTask>)Scheduler;

            var sortRule = new SortRule <IDrawTask, float>(Scheduler.Tasks, x => x.RenderDepth, Comparer <float> .Default,
                                                           (x, h) => x.RenderDepthChanged += h, (x, h) => x.RenderDepthChanged -= h)
            {
                Weight        = 10f,
                MustBeApplied = true
            };

            Scheduler.Rules.Add(sortRule);
        }
Ejemplo n.º 13
0
        public static SortRule CreateSortRule(FieldConfig config, string cultureCode, string field, bool descending)
        {
            var fieldConfig   = GetField(config, field);
            var cultureSuffix = fieldConfig != null && fieldConfig.MultiLanguage ? "." + cultureCode : string.Empty;
            var indexType     = GetFieldType(fieldConfig != null ? fieldConfig.IndexType : string.Empty);
            var rule          = new SortRule()
            {
                Field      = field + cultureSuffix,
                FieldType  = indexType,
                Descending = descending
            };

            return(rule);
        }
Ejemplo n.º 14
0
        private IQueryable <TEntity> ApplySortSettingsIfExist <TEntity>(IQueryable <TEntity> queryable, QueryParameters parameters)
            where TEntity : Entity
        {
            if (parameters.SortSettings != null && parameters.SortSettings.SortRules != null &&
                parameters.SortSettings.SortRules.Any())
            {
                SortRule initialSortingRule = parameters.SortSettings.SortRules.First();
                queryable = ApplySortingRule(queryable, initialSortingRule, true);

                queryable = parameters.SortSettings.SortRules.Skip(1)
                            .Aggregate(queryable,
                                       (current, sortRule) => ApplySortingRule(current, sortRule));
            }
            return(queryable);
        }
Ejemplo n.º 15
0
        public void do_override_sorting_if_no_sorting_exists()
        {
            var rule = SortRule <Case> .Ascending(x => x.Condition);

            var request = new GridDataRequest()
            {
                SortColumn    = null,
                SortAscending = false
            };

            rule.ApplyDefaultSorting(request);

            request.SortColumn.ShouldEqual("Condition");
            request.SortAscending.ShouldBeTrue();
        }
Ejemplo n.º 16
0
        public void do_not_override_sorting_if_it_exists()
        {
            var rule = SortRule <Case> .Ascending(x => x.Condition);

            var request = new GridDataRequest()
            {
                SortColumn    = "different",
                SortAscending = false
            };

            rule.ApplyDefaultSorting(request);

            request.SortColumn.ShouldEqual("different");
            request.SortAscending.ShouldBeFalse();
        }
Ejemplo n.º 17
0
        public static List <T> ToNumberList <T>(this string[] data, SortRule sortDirection = SortRule.NoSort)
        {
            if (data == null || !data.Any())
            {
                throw new ArgumentNullException(nameof(data));
            }

            return(typeof(T).Name switch
            {
                "Int16" => data.Select(x => short.Parse(x)).Sort(sortDirection) as List <T>,
                "Int32" => data.Select(x => int.Parse(x)).Sort(sortDirection) as List <T>,
                "Int64" => data.Select(x => long.Parse(x)).Sort(sortDirection) as List <T>,
                "Decimal" => data.Select(x => decimal.Parse(x)).Sort(sortDirection) as List <T>,
                "Single" => data.Select(x => float.Parse(x)).Sort(sortDirection) as List <T>,
                _ => throw new ArgumentException($"A non-numeric type was attempted to be converted. Requested Type: {typeof(T).Name}. Accepted types: short, int, long, decimal and float.", nameof(data)),
            });
Ejemplo n.º 18
0
        public static SortRule CreateSortRule(FieldConfig parentFieldConfig, string cultureCode, string field, bool descending)
        {
            var fieldConfig   = GetField(parentFieldConfig, field);
            var cultureSuffix = fieldConfig != null && fieldConfig.MultiLanguage ? "." + cultureCode : string.Empty;
            var indexType     = GetFieldType(fieldConfig != null ? fieldConfig.IndexType : string.Empty);

            if (field == JsonMappingUtils.FIELD_TIMESTAMP)
            {
                indexType = FieldTypeEnum.DATETIME;
            }

            var rule = new SortRule()
            {
                Field      = field + cultureSuffix,
                FieldType  = indexType,
                Descending = descending
            };

            return(rule);
        }
Ejemplo n.º 19
0
 public SortRuleTests()
 {
     _sortRule = new SortRule <FakeEntity, int>();
 }
Ejemplo n.º 20
0
 public void SortDescending(Expression <Func <TEntity, object> > property)
 {
     _definition.SortBy = SortRule <TEntity> .Descending(property);
 }
Ejemplo n.º 21
0
        private IQueryable <TEntity> ApplySortingRule <TEntity>(IQueryable <TEntity> queryable, SortRule sortRule,
                                                                bool initialSorting = false)
            where TEntity : Entity
        {
            string methodName = GetSortingMethodName(sortRule, initialSorting);

            MethodCallExpression resultExp = Expression.Call(typeof(Queryable), methodName, new[]
            {
                typeof(TEntity),
                sortRule.Expression
                .ReturnType
            }, queryable.Expression,
                                                             Expression.Quote(sortRule.Expression));

            return(queryable.Provider.CreateQuery <TEntity>(resultExp));
        }