public async Task <Boolean> CacheTags(HttpClient client, Boolean forceReload = false) { if (this._tagList != null && !forceReload) { return(true); } StorageFolder tempFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder; String filename = "tags.json"; String tag_response = null; //Attempt to load tags from the saved file if (!forceReload) { try { StorageFile file = await tempFolder.GetFileAsync(filename); tag_response = await FileIO.ReadTextAsync(file); } catch (Exception) { } } Uri tag_index_uri = new Uri(App.BLOG_URL + "?json=get_tag_index"); try { //If tag_response is still null, we are either forcing reload or had an error if (tag_response == null) { tag_response = await client.GetStringAsync(tag_index_uri); } this._tagList = await JsonConvert.DeserializeObjectAsync <TagListObject>(tag_response); StorageFile file = await tempFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, tag_response); return(true); } catch (Exception) { return(false); } }
public async Task<Boolean> CacheTags(HttpClient client, Boolean forceReload = false) { if (this._tagList != null && !forceReload) { return true; } StorageFolder tempFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder; String filename = "tags.json"; String tag_response = null; //Attempt to load tags from the saved file if (!forceReload) { try { StorageFile file = await tempFolder.GetFileAsync(filename); tag_response = await FileIO.ReadTextAsync(file); } catch (Exception) { } } Uri tag_index_uri = new Uri(App.BLOG_URL + "?json=get_tag_index"); try { //If tag_response is still null, we are either forcing reload or had an error if (tag_response == null) { tag_response = await client.GetStringAsync(tag_index_uri); } this._tagList = await JsonConvert.DeserializeObjectAsync<TagListObject>(tag_response); StorageFile file = await tempFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, tag_response); return true; } catch (Exception) { return false; } }