Exemple #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "report/tokens")] HttpRequest req,
            [Table("tokens")] CloudTable tokenTable,
            ILogger log)
        {
            var continuationToken = default(TableContinuationToken);

            try
            {
                continuationToken = PagedEntities <TokenEntity> .GetContinuationToken(req);
            }
            catch (Exception exc)
            {
                log.LogError($"Failed to deserialize continuation token", exc);

                return(new BadRequestResult());
            }

            var segment = await tokenTable.ExecuteQuerySegmentedAsync <TokenEntity>(new TableQuery <TokenEntity>(), continuationToken).ConfigureAwait(false);

            var result = new PagedEntities <TokenEntity>(segment)
            {
                NextLink = (segment.ContinuationToken != null ? PagedEntities <TokenEntity> .GetNextLink(req, segment.ContinuationToken) : null)
            };

            return(new OkObjectResult(result));
        }
Exemple #2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "report/users")] HttpRequestMessage req,
                                                           [Table("users")] CloudTable userTable, TraceWriter log)
        {
            var continuationToken = default(TableContinuationToken);

            try
            {
                continuationToken = PagedEntities <UserEntity> .GetContinuationToken(req);
            }
            catch (Exception exc)
            {
                log.Error($"Failed to deserialize continuation token", exc);

                return(req.CreateResponse(HttpStatusCode.BadRequest));
            }

            var segment = await userTable.ExecuteQuerySegmentedAsync <UserEntity>(new TableQuery <UserEntity>(), continuationToken).ConfigureAwait(false);

            var result = new PagedEntities <UserEntity>(segment)
            {
                NextLink = (segment.ContinuationToken != null ? PagedEntities <UserEntity> .GetNextLink(req, segment.ContinuationToken) : null)
            };

            return(req.CreateResponse(HttpStatusCode.OK, result, "application/json"));
        }
Exemple #3
0
        public static async Task <PagedEntities <T> > ToPagedListAsync <T>(this IQueryable <T> source
                                                                           , int currentPage
                                                                           , int pageSize,
                                                                           CancellationToken cancellationToken = default)
        {
            if (0 > currentPage)
            {
                throw new ArgumentException($"currentPage: {currentPage}, must be greater than zero");
            }

            var totalItems = await source.CountAsync(cancellationToken).ConfigureAwait(false);

            var items = await source.Skip((currentPage - 1) *pageSize)
                        .Take(pageSize).ToListAsync(cancellationToken).ConfigureAwait(false);

            var list = new PagedEntities <T>(items, totalItems, currentPage, pageSize);

            return(list);
        }
        public PagedResponse <TDestination> Convert(PagedEntities <TSource> source, PagedResponse <TDestination> destination, ResolutionContext context)
        {
            var collection = context.Mapper.Map <IEnumerable <TSource>, IEnumerable <TDestination> >(source.Items);

            return(new PagedResponse <TDestination>(collection, source.TotalItems, source.CurrentPage, source.PageSize));
        }