Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public virtual IQueryable <T> ApplySorting <T>(IQueryable <T> queryable, SortingOptions <T> options) where T : SearchResultItem
        {
            if (options == null || !options.Operations.Any())
            {
                return(queryable);
            }

            // Resolve bug with Sitecore not evaluating orders correctly
            // http://www.daveleigh.co.uk/sitecore-content-search-api-thenby-clause-not-evaluating-correctly/
            //var expressions = options.Operations.Reverse();

            var operations = options.Operations as SortingOptions <T> .SortingOperation[] ?? options.Operations.ToArray();

            var orderByExpression = operations.First();

            var orderedQueryable = orderByExpression.SortOrder == SortOrder.Ascending
                ? queryable.OrderBy(orderByExpression.Expression)
                : queryable.OrderByDescending(orderByExpression.Expression);

            return(operations.Skip(1)
                   .Aggregate(orderedQueryable,
                              (current, expression) =>
                              expression.SortOrder == SortOrder.Ascending
                                         ? current.ThenBy(expression.Expression)
                                         : current.ThenByDescending(expression.Expression)));
        }
Ejemplo n.º 2
0
        public static void LoadList()
        {
            _logger.Debug("Test: LoadList()");

            var sorting = new SortingOptions<TestObject>(x => x.Name).Asc();
            var paging = new PagingOptions { ResultsPerPage = 5, Page = 0 };

            _logger.Debug("Loading page 1");
            var list = TestObject.Load(paging, sorting);
            foreach (var i in list)
            {
                _logger.Debug("Record {0}: {1}", i.Id, i.Name);
            }

            if (paging.PageCount > 1)
            {
                _logger.Debug("Loading page 2");
                paging.Page = 1;
                list = TestObject.Load(paging, sorting);
                foreach (var i in list)
                {
                    _logger.Debug("Record {0}: {1}", i.Id, i.Name);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <ServiceResult <CommentsResponseBo> > GetCommentsAsync(string postId, string commentId, int skip, int limit)
        {
            var pagingOptions  = new PagingOptions().SkipItems(skip).LimitItems(limit);
            var sortingOptions = new SortingOptions("CreatedOn");

            var sortOptions = new List <SortingOptions> {
                sortingOptions
            };

            Expression <Func <CommentEntity, bool> > filterCondition;

            if (!string.IsNullOrEmpty(commentId))
            {
                filterCondition = comment => comment.IsDeleted == false && comment.PostId == postId && comment.ParentId == commentId;
            }
            else
            {
                filterCondition = comment => comment.IsDeleted == false && comment.PostId == postId && comment.ParentId == null;
            }

            var repositoryResult = await this._commentRepository.GetAsync(filterCondition, pagingOptions, sortOptions);

            var mapperResult = this._mapper.Map <IEnumerable <CommentItemBo> >(repositoryResult);

            var commentResponseBo = await this.MapCommentsResultsWithPageOptions(postId, commentId, skip, limit, mapperResult);

            return(new ServiceResult <CommentsResponseBo> {
                Value = commentResponseBo
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Load list of T objects that match the specified criteria with support for paging and sorting
        /// </summary>
        /// <param name="paging"></param>
        /// <param name="sorting"></param>
        /// <param name="query">Query used to retrieve the T objects. If not specified, all objects will be returned</param>
        /// <returns></returns>
        public static List <T> Load(PagingOptions paging, SortingOptions <T> sorting, IQueryOver <T, T> useQuery = null)
        {
            IQueryOver <T, T> query = (useQuery == null) ? SessionManager.CurrentSession.QueryOver <T>() : useQuery;

            // Logging the method call
            _logger.Debug("{0}.Load(paging, sorting, useQuery)", typeof(T));
            _logger.Debug("Paging: DontApplyPaging={0} Page={1} ResultsPerPage={2} ItemsCount={3} PageCount={4}", paging.DontApplyPaging, paging.Page, paging.ResultsPerPage, paging.ItemsCount, paging.PageCount);
            _logger.Debug("Sorting: DontApplySorting={0} OrderBy={1} SortOrder={2}", sorting.DontApplySorting, sorting.OrderBy.Body, sorting.SortOrder);

            // Aplly sorting
            if (!sorting.DontApplySorting)
            {
                var order = query.OrderBy(sorting.OrderBy);
                query = (sorting.SortOrder == SortOrder.Ascending) ? order.Asc : order.Desc;
            }

            // Apply paging
            if (!paging.DontApplyPaging)
            {
                // Update the paging object with the total number of records
                // so we can determine how many pages there are available
                UpdatePagingOptions((ICriteria)query.UnderlyingCriteria.Clone(), paging);

                // Limit the query results
                query.UnderlyingCriteria
                .SetFirstResult(paging.ResultsPerPage * paging.Page)
                .SetMaxResults(paging.ResultsPerPage);
            }

            return((List <T>)query.List <T>());
        }
Ejemplo n.º 5
0
        public List <Resource> GetRolePermsResList(List <UserRole> userRoles)
        {
            List <Resource> rolePermsResList = new List <Resource>();
            string          roleIds          = string.Empty;
            string          roleNames        = string.Empty;

            if (userRoles.Count > 0)
            {
                foreach (UserRole ur in userRoles)
                {
                    roleIds   += ur.Role.Id + ",";
                    roleNames += ur.Role.FullName + ",";
                }
                roleIds   = roleIds.TrimEnd(',');
                roleNames = roleNames.TrimEnd(',');
            }
            long[] objectIds         = Array.ConvertAll <string, long>(roleIds.Split(','), delegate(string s) { return(long.Parse(s)); });
            var    roleSpecification = new Specification <Permission>(p => objectIds.Contains(p.ObjectId));

            roleSpecification.FetchStrategy.Include(obj => obj.Resource);
            var sortingOtopns   = new SortingOptions <Permission, int?>(x => x.Resource.SortCode, isDescending: false);
            var rolePermissions = permissionRepository.FindAll(roleSpecification, sortingOtopns);

            foreach (Permission p in rolePermissions)
            {
                rolePermsResList.Add(p.Resource);
            }
            return(rolePermsResList);
        }
Ejemplo n.º 6
0
        public async Task <ServiceResult <PostsListResponseBo> > GetPostsAsync(string tag, string page, int skip, int limit, CancellationToken token)
        {
            var pagingOptions  = new PagingOptions().SkipItems(skip).LimitItems(limit);
            var sortingOptions = new SortingOptions("CreatedOn");

            var sortOptions = new List <SortingOptions> {
                sortingOptions
            };

            Expression <Func <PostEntity, bool> > condition = post => !post.IsDeleted;

            if (tag.IsNotNull())
            {
                condition.And(post => post.Tags.Contains(tag));
            }

            PageOption pageOption;
            bool       isValidPage = Enum.TryParse <PageOption>(page, true, out pageOption);

            if (!isValidPage || pageOption == PageOption.Recommended)
            {
                condition.And(post => post.IsRecommended);
            }

            var repositoryResult = await this._postRepository.GetAsync(condition, pagingOptions, sortOptions, token);

            var mapperResult = this._autoMapperService.Map <IEnumerable <PostItemBo> >(repositoryResult);

            var postsResponseBo = await this.MapPostsResultsWithPageOptions(skip, limit, mapperResult, token);

            return(new ServiceResult <PostsListResponseBo> {
                Value = postsResponseBo
            });
        }
Ejemplo n.º 7
0
        public void TryFindAllResult_After_Add_To_Partition_Should_Return_False()
        {
            IEnumerable <Contact> result;
            var contacts = new[] { new Contact()
                                   {
                                       ContactId = 1, Name = "Test User", ContactTypeId = 1
                                   } };
            var specification = new Specification <Contact>(x => x.ContactTypeId == 1);
            IQueryOptions <Contact> queryOptions = new SortingOptions <Contact>("Name", true);

            CachingStrategy.SaveFindAllResult(specification, queryOptions, null, contacts);
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(true);

            var contact2 = new Contact()
            {
                ContactId = 2, Name = "Test User 2", ContactTypeId = 1
            };

            CachingStrategy.Add(2, contact2);
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(false);
            CachingStrategy.SaveFindAllResult(specification, queryOptions, null, contacts);

            // after saving the new results in the next generation then it should find it
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(true);
        }
Ejemplo n.º 8
0
        protected virtual SortingOptions GetSort(string sort)
        {
            var sortingOptions = new SortingOptions();

            if (!String.IsNullOrEmpty(sort))
            {
                var fields = sort.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var field in fields)
                {
                    string name = field.Trim();
                    if (String.IsNullOrEmpty(name))
                    {
                        continue;
                    }

                    var order = SortOrder.Ascending;
                    if (!String.IsNullOrEmpty(sort) && sort.StartsWith("-"))
                    {
                        name  = name.Substring(1);
                        order = SortOrder.Descending;
                    }

                    if (AllowedFields.Contains(name))
                    {
                        sortingOptions.Fields.Add(new FieldSort {
                            Field = name, Order = order
                        });
                    }
                }
            }

            return(sortingOptions);
        }
Ejemplo n.º 9
0
        public ActionResult Edit(int id)
        {
            Device existing = deviceRepository.Get(id);

            if (existing == null)
            {
                return(RedirectToAction("TableMode"));
            }

            var model = new DeviceModel
            {
                Id              = existing.Id,
                Name            = existing.Name,
                Description     = existing.Description,
                IMEI            = existing.IMEI,
                SimNumber       = existing.SimNumber,
                AreaId          = existing.AreaId,
                TransportPlanId = existing.TransportPlanId
            };

            var    sortingOptions = new SortingOptions <DtuGPS, DateTime>(x => x.RecvTime, true);
            DtuGPS gps            = dtuGpsRepository.FindAll(g => g.IMEI == existing.IMEI, sortingOptions).FirstOrDefault();

            if (gps != null)
            {
                model.longitude = gps.Longitude;
                model.latitude  = gps.Latitude;
            }

            ViewBag.Areas       = GetAreaSelectItems();
            ViewBag.Plans       = GetPlanSelectItems();
            ViewBag.DeviceTypes = GetDeviceTypeItems();
            return(View(model));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Update all grouping options. This method is intended to be called only from parent view.
        /// </summary>
        /// <param name="stateManager">The new state manager for the hosted page.</param>
        public void ReloadGroupingOptions(IPageGroupingStateManager stateManager)
        {
            IsNavigationOpsAvailable = false;

            _stateManager = stateManager;
            SortingOptions.Clear();

            // Reload options
            var options = _stateManager.PopulateAvailablePairs();

            foreach (var option in options)
            {
                SortingOptions.Add(option);
            }

            // Set default option
            // We don't need to set it - it is already passed to view
            var lastUsedOption = _stateManager.GetLastUsedPair();
            var elem           = SortingOptions.Where(i => i.Identifier == lastUsedOption.Identifier).ToList();

            if (elem.Any())
            {
                SelectedItemIndex = SortingOptions.IndexOf(elem.FirstOrDefault());
            }

            // Enable selection
            IsNavigationOpsAvailable = true;
        }
Ejemplo n.º 11
0
        public static void LoadList()
        {
            _logger.Debug("Test: LoadList()");

            var sorting = new SortingOptions <TestObject>(x => x.Name).Asc();
            var paging  = new PagingOptions {
                ResultsPerPage = 5, Page = 0
            };

            _logger.Debug("Loading page 1");
            var list = TestObject.Load(paging, sorting);

            foreach (var i in list)
            {
                _logger.Debug("Record {0}: {1}", i.Id, i.Name);
            }

            if (paging.PageCount > 1)
            {
                _logger.Debug("Loading page 2");
                paging.Page = 1;
                list        = TestObject.Load(paging, sorting);
                foreach (var i in list)
                {
                    _logger.Debug("Record {0}: {1}", i.Id, i.Name);
                }
            }
        }
Ejemplo n.º 12
0
        public List <PermissionGridDto> GetUserPermissionList(long userId)
        {
            var specification = new Specification <Permission>(p => p.ObjectId.Equals(userId) && p.ObjectType.Equals("UserPermission"));
            var sortingOtopns = new SortingOptions <Permission, int?>(x => x.Resource.SortCode, isDescending: false);
            var list          = permissionRepository.FindAll(specification, sortingOtopns).ToList();

            return(Mapper.Map <List <PermissionGridDto> >(list));
        }
Ejemplo n.º 13
0
        public List <ResourceGridDto> GetButtonList(string menuId)
        {
            var specification = new Specification <Resource>(u => u.DeletedMark == false && u.ObjectType == "Button");
            var sortingOtopns = new SortingOptions <Resource, int?>(x => x.SortCode, isDescending: false);
            var list          = resourceRepository.FindAll(specification, sortingOtopns).ToList();

            return(Mapper.Map <List <ResourceGridDto> >(list));
        }
        public Task <FindResults <T> > GetAllAsync(SortingOptions sorting = null, PagingOptions paging = null)
        {
            var search = new ElasticQuery()
                         .WithPaging(paging)
                         .WithSort(sorting);

            return(FindAsync(search));
        }
Ejemplo n.º 15
0
        public List <OrganizeGridDto> GetList()
        {
            var specification = new Specification <Organize>(u => u.DeletedMark == false);
            var sortingOtopns = new SortingOptions <Organize, int?>(x => x.SortCode, isDescending: true);
            var list          = organizeRepository.FindAll(specification, sortingOtopns).ToList();

            return(Mapper.Map <List <OrganizeGridDto> >(list));
        }
 public static T WithSort <T>(this T query, SortingOptions sorting) where T : ISortableQuery
 {
     if (sorting != null)
     {
         query.SortBy.AddRange(sorting.Fields);
     }
     return(query);
 }
Ejemplo n.º 17
0
        public List <WxImageGridDto> GetList()
        {
            string appId         = WxOperatorProvider.Provider.GetCurrent().AppId;
            var    specification = new Specification <WxImage>(p => p.DeletedMark == false && p.AppId == appId);
            var    sortingOtopns = new SortingOptions <WxImage, DateTime?>(x => x.CreationTime, isDescending: false);
            var    list          = wxImageRepository.FindAll(specification, sortingOtopns).ToList();

            return(Mapper.Map <List <WxImageGridDto> >(list));
        }
Ejemplo n.º 18
0
        /// <summary>
        ///   Sorts task and updates GUI accordingly
        /// </summary>
        /// <param name="sortingOption"></param>
        private void SortTasks(SortingOptions sortingOption)
        {
            if (!Enum.IsDefined(typeof(SortingOptions), sortingOption))
            {
                throw new ArgumentException("sortingOption must be a SortingOptions", "sortingOption");
            }

            this.TaskManager.SortTasks(sortingOption);
            this.UpdateListWithTasks(this.TaskManager.GetTasks());
        }
Ejemplo n.º 19
0
        public virtual ICollection <string> GetIncludedEntities()
        {
            Groups.ForEach(g => AddNavigationPropertyIfNeeded(g.PropertyName));
            GroupSummaries.ForEach(g => AddNavigationPropertyIfNeeded(g.PropertyName));
            Filters.ForEach(g => AddNavigationPropertyIfNeeded(g.PropertyName));
            SortingOptions.ForEach(g => AddNavigationPropertyIfNeeded(g.PropertyName));
            Summaries.ForEach(g => AddNavigationPropertyIfNeeded(g.PropertyName));

            return(IncludeEntities);
        }
        public void SortingBuilder_ForNullExpression_ThrowsException()
        {
            // Arrange
            var options = new SortingOptions <TestSearchResultItem>();
            var builder = new SortingOptionsBuilder <TestSearchResultItem>(options);

            // Act
            builder.By(null);

            // Assert
        }
Ejemplo n.º 21
0
 public GridViewDataSet <Company <bool> > GetWithSorting([FromUri, AsObject(typeof(ISortingOptions))] SortingOptions sortingOptions)
 {
     lock (Database.Instance)
     {
         var dataSet = new GridViewDataSet <Company <bool> >()
         {
             SortingOptions = sortingOptions
         };
         dataSet.LoadFromQueryable(Database.Instance.Companies2.AsQueryable());
         return(dataSet);
     }
 }
        public void TryFindResult_With_Same_QueryOptions_Should_Return_True()
        {
            var contact = new Contact()
            {
                ContactId = 1, Name = "Test User"
            };
            var specification = new Specification <Contact>(x => x.ContactId == 1);
            IQueryOptions <Contact> queryOptions = new SortingOptions <Contact>("Name");

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out Contact result).ShouldBe(true);
        }
        public void SortingOptions_Will_Sort_By_SortExpression_Asc()
        {
            var contacts = new List<Contact>();
            for (var i = 5; i >= 1; i--)
            {
                contacts.Add(new Contact { Name = "Test User " + i });
            }

            var qo = new SortingOptions<Contact, string>(x => x.Name);
            var queryable = qo.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(5);
            queryable.First().Name.ShouldEqual("Test User 1");
        }
        public void SortingOptions_Will_Sort_By_Multiple_Deep_SortProperty_Desc()
        {
            var contacts = new List<Contact>();
            for (var i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact { Name = "Test User " + i, ContactType = new ContactType { Name = "Type " + (5 - i) } });
            }

            var qo = new SortingOptions<Contact>("ContactType.Name", isDescending: true);
            var queryable = qo.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(5);
            queryable.First().Name.ShouldEqual("Test User 1");
        }
        public void SortingBuilder_ForExpression_AddsExpression()
        {
            // Arrange
            var options = new SortingOptions <TestSearchResultItem>();
            var builder = new SortingOptionsBuilder <TestSearchResultItem>(options);

            // Act
            builder.By(result => result.Name, SortOrder.Descending);

            // Assert
            Assert.IsTrue(options.Operations.Count == 1);
            Assert.IsTrue(options.Operations.First().SortOrder == SortOrder.Descending);
        }
Ejemplo n.º 26
0
 public AudioSearch(string searchText, bool correctErrors, bool hasLyrics, bool searchOption,
                    SortingOptions sortingOption, bool searchInOwn, string offset, string count, string accessToken)
 {
     _searchText    = searchText;
     _correctErrors = correctErrors;
     _hasLyrics     = hasLyrics;
     _searchOption  = searchOption;
     _sortingOption = sortingOption;
     _searchInOwn   = searchInOwn;
     _offset        = offset;
     _count         = count;
     _accessToken   = accessToken;
 }
Ejemplo n.º 27
0
        public List <DutyGridDto> GetList(string keyword)
        {
            var spec = new Specification <Duty>(p => p.DeletedMark.Equals(false));

            if (!string.IsNullOrEmpty(keyword))
            {
                spec = new Specification <Duty>(p => p.DeletedMark.Equals(false) && (p.FullName.Contains(keyword) || p.EnCode.Contains(keyword)));
            }
            var sortingOtopns = new SortingOptions <Duty, int?>(x => x.SortCode, isDescending: false);
            var list          = dutyRepository.FindAll(spec, sortingOtopns).ToList();

            return(Mapper.Map <List <DutyGridDto> >(list));
        }
Ejemplo n.º 28
0
 public GridViewDataSet <Company <string> > GetWithSortingAndPaging([FromUri, AsObject(typeof(ISortingOptions))] SortingOptions sortingOptions, [FromUri, AsObject(typeof(IPagingOptions))] PagingOptions pagingOptions)
 {
     lock (Database.Instance)
     {
         var dataSet = new GridViewDataSet <Company <string> >()
         {
             PagingOptions  = pagingOptions,
             SortingOptions = sortingOptions
         };
         dataSet.LoadFromQueryable(Database.Instance.Companies.AsQueryable());
         return(dataSet);
     }
 }
        public void SortingOptions_Will_Sort_By_SortProperty_Desc()
        {
            var contacts = new List<Contact>();
            for (int i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact { Name = "Test User " + i });
            }

            var qo = new SortingOptions<Contact>("Name", true);
            IQueryable<Contact> queryable = qo.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(5);
            queryable.First().Name.ShouldEqual("Test User 5");
        }
        public void TryGetAllResult_With_Same_QueryOptions_Should_Return_True()
        {
            var contact = new Contact()
            {
                ContactId = 1, Name = "Test User"
            };
            var sorting = new SortingOptions <Contact>("Name");

            CachingStrategy.SaveGetAllResult(sorting, null, new[] { contact });
            CachingStrategy.TryGetAllResult(sorting, null, out IEnumerable <Contact> result).ShouldBe(true);

            result.Count().ShouldBe(1);
        }
        public void SortingOptions_Will_Sort_By_SortExpression_Desc()
        {
            var contacts = new List<Contact>();
            for (int i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact { Name = "Test User " + i });
            }

            var qo = new SortingOptions<Contact, string>(x => x.Name, isDescending: true);
            IQueryable<Contact> queryable = qo.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(5);
            queryable.First().Name.ShouldEqual("Test User 5");
        }
        public void SaveFindResult_Should_Set_Cache()
        {
            Contact result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };
            var specification = new Specification<Contact>(x => x.ContactId == 1);
            IQueryOptions<Contact> queryOptions = null;

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);

            queryOptions = new SortingOptions<Contact>("Name");
            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);
        }
Ejemplo n.º 33
0
        public List <WxTextGridDto> GetList(string keyword)
        {
            string appId         = WxOperatorProvider.Provider.GetCurrent().AppId;
            var    specification = new Specification <WxText>(p => p.DeletedMark == false && p.AppId == appId);

            if (!string.IsNullOrEmpty(keyword))
            {
                specification = new Specification <WxText>(p => p.DeletedMark == false && p.AppId == appId && (p.Title.Contains(keyword) || p.Content.Contains(keyword)));
            }
            var sortingOtopns = new SortingOptions <WxText, DateTime?>(x => x.CreationTime, isDescending: false);
            var list          = wxTextRepository.FindAll(specification, sortingOtopns).ToList();

            return(Mapper.Map <List <WxTextGridDto> >(list));
        }
Ejemplo n.º 34
0
        public void TryFindAllResult_With_Same_QueryOptions_Should_Return_True()
        {
            var contact = new Contact()
            {
                ContactId = 1, Name = "Test User"
            };
            var specification = new Specification <Contact>(x => x.ContactId == 1);
            IQueryOptions <Contact> queryOptions = new SortingOptions <Contact>("Name");

            CachingStrategy.SaveFindAllResult(specification, queryOptions, null, new[] { contact });
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out IEnumerable <Contact> result).Should().Be(true);

            result.Count().Should().Be(1);
        }
Ejemplo n.º 35
0
        public List <WxOfficialGridDto> GetList(string keyword)
        {
            OperatorModel operatorModel = OperatorProvider.Provider.GetCurrent();
            var           specification = new Specification <WxOfficial>(p => p.CreatorUserId == operatorModel.Id);

            if (!string.IsNullOrEmpty(keyword))
            {
                specification = new Specification <WxOfficial>(p => p.Account.Contains(keyword) || p.Name.Contains(keyword));
            }
            var sortingOtopns = new SortingOptions <WxOfficial, DateTime?>(x => x.CreationTime, isDescending: false);
            var list          = wxOfficialRepository.FindAll(specification, sortingOtopns).ToList();

            return(Mapper.Map <List <WxOfficialGridDto> >(list));
        }
Ejemplo n.º 36
0
        public void SaveFindResult_Should_Set_Cache()
        {
            var contact = new Contact()
            {
                ContactId = 1, Name = "Test User"
            };
            var specification = new Specification <Contact>(x => x.ContactId == 1);
            IQueryOptions <Contact> queryOptions = null;

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out Contact result).Should().Be(true);

            queryOptions = new SortingOptions <Contact>("Name");
            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).Should().Be(true);
        }
        public void TryGetAllResult_With_Same_QueryOptions_Should_Return_True()
        {
            IEnumerable<Contact> result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };
            var sorting = new SortingOptions<Contact>("Name");

            CachingStrategy.SaveGetAllResult(sorting, null, new[] { contact });
            CachingStrategy.TryGetAllResult(sorting, null, out result).ShouldEqual(true);

            result.Count().ShouldEqual(1);
        }
        public void TryFindResult_With_Different_QueryOptions_Should_Return_False()
        {
            Contact result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };
            var specification = new Specification<Contact>(x => x.ContactId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name");

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, null, null, out result).ShouldEqual(false);

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, new SortingOptions<Contact>("Name", true), null, out result).ShouldEqual(false);
        }
Ejemplo n.º 39
0
 private void LoadGameLibrary()
 {
     var library = _serviceLocator.GetInstance<IGameLibraryManager>();
     var gameInfoList = new ObservableCollection<GameInfo>();
     var collection = new ThreadedObservableCollection<GameInfo>(gameInfoList, this.Dispatcher);
     _collectionView = new ListCollectionView(gameInfoList);
     _collectionView.Filter = new Predicate<object>(Filter);
     _collectionView.CustomSort = new GameInfoComparer(SortingOptions.Name);
     _collectionView.GroupDescriptions.Add(new GameInfoGroupDescription(SortingOptions.Name));
     _sortingOption = SortingOptions.Name;
     Thread gameLoader = new Thread(() => library.UpdateGameLibrary(collection));
     gameLoader.Start();
     gamesList.ItemsSource = _collectionView;
     gamesList.SelectedIndex = 0;
 }
        public void TryFindAllResult_With_Same_QueryOptions_Should_Return_True()
        {
            IEnumerable<Contact> result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };
            var specification = new Specification<Contact>(x => x.ContactId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name");

            CachingStrategy.SaveFindAllResult(specification, queryOptions, null, new[] { contact });
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(true);

            result.Count().ShouldEqual(1);
        }
        public void TryFindAllResult_After_Delete_To_Partition_Should_Return_False()
        {
            IEnumerable<Contact> result;
            var contacts = new[] { new Contact() { ContactId = 1, Name = "Test User", ContactTypeId = 1 } };
            var specification = new Specification<Contact>(x => x.ContactTypeId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name", true);

            CachingStrategy.SaveFindAllResult(specification, queryOptions, null, contacts);
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(true);

            CachingStrategy.Delete(1, contacts[0]);

            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(false);
            CachingStrategy.SaveFindAllResult(specification, queryOptions, null, contacts);

            // after saving the new results in the next generation then it should find it
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(true);
        }
Ejemplo n.º 42
0
        private void ChangeSorting_Click(object sender, RoutedEventArgs e)
        {
            _collectionView.GroupDescriptions.Clear();

            if (_sortingOption == SortingOptions.Name)
            {
                _sortingOption = SortingOptions.Publisher;
                _collectionView.CustomSort = new GameInfoComparer(_sortingOption);
                _collectionView.GroupDescriptions.Add(new GameInfoGroupDescription(_sortingOption));
                return;
            }

            if (_sortingOption == SortingOptions.Publisher)
            {
                _sortingOption = SortingOptions.Year;
                _collectionView.CustomSort = new GameInfoComparer(_sortingOption);
                _collectionView.GroupDescriptions.Add(new GameInfoGroupDescription(_sortingOption));
                return;
            }
            
            if (_sortingOption == SortingOptions.Year)
            {
                _sortingOption = SortingOptions.Name;
                _collectionView.CustomSort = new GameInfoComparer(_sortingOption);
                _collectionView.GroupDescriptions.Add(new GameInfoGroupDescription(_sortingOption));
                return;
            }
        }
Ejemplo n.º 43
0
 public GameInfoComparer(SortingOptions sorting)
 {
     _sorting = sorting;
 }
        public void SortingOptions_With_Multiple_Sorting_Properties()
        {
            var contacts = new List<Contact>();
            for (int i = 5; i >= 1; i--)
            {
                contacts.Add(new Contact { Name = "Test User " + (i % 2),ContactTypeId = i});
            }

            var qo = new SortingOptions<Contact>("Name");
            qo.ThenSortBy("ContactTypeId");

            IQueryable<Contact> queryable = qo.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(5);

            var contact = queryable.First();
            contact.Name.ShouldEqual("Test User 0");
            contact.ContactTypeId.ShouldEqual(2);
        }
 public GameInfoGroupDescription(SortingOptions sorting)
 {
     _sorting = sorting;
 }
        public void TryFindResult_After_Update_To_Different_Partition_Should_Return_True()
        {
            Contact result;
            var contact = new Contact() { ContactId = 1, Name = "Test User", ContactTypeId = 1 };
            var specification = new Specification<Contact>(x => x.ContactTypeId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name", true);

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);

            var contact2 = new Contact() { ContactId = 2, Name = "Test User 2", ContactTypeId = 2 };
            CachingStrategy.Update(2, contact2);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);
        }
        public void SortingOptions_Will_Sort_By_SortExpression_Multiple_Deep_Asc()
        {
            var contacts = new List<Contact>();
            for (var i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact { Name = "Test User " + i, ContactType = new ContactType { Name = "Type " + (5 - i)} });
            }

            var qo = new SortingOptions<Contact, string>(x => x.ContactType.Name);
            var queryable = qo.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(5);
            queryable.First().Name.ShouldEqual("Test User 5");
        }
        public void TryFindResult_After_Update_To_Partition_Should_Return_False()
        {
            Contact result;
            var contact = new Contact() { ContactId = 1, Name = "Test User", ContactTypeId = 1 };
            var specification = new Specification<Contact>(x => x.ContactTypeId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name", true);

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);

            contact.Name = "Test User - EDITED";
            CachingStrategy.Update(1, contact);

            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(false);
            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);

            // after saving the new results in the next generation then it should find it
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);
        }