From 9364a3e4eadba90357d2ae94f72f8b37b5988989 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sun, 26 Jan 2014 01:54:26 -0500 Subject: [PATCH] initial commit --- .NETGravatarWrapper | 1 + .../GravatarWrapper.Test.csproj | 90 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++ GravatarWrapper.Test/UnitTest1.cs | 23 +++++ GravatarWrapper.sln | 26 ++++++ GravatarWrapper/GravatarWrapper.cs | 50 +++++++++++ GravatarWrapper/GravatarWrapper.csproj | 60 +++++++++++++ GravatarWrapper/Properties/AssemblyInfo.cs | 36 ++++++++ GravatarWrapper/packages.config | 4 + 9 files changed, 326 insertions(+) create mode 160000 .NETGravatarWrapper create mode 100644 GravatarWrapper.Test/GravatarWrapper.Test.csproj create mode 100644 GravatarWrapper.Test/Properties/AssemblyInfo.cs create mode 100644 GravatarWrapper.Test/UnitTest1.cs create mode 100644 GravatarWrapper.sln create mode 100644 GravatarWrapper/GravatarWrapper.cs create mode 100644 GravatarWrapper/GravatarWrapper.csproj create mode 100644 GravatarWrapper/Properties/AssemblyInfo.cs create mode 100644 GravatarWrapper/packages.config diff --git a/.NETGravatarWrapper b/.NETGravatarWrapper new file mode 160000 index 0000000..eb9e711 --- /dev/null +++ b/.NETGravatarWrapper @@ -0,0 +1 @@ +Subproject commit eb9e711c8bbf4cdf6d12cca2d0bef5c6a0174dbf diff --git a/GravatarWrapper.Test/GravatarWrapper.Test.csproj b/GravatarWrapper.Test/GravatarWrapper.Test.csproj new file mode 100644 index 0000000..85719de --- /dev/null +++ b/GravatarWrapper.Test/GravatarWrapper.Test.csproj @@ -0,0 +1,90 @@ + + + + Debug + AnyCPU + {7CA99791-0CF2-461D-9A94-C647111FA0E8} + Library + Properties + GravatarWrapper.Test + GravatarWrapper.Test + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + {c14035fc-74a1-42ff-bd3a-dd8a9ca8cec4} + GravatarWrapper + + + + + + + False + + + False + + + False + + + False + + + + + + + + \ No newline at end of file diff --git a/GravatarWrapper.Test/Properties/AssemblyInfo.cs b/GravatarWrapper.Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e7c5c93 --- /dev/null +++ b/GravatarWrapper.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("GravatarWrapper.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GravatarWrapper.Test")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("eeadd6c8-f104-4bc2-8027-42968485af46")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GravatarWrapper.Test/UnitTest1.cs b/GravatarWrapper.Test/UnitTest1.cs new file mode 100644 index 0000000..fb6b01e --- /dev/null +++ b/GravatarWrapper.Test/UnitTest1.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace GravatarWrapper.Test +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + var req = GravatarWrapper.Request("test@mctest.com", 400); + if (req != null) + { + req.Save(@"c:\users\test\Desktop\bmp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); + } + else + { + Assert.Fail(); + } + } + } +} diff --git a/GravatarWrapper.sln b/GravatarWrapper.sln new file mode 100644 index 0000000..2eba8f2 --- /dev/null +++ b/GravatarWrapper.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GravatarWrapper", "GravatarWrapper\GravatarWrapper.csproj", "{C14035FC-74A1-42FF-BD3A-DD8A9CA8CEC4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GravatarWrapper.Test", "GravatarWrapper.Test\GravatarWrapper.Test.csproj", "{7CA99791-0CF2-461D-9A94-C647111FA0E8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C14035FC-74A1-42FF-BD3A-DD8A9CA8CEC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C14035FC-74A1-42FF-BD3A-DD8A9CA8CEC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C14035FC-74A1-42FF-BD3A-DD8A9CA8CEC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C14035FC-74A1-42FF-BD3A-DD8A9CA8CEC4}.Release|Any CPU.Build.0 = Release|Any CPU + {7CA99791-0CF2-461D-9A94-C647111FA0E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7CA99791-0CF2-461D-9A94-C647111FA0E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7CA99791-0CF2-461D-9A94-C647111FA0E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7CA99791-0CF2-461D-9A94-C647111FA0E8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/GravatarWrapper/GravatarWrapper.cs b/GravatarWrapper/GravatarWrapper.cs new file mode 100644 index 0000000..1724096 --- /dev/null +++ b/GravatarWrapper/GravatarWrapper.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Security.Cryptography; +using RestSharp; +using System.Drawing; +using System.IO; + +namespace GravatarWrapper +{ + public static class GravatarWrapper + { + private static string HashEmailForGravatar(string email) + { + email = email.ToLower(); + //MD + var md5Hasher = MD5.Create(); + + var data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(email)); + + var sBuilder = new StringBuilder(); + + foreach (var x in data) + { + sBuilder.Append(x.ToString("x2")); + } + + return sBuilder.ToString(); // Return the hexadecimal string. + } + + public static Bitmap Request(string email, int size) + { + var client = new RestClient("http://www.gravatar.com/avatar/" + HashEmailForGravatar(email)); + var req = new RestRequest(Method.GET); + req.AddParameter("d", "%22%22" ); + req.AddParameter("s", size); + var res = client.Execute(req); + if (res != null) + { + var imagebytes = res.RawBytes; + var ms = new MemoryStream(imagebytes); + return new Bitmap(ms); + //img.Save(@"c:\bmp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); + } + return null; + } + } +} diff --git a/GravatarWrapper/GravatarWrapper.csproj b/GravatarWrapper/GravatarWrapper.csproj new file mode 100644 index 0000000..bfff557 --- /dev/null +++ b/GravatarWrapper/GravatarWrapper.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {C14035FC-74A1-42FF-BD3A-DD8A9CA8CEC4} + Library + Properties + GravatarWrapper + GravatarWrapper + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\RestSharp.104.4.0\lib\net4\RestSharp.dll + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GravatarWrapper/Properties/AssemblyInfo.cs b/GravatarWrapper/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..730e896 --- /dev/null +++ b/GravatarWrapper/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("GravatarWrapper")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GravatarWrapper")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3f39c40e-2c16-4f6e-81b7-65ba1c53ee71")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GravatarWrapper/packages.config b/GravatarWrapper/packages.config new file mode 100644 index 0000000..7766ab8 --- /dev/null +++ b/GravatarWrapper/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file