private int SetPageSizeAndGetPage(int skip, int max, ArchiveQueryParameters context) { if (skip > ArchiveQueryParameters.MAX_PAGE_SIZE) { throw new NotSupportedException("Skip cannot exceed the maximum page size of " + ArchiveQueryParameters.MAX_PAGE_SIZE); } if (skip > 0 && max > 0 && skip % SKIP_MULTIPLE != 0) { throw new NotSupportedException("When specifying both Skip and Take (max) then Skip must be a multiple of " + SKIP_MULTIPLE); } if (skip > max && max > 0) { //we don't want to fetch a lot of useless results, so we use small page sizes to get to our max. //the downsideis that we might be doing a lot of calls before we get to max context.PageSize = SKIP_MULTIPLE; return(skip / context.PageSize); } else { //when no max is specified or if skip <= max we just fetch everything after the skipped rows context.PageSize = skip; return(1); } }
private IList <T> InnerDoQuery(RestrictionBuilderBase restrictionBuilder, OrderByBuilder orderByBuilder, int max, int skip) { ArchiveExecutionContext executionContext = _archiveExecutionContextProvider.Get(); if (executionContext == null) { throw new InvalidOperationException(nameof(executionContext) + " not set, cannot be null"); } ArchiveQueryParameters context = new ArchiveQueryParameters(); context.ArchiveName = executionContext.ArchiveName; context.Entities = executionContext.Entities; context.RequestedColumns = DynamicPropertyHelper.GetAllDbColumnsPrefixed <T>(); int page = 0; if (skip > 0) { page = SetPageSizeAndGetPage(skip, max, context); } if (restrictionBuilder != null) { context.Restrictions = restrictionBuilder.GetRestrictions(); } if (orderByBuilder != null) { context.OrderBy = orderByBuilder.Get(); } return(_resultParser.Parse <T>(executionContext, _executor.GetItems(context, max, page))); }
private ArchiveOrderByInfo[] GetOrderBy(ArchiveQueryParameters context) { if (context.OrderBy == null) { return(null); } return(context.OrderBy.ToArray()); }
private ArchiveRestrictionInfo[] GetRestrictions(ArchiveQueryParameters context) { if (context.Restrictions == null) { return(null); } return(context.Restrictions.ToArray()); }
private string[] GetColumns(ArchiveQueryParameters context) { if (context.RequestedColumns.Count == 0) { throw new Exception("No columns specified"); } return(context.RequestedColumns.Distinct().ToArray()); }
private IList <ArchiveListItem> GetMultiPageItems(ArchiveQueryParameters parameters, int max, int page) { List <ArchiveListItem> items = new List <ArchiveListItem>(); if (parameters.PageSize > max && max > 0 && page == 0) { //if we can get the requested amount of items in one go, do so. this only works if we don't want to start from a specific page parameters.PageSize = max; } using (IArchiveAgentWrapper agent = _archiveAgentWrapperCreator()) { bool hasResult = true; int loopPage = page; while (hasResult) //loop while we still can get results { //change the context if we are nearing our max, but only if we did not specify a page if (max > 0 && items.Count + parameters.PageSize > max && page == 0) { parameters.PageSize = max - items.Count; } IList <ArchiveListItem> itemsOnPage = GetItems(parameters, agent, loopPage); //stop if there are no more items found if (itemsOnPage == null) { hasResult = false; } else { items.AddRange(itemsOnPage); loopPage++; //check if the number of results matches the page-size, if not, stop if (itemsOnPage.Count < parameters.PageSize) { hasResult = false; } //if there is a max and the item count is equal to or exceeded the max, we should stop as well if (max > 0 && items.Count >= max) { hasResult = false; } } } } //remove items if we fetched too many (possible when max and page is specified if (max > 0 && items.Count > max) { items.RemoveRange(max, items.Count - max); } return(items); }
private IList <ArchiveListItem> GetItems(ArchiveQueryParameters parameters, IArchiveAgentWrapper agent, int page) { if (parameters.PageSize > ArchiveQueryParameters.MAX_PAGE_SIZE) { throw new NotSupportedException("Page size cannot be larger than " + ArchiveQueryParameters.MAX_PAGE_SIZE); } if (parameters.Restrictions == null || parameters.Restrictions.Count == 0) { throw new Exception("No restriction specified. The SuperOffice ArchiveAgent needs at least one restriction."); } ArchiveListItem[] results = agent.GetArchiveListByColumns(parameters.ArchiveName, GetColumns(parameters), GetOrderBy(parameters), GetRestrictions(parameters), parameters.Entities, page, parameters.PageSize); if (results == null || results.Length == 0) { return(null); } else { return(results); } }
public IList <ArchiveListItem> GetItems(ArchiveQueryParameters parameters, int maxItems, int page) { return(GetMultiPageItems(parameters, maxItems, page)); }