public override CollectionDataView GetDataView(CollectionQuery query) { lock (cachedData) { var cacheState = GetCacheState(query); if (cacheState != CachedDataViewState.CompleteHit && isLoading == false && HasAllDataBeenLoaded(query) == false) { isLoading = true; pump.QueueAsyncAction(LoadMoreAsync(query, lastContinuationToken), (t) => { if (t.Exception != null) { throw new AggregateException(t.Exception); } lock (cachedData) { CachedDataSet results; if (cachedData.TryGetValue(query.CacheKey, out results) == false) { results = new CachedDataSet(); results.Items.AddRange(t.Result.Items); cachedData.Add(query.CacheKey, results); } else { results.Items.AddRange(t.Result.Items); } if (t.Result.ContinuationToken == null) { results.IsComplete = true; } } lastContinuationToken = t.Result.ContinuationToken; isLoading = false; FireDataChanged(); }); } if (cacheState == CachedDataViewState.CompleteHit) { return(CreateFromCache(query, true, HasAllDataBeenLoaded(query) && IsEndOfCache(query))); } else if (cacheState == CachedDataViewState.CompleteMiss) { return(new CollectionDataView(new List <object>(), HasAllDataBeenLoaded(query), HasAllDataBeenLoaded(query), query.Skip)); } else { return(CreateFromCache(query, HasAllDataBeenLoaded(query), HasAllDataBeenLoaded(query))); } } }
public override CollectionDataView GetDataView(CollectionQuery query) { lock(cachedData) { var cacheState = GetCacheState(query); if (cacheState != CachedDataViewState.CompleteHit && isLoading == false && HasAllDataBeenLoaded(query) == false) { isLoading = true; pump.QueueAsyncAction(LoadMoreAsync(query, lastContinuationToken), (t) => { if (t.Exception != null) throw new AggregateException(t.Exception); lock (cachedData) { CachedDataSet results; if (cachedData.TryGetValue(query.CacheKey, out results) == false) { results = new CachedDataSet(); results.Items.AddRange(t.Result.Items); cachedData.Add(query.CacheKey, results); } else { results.Items.AddRange(t.Result.Items); } if (t.Result.ContinuationToken == null) { results.IsComplete = true; } } lastContinuationToken = t.Result.ContinuationToken; isLoading = false; FireDataChanged(); }); } if (cacheState == CachedDataViewState.CompleteHit) { return CreateFromCache(query, true, HasAllDataBeenLoaded(query) && IsEndOfCache(query)); } else if (cacheState == CachedDataViewState.CompleteMiss) { return new CollectionDataView(new List<object>(), HasAllDataBeenLoaded(query), HasAllDataBeenLoaded(query), query.Skip); } else { return CreateFromCache(query, HasAllDataBeenLoaded(query), HasAllDataBeenLoaded(query)); } } }