private static async Task <(CatalogPage, bool)> GetPage(CatalogPageIdentifier pageId, bool forceDownload) { string filePath = GetPageCachePath(pageId.Url); if (!File.Exists(filePath)) { Log.Debug($"Cannot find page {pageId.Url}, will download it.."); return(await DownloadPage(pageId).ContinueWith(CachePage), true); } if (forceDownload) { Log.Debug($"Download of page {pageId.Url} was forced.."); return(await DownloadPage(pageId).ContinueWith(CachePage), false); } string pageString = File.ReadAllText(filePath); return(JsonConvert.DeserializeObject <CatalogPage>(pageString), false); CatalogPage CachePage(Task <CatalogPage> i) { return(DiskCache.Cache(filePath, i)); } }
private static async Task <CatalogPage> DownloadPage(CatalogPageIdentifier pageId) { var pageString = await SharedHttpClient.GetStringAsync(pageId.Url); return(JsonConvert.DeserializeObject <CatalogPage>(pageString)); }