From 47360c036d47eff15eabde6f43571ebda8bb6039 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Wed, 13 Nov 2019 11:11:00 -0500 Subject: [PATCH] Pre-beta: picture storage should be more responsive if on disk --- FileManager/UNTESTED/PictureStorage.cs | 56 +++++++++++++------------- __TODO.txt | 41 +++++++++---------- 2 files changed, 46 insertions(+), 51 deletions(-) diff --git a/FileManager/UNTESTED/PictureStorage.cs b/FileManager/UNTESTED/PictureStorage.cs index 34fbc4cb..7a13168e 100644 --- a/FileManager/UNTESTED/PictureStorage.cs +++ b/FileManager/UNTESTED/PictureStorage.cs @@ -42,7 +42,13 @@ namespace FileManager public static (bool isDefault, byte[] bytes) GetPicture(PictureDefinition def) { if (!cache.ContainsKey(def)) - cache.Add(def, null); + { + var path = getPath(def); + cache[def] + = FileUtility.FileExists(path) + ? File.ReadAllBytes(path) + : null; + } return (cache[def] == null, cache[def] ?? getDefaultImage(def.Size)); } @@ -64,33 +70,19 @@ namespace FileManager return; isProcessing = true; - PictureDefinition def; - string path; + var def = cache + .Where(kvp => kvp.Value is null) + .Select(kvp => kvp.Key) + // 80x80 should be 1st since it's enum value == 0 + .OrderBy(d => d.PictureId) + .FirstOrDefault(); - while (true) - { - def = cache - .Where(kvp => kvp.Value is null) - .Select(kvp => kvp.Key) - // 80x80 should be 1st since it's enum value == 0 - .OrderBy(d => d.PictureId) - .FirstOrDefault(); - // no more null entries. all requsted images are cached - if (string.IsNullOrWhiteSpace(def.PictureId)) - return; + // no more null entries. all requsted images are cached + if (string.IsNullOrWhiteSpace(def.PictureId)) + return; - path = getPath(def); - // we found the next one to download - if (!FileUtility.FileExists(path)) - break; - - // file exists. read into cache. try again - // the point is to throttle web calls. therefore only return if we performed a d/l or there are no null cache entries - cache[def] = File.ReadAllBytes(path); - } - - var bytes = download(def); - File.WriteAllBytes(path, bytes); + var bytes = downloadBytes(def); + saveFile(def, bytes); cache[def] = bytes; } finally @@ -98,12 +90,18 @@ namespace FileManager isProcessing = false; } } + private static HttpClient imageDownloadClient { get; } = new HttpClient(); - private static byte[] download(PictureDefinition def) + private static byte[] downloadBytes(PictureDefinition def) { var sz = def.Size.ToString().Split('x')[1]; - var bytes = imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result; - return bytes; + return imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result; + } + + private static void saveFile(PictureDefinition def, byte[] bytes) + { + var path = getPath(def); + File.WriteAllBytes(path, bytes); } } } diff --git a/__TODO.txt b/__TODO.txt index b0865cb7..41bc003f 100644 --- a/__TODO.txt +++ b/__TODO.txt @@ -1,30 +1,27 @@ -- begin BETA --------------------------------------------------------------------------------------------------------------------- -throttle needed for downloading pdf.s +UI +- download now incl pdf +- update wording in menu + pdf menu should be 'PDFs only' +README +- download now incl pdf +- update readme +OLD WEB DOWNLOADER +- download logic in DownloadPdf should look more like DownloadBook -picture storage should be more responsive if on disk? +TESTING +possible bug: no mdf,ldf files created in C:\Users\[username] - -download now incl pdf -pdf menu should be 'PDFs only' - -update wording in menu -update readme - - - - -no mdf,ldf files created in C:\Users\[username] - -Warn of known performance issues -- Library import -- Tag add/edit -- Grid is slow to respond loading when books aren't liberated -- get decrypt key -- unavoidable - -Create release version and installer -https://dotnetcoretutorials.com/2019/06/20/publishing-a-single-exe-file-in-net-core-3-0/ +RELEASE TO BETA +- Create release version and installer + https://dotnetcoretutorials.com/2019/06/20/publishing-a-single-exe-file-in-net-core-3-0/ +- Warn of known performance issues + - Library import + - Tag add/edit + - Grid is slow to respond loading when books aren't liberated + - get decrypt key -- unavoidable -- end BETA --------------------------------------------------------------------------------------------------------------------- -- begin ENHANCEMENT, IMPORT UI ---------------------------------------------------------------------------------------------------------------------