Exemple #1
0
        public async Task <DateTime> LoadDataAsync(ObservableCollection <T> viewItems, bool forceRefresh)
        {
            DateTime timeStamp = DateTime.Now;

            if (HasStaticData)
            {
                viewItems.AddRangeUnique(await LoadDataAsync());
            }
            else
            {
                var dataInCache = await AppCache.GetItemsAsync <T>(CacheKey);

                if (dataInCache != null)
                {
                    timeStamp = dataInCache.TimeStamp;

                    viewItems.AddRangeUnique(dataInCache.Items);
                }

                if (NetworkInterface.GetIsNetworkAvailable() && DataNeedToBeUpdated(forceRefresh, dataInCache))
                {
                    var freshData = await UpdateCache();

                    viewItems.AddRangeUnique(freshData.Items);
                    timeStamp = freshData.TimeStamp;
                }
            }
            return(timeStamp);
        }
Exemple #2
0
        internal async Task <DataSourceContent <T> > UpdateCache()
        {
            var freshData = new DataSourceContent <T>()
            {
                TimeStamp = DateTime.Now,
                Items     = await LoadDataAsync()
            };

            await AppCache.AddItemsAsync(CacheKey, freshData);

            return(freshData);
        }