public static (bool isDefault, byte[] bytes) GetPicture(PictureDefinition def) { if (!cache.ContainsKey(def)) { var path = getPath(def); cache[def] = File.Exists(path) ? File.ReadAllBytes(path) : null; } return(cache[def] == null, cache[def] ?? getDefaultImage(def.Size)); }
private static void saveFile(PictureDefinition def, byte[] bytes) { var path = getPath(def); File.WriteAllBytes(path, bytes); }
private static string getPath(PictureDefinition def) => Path.Combine(ImagesDirectory, $"{def.PictureId}{def.Size}.jpg");
private static byte[] downloadBytes(PictureDefinition def) { var sz = def.Size.ToString().Split('x')[1]; return(imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result); }