public async Task <bool> LoadCacheAsync(PocketCache pocketCache) { try { StorageFile itemsStorageFile = await _storageFolder.GetFileAsync("PocketItems.json"); string itemsString = File.ReadAllText(itemsStorageFile.Path); ObservableCollection <PocketItem> pocketItems = JsonSerializer.Deserialize <ObservableCollection <PocketItem> >(itemsString); StorageFile lastSyncDateStorageFile = await _storageFolder.GetFileAsync("SyncDate.json"); string lastSyncDateString = File.ReadAllText(lastSyncDateStorageFile.Path); DateTime dateTime = JsonSerializer.Deserialize <DateTime>(lastSyncDateString); pocketCache.SetCacheContent(dateTime, pocketItems); return(true); } catch (FileNotFoundException) { return(false); } catch (Exception e) { throw (e); } }
private async void InitializePocketCache() { await this.AuthPocketAsync(); pocketCache = new PocketCache(pocketClient); await cacheSaver.LoadCacheAsync(pocketCache); await SyncPocketCacheAsync(); }
public async Task <bool> SaveCacheAsync(PocketCache pocketCache) { StorageFile itemsStorageFile = await _storageFolder.CreateFileAsync("PocketItems.json", CreationCollisionOption.ReplaceExisting); StorageFile lastSyncDateStorageFile = await _storageFolder.CreateFileAsync("SyncDate.json", CreationCollisionOption.ReplaceExisting); try { string itemsString = JsonSerializer.Serialize(pocketCache.PocketItems); string lastSyncDateString = JsonSerializer.Serialize(pocketCache.LastSyncDateTime); File.WriteAllText(itemsStorageFile.Path, itemsString); File.WriteAllText(lastSyncDateStorageFile.Path, lastSyncDateString); return(true); } catch (Exception) { return(false); } }