示例#1
0
        protected async Task EnsurePagingConfig(PagingPath paging, CancellationToken cancellationToken = default)
        {
            if (paging.Config != null)
            {
                return;
            }
            using var fs = await GetFileReadStream(paging.ConfigPath);

            paging.Config = await JsonSerializer.DeserializeAsync <PagingConfig>(fs, cancellationToken : cancellationToken);
        }
示例#2
0
        protected async Task <IList <TId> > GetPagingResult(PagingPath paging, Pagination pagination, CancellationToken cancellationToken = default)
        {
            IList <TId> result = Array.Empty <TId>();

            var path = paging.GetPagePath(pagination);

            if (path != null)
            {
                using var fs = await GetFileReadStream(path, cancellationToken);

                result = await JsonSerializer.DeserializeAsync <IList <TId> >(fs, cancellationToken : cancellationToken);
            }

            return(result);
        }
示例#3
0
        public override async Task <QueryResponse <string> > Query(PostQueryRequest query, CancellationToken cancellationToken = default)
        {
            query.Pagination ??= new Pagination();

            PagingPath?paging = null;

            if (query.Type != null)
            {
                switch (query.Type)
                {
                case PostType.Article:
                    paging = new PagingPath(Path.Join(RootPath, "articles"));
                    break;

                case PostType.Slides:
                    paging = new PagingPath(Path.Join(RootPath, "slides"));
                    break;

                case PostType.Note:
                    paging = new PagingPath(Path.Join(RootPath, "notes"));
                    break;
                }
            }
            else if (!string.IsNullOrWhiteSpace(query.CategoryId))
            {
                var catRoot = Path.Join(RootPath, "categories");
                paging = new PagingPath(Path.Join(catRoot, query.CategoryId));
            }
            else if (!string.IsNullOrWhiteSpace(query.KeywordId))
            {
                var catRoot = Path.Join(RootPath, "keywords");
                paging = new PagingPath(Path.Join(catRoot, query.KeywordId));
            }

            paging ??= new PagingPath(Path.Join(RootPath, "pages"));

            await EnsurePagingConfig(paging);

            paging.FillPagination(query.Pagination);

            var res = new QueryResponse <string>(await GetPagingResult(paging, query.Pagination, cancellationToken), query.Pagination);

            return(res);
        }