Пример #1
0
        public async Task <IPage <T> > PageAsync(
            int pageSize,
            byte[] pagingState)
        {
            byte[]      currentPagingState = pagingState;
            PagingState ps      = pagingState.DeserializePageState();
            var         records = await RetrieveAllAsync();

            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 PageContainer <T>(currentPagingState, pagingState, slice);

            return(page);
        }
Пример #2
0
        public static string SerializeToBase64String(this PagingState pagingState)
        {
            if (pagingState == null)
            {
                return(null);
            }
            byte[] bytes    = pagingState.Serialize();
            var    psString = Convert.ToBase64String(bytes);

            return(psString);
        }