protected async Task <bool> DoRegularLoadAsync(bool fullLoad) { int loadCount = IncrementalLoadMax - ReserveSize; ITableQueryAsync <Card> tableQuery = Db.Table <Card>() .Where( c => c.PracticeState == PracticeState.New && !Objects.Select(o => o.Id).Contains(c.Id)) .Take(loadCount); if (!fullLoad) { tableQuery = tableQuery.ShallowLoad(LazyLoader); } tableQuery = Random ? tableQuery.OrderByRand() : tableQuery.OrderBy(c => c.Due); int loadedCount = await AddItemsAsync(tableQuery).ConfigureAwait(false); if (loadedCount < loadCount) { Status = ReviewStatus.MoveNextEndOfStore; } else if (fullLoad) { FurtherLoadedIndex = loadedCount - 1; } return(loadedCount > 0); }
protected async Task <bool> DoRegularLoadAsync(bool fullLoad) { int loadCount = IncrementalLoadMax - ReserveSize; int tomorrow = DateTimeExtensions.Tomorrow.ToUnixTimestamp(); // Prepare query ITableQueryAsync <Card> tableQuery = Db.Table <Card>() .Where( c => c.PracticeState == PracticeState.Due && c.Due < tomorrow && !Objects.Select(o => o.Id).Contains(c.Id)) .Take(loadCount); if (!fullLoad) { tableQuery = tableQuery.ShallowLoad(LazyLoader); } int loadedCount = await AddItemsAsync(tableQuery.OrderBy(c => c.Due)).ConfigureAwait(false); if (loadedCount < loadCount) { Status = ReviewStatus.MoveNextEndOfStore; } else if (fullLoad) { FurtherLoadedIndex = loadedCount - 1; } return(loadedCount > 0); }
/// <summary> /// Helper methods which simply adding items to current collection by dealing with /// synchronization and asynchronous operations. /// </summary> /// <param name="dbQuery">The parametrized DB query.</param> /// <returns>Added item count</returns> protected async Task <int> AddItemsAsync(ITableQueryAsync <T> dbQuery) { // Get items asynchronously var items = await dbQuery.ToListAsync().ConfigureAwait(false); // Add to collection lock (LockObject) Objects.AddRange(items); return(items.Count); }
/// <summary>Loads data for given page.</summary> /// <param name="start">Start item index.</param> /// <param name="size">Page size.</param> /// <returns></returns> public async Task <IEnumerable <T> > LoadPageAsync(int start, int size) { // Create base query ITableQueryAsync <T> baseQuery = _db.Table <T>(); if (_queryFunc != null) { baseQuery = _queryFunc(baseQuery); } ITableQueryAsync <T> fetchQuery = baseQuery.Skip(start).Take(size); return(await fetchQuery.ToListAsync().ConfigureAwait(false)); }
/// <summary>Computes <see cref="PageSize"/> and <see cref="PageCount"/></summary> /// <returns></returns> public async Task ResetAsync() { // Create base query ITableQueryAsync <T> baseQuery = _db.Table <T>(); if (_queryFunc != null) { baseQuery = _queryFunc(baseQuery); } // Count items ItemCount = await baseQuery.CountAsync().ConfigureAwait(false); RaisePropertyChanged(() => PageCount); }
private ITableQueryAsync <Card> FilterCollection(ITableQueryAsync <Card> query) { if (Query != null && Query.IsExpressionValid) { query = Query.Apply(query); } if (_sortDescriptions != null) { foreach (var sortDescription in _sortDescriptions) { query = query.AddOrderBy( sortDescription.PropertyName, sortDescription.Direction == ListSortDirection.Ascending); } } return(query); }
protected async Task <bool> DoFirstLoadAsync() { int totalLoadCount = NewCardsLeft + IncrementalLoadMax; int fullLoadCount = Math.Min(totalLoadCount, IncrementalFurtherLoadMax); int shallowLoadCount = totalLoadCount - fullLoadCount; ITableQueryAsync <Card> tableQuery = Db.Table <Card>().Where(c => c.PracticeState == PracticeState.New).Take(fullLoadCount); tableQuery = Random ? tableQuery.OrderByRand() : tableQuery.OrderBy(c => c.Due); // Fully load up to IncrementalFurtherLoadMax items int loadedCount = await AddItemsAsync(tableQuery).ConfigureAwait(false); FurtherLoadedIndex = loadedCount - 1; if (shallowLoadCount > 0 && loadedCount == fullLoadCount) { tableQuery = Db.Table <Card>() .ShallowLoad(LazyLoader) .Where( c => c.PracticeState == PracticeState.New && !Objects.Select(o => o.Id).Contains(c.Id)) .Take(shallowLoadCount); tableQuery = Random ? tableQuery.OrderByRand() : tableQuery.OrderBy(c => c.Due); loadedCount += await AddItemsAsync(tableQuery).ConfigureAwait(false); } if (loadedCount < totalLoadCount) { Status = ReviewStatus.MoveNextEndOfStore; } return(loadedCount > 0); }
/// <summary> /// Update page item according to current page. /// </summary> /// <returns></returns> public override async Task UpdateCurrentPageItemsAsync() { // Create base query ITableQueryAsync <T> baseQuery = _db.Table <T>(); if (_queryFunc != null) { baseQuery = _queryFunc(baseQuery); } // Count items _itemCount = await baseQuery.CountAsync().ConfigureAwait(false); // Fetch and add items int skip = (CurrentPage - 1) * PageSize; ITableQueryAsync <T> fetchQuery = baseQuery.Skip(skip).Take(PageSize); IEnumerable <T> newItems = await fetchQuery.ToListAsync().ConfigureAwait(false); using (CurrentPageItems.SuspendChangeNotifications()) ((ICollection <T>)CurrentPageItems).ReplaceRange(newItems); }
public ITableQueryAsync <T> FurtherLoad(ITableQueryAsync <T> query) { return(query.SelectColumns(LazyLoadedProperties)); }
public ITableQueryAsync <T> ShallowLoad(ITableQueryAsync <T> query) { return(query.SelectColumns(PermanentProperties)); }
public static ITableQueryAsync <T> FurtherLoad <T>( this ITableQueryAsync <T> query, DbLazyLoad <T> lazyLoad) where T : class { return(lazyLoad.FurtherLoad(query)); }
/// <summary> /// Applies filter conditions to database query. /// </summary> /// <param name="query">The database query</param> /// <returns></returns> public ITableQueryAsync <Card> Apply(ITableQueryAsync <Card> query) { Argument.IsNotNull(() => query); return(query.Where(this.ToLinqExpression <Card>())); }