public static void GetImageFromGravatar(string imageFileName, string email, int authorImageSize, FallBackService fallBack) { try { var imageUrl = BuildGravatarUrl(email, authorImageSize, false, Rating.G, fallBack); var webClient = new WebClient { Proxy = WebRequest.DefaultWebProxy }; webClient.Proxy.Credentials = CredentialCache.DefaultCredentials; var imageStream = webClient.OpenRead(imageUrl); cache.CacheImage(imageFileName, imageStream); } catch (Exception ex) { //catch IO errors Trace.WriteLine(ex.Message); } }
public static void GetImageFromGravatar(string imageFileName, string email, int authorImageSize, FallBackService fallBack) { try { var baseUrl = String.Concat("http://www.gravatar.com/avatar/{0}?d=identicon&s=", authorImageSize, "&r=g"); if (fallBack == FallBackService.Identicon) { baseUrl += "&d=identicon"; } if (fallBack == FallBackService.MonsterId) { baseUrl += "&d=monsterid"; } if (fallBack == FallBackService.Wavatar) { baseUrl += "&d=wavatar"; } //hash the email address var emailHash = MD5.CalcMD5(email.ToLower()); //format our url to the Gravatar var imageUrl = String.Format(baseUrl, emailHash); var webClient = new WebClient { Proxy = WebRequest.DefaultWebProxy }; webClient.Proxy.Credentials = CredentialCache.DefaultCredentials; var imageStream = webClient.OpenRead(imageUrl); cache.CacheImage(imageFileName, imageStream); } catch (Exception ex) { //catch IO errors Trace.WriteLine(ex.Message); } }