Esempio n. 1
0
        private async Task <Image> DownloadImage(Uri imageUrl, string imageFileName)
        {
            try
            {
                using (var webClient = new WebClient {
                    Proxy = WebRequest.DefaultWebProxy
                })
                {
                    webClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
                    using (var imageStream = await webClient.OpenReadTaskAsync(imageUrl))
                    {
                        await _cache.AddImageAsync(imageFileName, imageStream);
                    }

                    return(await _cache.GetImageAsync(imageFileName, null));
                }
            }
            catch (Exception ex)
            {
                // catch IO errors
                Trace.WriteLine(ex.Message);
            }

            return(null);
        }
Esempio n. 2
0
 private async Task <Image> LoadFromGravatarAsync(string imageFileName, string email, int imageSize, DefaultImageType defaultImageType)
 {
     try
     {
         var imageUrl = BuildGravatarUrl(email, imageSize, false, Rating.G, defaultImageType);
         using (var webClient = new WebClient {
             Proxy = WebRequest.DefaultWebProxy
         })
         {
             webClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
             using (var imageStream = await webClient.OpenReadTaskAsync(imageUrl))
             {
                 await _cache.AddImageAsync(imageFileName, imageStream);
             }
             return(await _cache.GetImageAsync(imageFileName, null));
         }
     }
     catch (Exception ex)
     {
         //catch IO errors
         Trace.WriteLine(ex.Message);
     }
     return(null);
 }