/// <summary> /// Initializes a new instance of the <see cref="PagedEnumerable{T}"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="paging">The paging.</param> public PagedEnumerable(IEnumerable <T> source, IPagingSettings <T> paging) { var queryable = source.Require().AsQueryable(); if (!string.IsNullOrWhiteSpace(paging.OrderBy)) { string command = paging.IsOrderDescending ? "OrderByDescending" : "OrderBy"; var type = typeof(T); var property = type.GetProperty(paging.OrderBy, BindingFlags.IgnoreCase | BindingFlags.Default | BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty); if (property != null) { var parameter = Expression.Parameter(type, "p"); var propertyAccess = Expression.MakeMemberAccess(parameter, property); var orderByExpression = Expression.Lambda(propertyAccess, parameter); var resultExpression = Expression.Call(typeof(Queryable), command, new Type[] { type, property.PropertyType }, queryable.Expression, Expression.Quote(orderByExpression)); queryable = queryable.Provider.CreateQuery <T>(resultExpression); } } PageIndex = paging.Skip == 0 ? 0 : (int)Math.Ceiling(paging.Skip / (double)paging.Take); PageSize = paging.Take; Total = queryable.Count(); Results = queryable.Skip(paging.Skip).Take(paging.Take); }
private IEnumerable <IPageableContainer> Page(IPagingSettings settings, string url, Type type, int maxResultsPerPage) { if (settings.Page.HasValue || settings.PerPage.HasValue) { var requestData = RequestSettingsHelper.GetPopulatedProperties(settings); return(PageRequest(url, requestData, type)); } var results = new List <IPageableContainer>(); bool cont = true; int page = 1; while (cont) { settings.Page = page; settings.PerPage = maxResultsPerPage; var requestData = RequestSettingsHelper.GetPopulatedProperties(settings); var newResults = PageRequest(url, requestData, type); if (newResults.Any()) { results.AddRange(newResults); } if (newResults.Count() < maxResultsPerPage) { cont = false; } page++; } return(results); }
/// <summary> /// Converts the specified source to the target. /// </summary> /// <typeparam name="TSource">The type of the source.</typeparam> /// <typeparam name="TTarget">The type of the target.</typeparam> /// <param name="source">The source.</param> /// <returns></returns> public static IPagingSettings <TTarget> ConvertTo <TSource, TTarget>(this IPagingSettings <TSource> source) { return(new PagingSettings <TTarget> { Skip = source.Skip, Take = source.Take }); }
private List <Message> GetMessageListPager(long collectorId, IPagingSettings settings) { string endPoint = String.Format("/collectors/{0}/messages", collectorId); const int maxResultsPerPage = 1000; var results = Page(settings, endPoint, typeof(List <Message>), maxResultsPerPage); return(results.ToList().ConvertAll(o => (Message)o)); }
private List <Collector> GetCollectorListPager(long surveyId, IPagingSettings settings) { string endPoint = String.Format("/surveys/{0}/collectors", surveyId); const int maxResultsPerPage = 1000; var results = Page(settings, endPoint, typeof(List <Collector>), maxResultsPerPage); return(results.ToList().ConvertAll(o => (Collector)o)); }
private List <SurveyTemplate> GetSurveyTemplateListPager(IPagingSettings settings) { string endPoint = "/survey_templates"; const int maxResultsPerPage = 1000; var results = Page(settings, endPoint, typeof(List <SurveyTemplate>), maxResultsPerPage); return(results.ToList().ConvertAll(o => (SurveyTemplate)o)); }
private List <Question> GetQuestionListPager(long surveyId, long pageId, IPagingSettings settings) { string endPoint = String.Format("/surveys/{0}/pages/{1}/questions", surveyId, pageId); const int maxResultsPerPage = 100; var results = Page(settings, endPoint, typeof(List <Question>), maxResultsPerPage); return(results.ToList().ConvertAll(o => (Question)o)); }
private List <Member> GetMemberListPager(long groupId, IPagingSettings settings) { string endPoint = String.Format("/groups/{0}/members", groupId); const int maxResultsPerPage = 1000; var results = Page(settings, endPoint, typeof(List <Member>), maxResultsPerPage); return(results.ToList().ConvertAll(o => (Member)o)); }
private List <Group> GetGroupListPager(IPagingSettings settings) { string endPoint = "/groups"; const int maxResultsPerPage = 1000; var results = Page(settings, endPoint, typeof(List <Group>), maxResultsPerPage); return(results.ToList().ConvertAll(o => (Group)o)); }
private List <ContactList> GetContactListsPager(IPagingSettings settings) { string endPoint = String.Format("/contact_lists"); const int maxResultsPerPage = 1000; var results = Page(settings, endPoint, typeof(List <ContactList>), maxResultsPerPage); return(results.ToList().ConvertAll(o => (ContactList)o)); }
private List <Response> GetResponseListPager(long id, ObjectType objectType, IPagingSettings settings, bool details) { var bulk = details ? "/bulk" : String.Empty; string endPoint = String.Format("/{0}s/{1}/responses{2}", objectType.ToString().ToLower(), id, bulk); const int maxResultsPerPage = 100; var results = Page(settings, endPoint, typeof(List <Response>), maxResultsPerPage); return(results.ToList().ConvertAll(o => (Response)o)); }
public TicketService(IPagingSettings ticketPagingSettings, ITicketRepository ticketRepository) { this.ticketPagingSettings = ticketPagingSettings; this.ticketRepository = ticketRepository; lazyTicketTypes = new LazyObject <IEnumerable <TicketType> >( () => this.ticketRepository.ListTicketTypes(CurrentCulture.TwoLetterISOLanguageName)); lazyTicketTypeMap = new LazyObject <IDictionary <int, TicketType> >( () => this.ticketRepository.MapTicketType(CurrentCulture.TwoLetterISOLanguageName)); }
public static IPagedList <TResult> RetrieveMultiple <TSpecification, TResult>( this IRetrieveMultipleRepository <TSpecification, TResult> repository, TSpecification specification, int?pageIndex, int?pageSize, IPagingSettings pagingSettings) { int pageIndexInRange = pagingSettings.EnsurePageIndexInRange(pageIndex); int pageSizeInRange = pagingSettings.EnsurePageSizeInRange(pageSize); var request = new RetrieveMultipleRequest <TSpecification>(specification) { PageIndex = pageIndexInRange / pagingSettings.PageCount, PageSize = pageSizeInRange * pagingSettings.PageCount }; var result = repository.RetrieveMultiple(request); var pageIndexOffset = (request.PageIndex * request.PageSize) / pageSizeInRange; var pagedList = result.Items.ToPagedList(pageIndexInRange, pageSizeInRange, pageIndexOffset, result.HasMore); pagedList.State.Settings = pagingSettings; return(pagedList); }
private List <Recipient> GetRecipientListPager(long collectorId, long messageId, IPagingSettings settings) { string endPoint = String.Format("/collectors/{0}/messages/{1}/recipients", collectorId, messageId); const int maxResultsPerPage = 1000; var results = Page(settings, endPoint, typeof(List <Recipient>), maxResultsPerPage); return(results.ToList().ConvertAll(o => (Recipient)o)); }
/// <summary> /// Converts the IEnumerable to a PagedEnumerable /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source">The source.</param> /// <param name="settings">The settings.</param> /// <returns></returns> public static IPagedEnumerable <T> AsPagedEnumerable <T>(this IEnumerable <T> source, IPagingSettings <T> settings) { return(new PagedEnumerable <T>(source, settings)); }