Pre-beta: picture storage should be more responsive if on disk
This commit is contained in:
parent
e69df2abbc
commit
47360c036d
@ -42,7 +42,13 @@ namespace FileManager
|
|||||||
public static (bool isDefault, byte[] bytes) GetPicture(PictureDefinition def)
|
public static (bool isDefault, byte[] bytes) GetPicture(PictureDefinition def)
|
||||||
{
|
{
|
||||||
if (!cache.ContainsKey(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));
|
return (cache[def] == null, cache[def] ?? getDefaultImage(def.Size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,33 +70,19 @@ namespace FileManager
|
|||||||
return;
|
return;
|
||||||
isProcessing = true;
|
isProcessing = true;
|
||||||
|
|
||||||
PictureDefinition def;
|
var def = cache
|
||||||
string path;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
def = cache
|
|
||||||
.Where(kvp => kvp.Value is null)
|
.Where(kvp => kvp.Value is null)
|
||||||
.Select(kvp => kvp.Key)
|
.Select(kvp => kvp.Key)
|
||||||
// 80x80 should be 1st since it's enum value == 0
|
// 80x80 should be 1st since it's enum value == 0
|
||||||
.OrderBy(d => d.PictureId)
|
.OrderBy(d => d.PictureId)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
// no more null entries. all requsted images are cached
|
// no more null entries. all requsted images are cached
|
||||||
if (string.IsNullOrWhiteSpace(def.PictureId))
|
if (string.IsNullOrWhiteSpace(def.PictureId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path = getPath(def);
|
var bytes = downloadBytes(def);
|
||||||
// we found the next one to download
|
saveFile(def, bytes);
|
||||||
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);
|
|
||||||
cache[def] = bytes;
|
cache[def] = bytes;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@ -98,12 +90,18 @@ namespace FileManager
|
|||||||
isProcessing = false;
|
isProcessing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpClient imageDownloadClient { get; } = new HttpClient();
|
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 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 imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result;
|
||||||
return bytes;
|
}
|
||||||
|
|
||||||
|
private static void saveFile(PictureDefinition def, byte[] bytes)
|
||||||
|
{
|
||||||
|
var path = getPath(def);
|
||||||
|
File.WriteAllBytes(path, bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
__TODO.txt
41
__TODO.txt
@ -1,30 +1,27 @@
|
|||||||
-- begin BETA ---------------------------------------------------------------------------------------------------------------------
|
-- 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]
|
||||||
|
|
||||||
|
RELEASE TO BETA
|
||||||
download now incl pdf
|
- Create release version and installer
|
||||||
pdf menu should be 'PDFs only'
|
https://dotnetcoretutorials.com/2019/06/20/publishing-a-single-exe-file-in-net-core-3-0/
|
||||||
|
- Warn of known performance issues
|
||||||
update wording in menu
|
- Library import
|
||||||
update readme
|
- Tag add/edit
|
||||||
|
- Grid is slow to respond loading when books aren't liberated
|
||||||
|
- get decrypt key -- unavoidable
|
||||||
|
|
||||||
|
|
||||||
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/
|
|
||||||
-- end BETA ---------------------------------------------------------------------------------------------------------------------
|
-- end BETA ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- begin ENHANCEMENT, IMPORT UI ---------------------------------------------------------------------------------------------------------------------
|
-- begin ENHANCEMENT, IMPORT UI ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user