Example #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);
        }
        public static byte[] Serialize(this PagingState pagingState)
        {
            if (pagingState == null)
            {
                return(null);
            }
            var bytes = ZeroFormatterSerializer.Serialize(pagingState);

            return(bytes);
        }
        public static string SerializeToBase64String(this PagingState pagingState)
        {
            if (pagingState == null)
            {
                return(null);
            }
            byte[] bytes    = pagingState.Serialize();
            var    psString = Convert.ToBase64String(bytes);

            return(psString);
        }
        public static PagingState DeserializePageStateFromBase64String(this string psString)
        {
            if (string.IsNullOrEmpty(psString))
            {
                return new PagingState()
                       {
                           CurrentIndex = 0
                       }
            }
            ;
            var         bytes       = Convert.FromBase64String(psString);
            PagingState pagingState = bytes.DeserializePageState();

            return(pagingState);
        }
    }