Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Generates an email hash as per the Gravatar specifications.
 /// </summary>
 /// <param name="email">The email to hash.</param>
 /// <returns>The hash of the email.</returns>
 /// <remarks>
 /// The process of creating the hash are specified at http://en.gravatar.com/site/implement/hash/
 /// </remarks>
 private static string HashEmail(string email)
 {
     return(MD5.CalcMD5(email.Trim().ToLowerInvariant()));
 }