예제 #1
0
        public void paging_state_conversions()
        {
            PagingState pagingStateExpected = new PagingState()
            {
                CurrentIndex = 1234
            };
            var bytes       = pagingStateExpected.Serialize();
            var pagingState = bytes.DeserializePageState();

            pagingState.ShouldBe(pagingStateExpected);

            var psString = Convert.ToBase64String(bytes);

            bytes       = Convert.FromBase64String(psString);
            pagingState = bytes.DeserializePageState();

            pagingState.ShouldBe(pagingStateExpected);

            var urlEncodedPagingState = WebUtility.UrlEncode(psString);
            var psStringUrlDecoded    = WebUtility.UrlDecode(urlEncodedPagingState);

            psStringUrlDecoded.ShouldBe(psString);
            bytes       = Convert.FromBase64String(psStringUrlDecoded);
            pagingState = bytes.DeserializePageState();
            pagingState.ShouldBe(pagingStateExpected);
        }
예제 #2
0
        public async Task <IPage <SimpleDocument <T> > > PageAsync(int pageSize, byte[] pagingState, Guid?tenantId = null,
                                                                   MetaData metaData = null)
        {
            if (metaData == null)
            {
                return(await base.PageAsync(pageSize, pagingState, tenantId));
            }

            byte[]      currentPagingState = pagingState;
            PagingState ps      = pagingState.DeserializePageState();
            var         records = await RetrieveAsync(tenantId);

            records = Filter(records, metaData);
            var slice = records.Skip(ps.CurrentIndex).Take(pageSize).ToList();

            if (slice.Count < pageSize)
            {
                // we are at the end
                pagingState = null;
            }
            else
            {
                ps.CurrentIndex += pageSize;
                pagingState      = ps.Serialize();
            }

            var page = new PageProxy <SimpleDocument <T> >(currentPagingState, pagingState, slice);

            return(page);
        }
예제 #3
0
        public async Task <IPage <T> > PageAsync(
            int pageSize,
            byte[] pagingState,
            Guid?tenantId = null)
        {
            byte[]      currentPagingState = pagingState;
            PagingState ps      = pagingState.DeserializePageState();
            var         records = await RetrieveAsync(tenantId);

            var slice = records.Skip(ps.CurrentIndex).Take(pageSize).ToList();

            if (slice.Count < pageSize)
            {
                // we are at the end
                pagingState = null;
            }
            else
            {
                ps.CurrentIndex += pageSize;
                pagingState      = ps.Serialize();
            }

            var page = new PageProxy <T>(currentPagingState, pagingState, slice);

            return(page);
        }
예제 #4
0
        public async Task <ICollection <SimpleDocument <T> > > PageAsync(int pageSize, int page, Guid?tenantId = null, MetaData metaData = null)
        {
            PagingState ps = new PagingState()
            {
                CurrentIndex = pageSize * (page - 1)
            };
            var pagingState = ps.Serialize();

            return(await PageAsync(pageSize, pagingState, tenantId, metaData));
        }
예제 #5
0
        public async Task <IPage <SimpleDocument <Blog> > > PageAsync(int pageSize, int page, DateTime?timeStampLowerBoundary = default(DateTime?), DateTime?timeStampUpperBoundary = default(DateTime?), string[] categories = null, string[] tags = null)
        {
            PagingState ps = new PagingState()
            {
                CurrentIndex = pageSize * (page - 1)
            };
            var pagingState = ps.Serialize();

            return(await PageAsync(pageSize, pagingState, timeStampLowerBoundary, timeStampUpperBoundary, categories,
                                   tags));
        }
예제 #6
0
        public async Task <IPage <SimpleDocument <RazorLocation> > > PageAsync(int pageSize, int page,
                                                                               DateTime?timeStampLowerBoundary = default(DateTime?),
                                                                               DateTime?timeStampUpperBoundary = default(DateTime?))
        {
            PagingState ps = new PagingState()
            {
                CurrentIndex = pageSize * (page - 1)
            };
            var pagingState = ps.Serialize();

            return(await PageAsync(pageSize, pagingState, timeStampLowerBoundary, timeStampUpperBoundary));
        }
예제 #7
0
        public async Task <IPage <SimpleDocument <Blog> > > PageAsync(int pageSize, byte[] pagingState,
                                                                      DateTime?timeStampLowerBoundary = null,
                                                                      DateTime?timeStampUpperBoundary = null, string[] categories = null, string[] tags = null)
        {
            byte[]      currentPagingState = pagingState;
            PagingState ps      = pagingState.DeserializePageState();
            var         records = await RetrieveAsync();

            records = records.OrderBy(o => o.Document.TimeStamp).ToList();

            var predicate = PredicateBuilder.True <SimpleDocument <Blog> >();

            if (timeStampLowerBoundary != null)
            {
                predicate = predicate.And(i => i.Document.TimeStamp >= timeStampLowerBoundary);
            }
            if (timeStampUpperBoundary != null)
            {
                predicate = predicate.And(i => i.Document.TimeStamp <= timeStampUpperBoundary);
            }

            // this is an AND that return an OR match for tags and categories.
            List <string> safeTagList        = (tags == null) ? null : new List <string>(tags);
            List <string> safeCategoriesList = (categories == null) ? null : new List <string>(categories);

            predicate = predicate.And(i => DelegateContainsAnyInTagsOrCategories(i.Document, safeTagList, safeCategoriesList));


            var filtered = records.Where(predicate.Compile()).Select(i => i);

            var slice = filtered.Skip(ps.CurrentIndex).Take(pageSize).ToList();

            if (slice.Count < pageSize)
            {
                // we are at the end
                pagingState = null;
            }
            else
            {
                ps.CurrentIndex += pageSize;
                pagingState      = ps.Serialize();
            }

            var page = new PageProxy <SimpleDocument <Blog> >(currentPagingState, pagingState, slice);

            return(page);
        }
예제 #8
0
        public async Task <IPage <SimpleDocument <RazorLocation> > > PageAsync(int pageSize, byte[] pagingState,
                                                                               DateTime?timeStampLowerBoundary = null,
                                                                               DateTime?timeStampUpperBoundary = null)
        {
            byte[]      currentPagingState = pagingState;
            PagingState ps      = pagingState.DeserializePageState();
            var         records = await RetrieveAsync();

            records = records.OrderBy(o => o.Document.LastModified).ToList();

            var predicate = PredicateBuilder.True <SimpleDocument <RazorLocation> >();

            if (timeStampLowerBoundary != null)
            {
                predicate = predicate.And(i => i.Document.LastModified >= timeStampLowerBoundary);
            }
            if (timeStampUpperBoundary != null)
            {
                predicate = predicate.And(i => i.Document.LastModified <= timeStampUpperBoundary);
            }

            var filtered = records.Where(predicate.Compile()).Select(i => i);

            var slice = filtered.Skip(ps.CurrentIndex).Take(pageSize).ToList();

            if (slice.Count < pageSize)
            {
                // we are at the end
                pagingState = null;
            }
            else
            {
                ps.CurrentIndex += pageSize;
                pagingState      = ps.Serialize();
            }

            var page = new PageProxy <SimpleDocument <RazorLocation> >(currentPagingState, pagingState, slice);

            return(page);
        }
예제 #9
0
        public async Task <IPage <Client> > PageAsync(int pageSize, byte[] pagingState)
        {
            byte[]      currentPagingState = pagingState;
            PagingState ps      = pagingState.DeserializePageState();
            var         records = await RetrieveAsync();

            records = records.OrderBy(o => o.Id).ToList();

            var predicate = PredicateBuilder.True <ClientDocument>();

            var filtered = records.Where(predicate.Compile()).Select(i => i);

            var slice = filtered.Skip(ps.CurrentIndex).Take(pageSize).ToList();

            if (slice.Count < pageSize)
            {
                // we are at the end
                pagingState = null;
            }
            else
            {
                ps.CurrentIndex += pageSize;
                pagingState      = ps.Serialize();
            }

            List <Client> clientSlice = new List <Client>();

            foreach (var item in slice)
            {
                var client = await item.MakeClientAsync();

                clientSlice.Add(client);
            }

            var page = new PageProxy <Client>(currentPagingState, pagingState, clientSlice);

            return(page);
        }