static Image LoadLogoImage(string currencyName, bool allowDownload) { Image res = null; try { if (string.IsNullOrEmpty(currencyName)) { return(null); } Debug.Write("loading logo: " + currencyName); string fileName = GetIconFileName(currencyName); if (File.Exists(fileName)) { Debug.WriteLine(" - done"); return(Image.FromFile(fileName)); } if (!allowDownload) { return(null); } string logoUrl = null; if (!CurrencyLogo.TryGetValue(currencyName, out logoUrl) || string.IsNullOrEmpty(logoUrl)) { return(null); } byte[] imageData = new WebClient().DownloadData(logoUrl); if (imageData == null) { return(null); } MemoryStream stream = new MemoryStream(imageData); res = Image.FromStream(stream); res.Save(fileName); } catch (Exception e) { Debug.WriteLine(" - error: " + e.Message); return(null); } return(res); }
public static void BuildIconsDataBase(IEnumerable <string[]> list, bool allowDownload) { CurrencyLogo.Clear(); foreach (string[] str in list) { if (string.IsNullOrEmpty(str[0]) || string.IsNullOrEmpty(str[1]) || str[1] == "null") { continue; } if (!CurrencyLogo.ContainsKey(str[0])) { CurrencyLogo.Add(str[0], str[1]); } if (!CurrencyLogoImage.ContainsKey(str[0])) { Image res = LoadLogoImage(str[0], allowDownload); if (res != null && !CurrencyLogoImage.ContainsKey(str[0])) { CurrencyLogoImage.Add(str[0], res); } } } }