public QueryParameters(
     string schemaIdentifier,
     string path,
     IPaginationParameters paginationParameters)
     : this(schemaIdentifier, path, Array.Empty <IFilter>(), Array.Empty <string>(), Array.Empty <string>())
 {
     this.PaginationParameters = paginationParameters ?? throw new ArgumentNullException(nameof(paginationParameters));
 }
示例#2
0
        public virtual async Task <QueryResponseBase> Query(
            HttpRequestMessage request,
            IReadOnlyCollection <IFilter> filters,
            IReadOnlyCollection <string> requestedAttributePaths,
            IReadOnlyCollection <string> excludedAttributePaths,
            IPaginationParameters paginationParameters,
            string correlationIdentifier)
        {
            if (null == request)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (null == requestedAttributePaths)
            {
                throw new ArgumentNullException(nameof(requestedAttributePaths));
            }

            if (null == excludedAttributePaths)
            {
                throw new ArgumentNullException(nameof(excludedAttributePaths));
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(nameof(correlationIdentifier));
            }

            string           path            = this.GetPath(request);
            IQueryParameters queryParameters =
                new QueryParameters(this.SchemaIdentifier, path, filters, requestedAttributePaths, excludedAttributePaths);

            queryParameters.PaginationParameters = paginationParameters;
            IReadOnlyCollection <IExtension> extensions   = this.ReadExtensions();
            IRequest <IQueryParameters>      queryRequest =
                new QueryRequest(request, queryParameters, correlationIdentifier, extensions);
            QueryResponseBase result = await this.Provider.PaginateQueryAsync(queryRequest).ConfigureAwait(false);

            return(result);
        }
        private void ApplyPaginationParameter(
            string value,
            Action <IPaginationParameters, int> action)
        {
            if (null == action)
            {
                throw new ArgumentNullException(nameof(action));
            }

            if (string.IsNullOrWhiteSpace(value))
            {
                return;
            }

            int parsedValue = int.Parse(value, CultureInfo.InvariantCulture);

            if (null == this.PaginationParameters)
            {
                this.PaginationParameters = new PaginationParameters();
            }
            action(this.PaginationParameters, parsedValue);
        }
        public static IEnumerable <T> AddPaginationToQuery <T>(this IEnumerable <T> query, IPaginationParameters pagination)
        {
            if (pagination != null)
            {
                query = query.Skip(pagination.Offset).Take(pagination.MaximumRecords);
            }

            return(query);
        }