summaryrefslogtreecommitdiffstats
path: root/SendGrid/SendGridMail/Utils.cs
diff options
context:
space:
mode:
authorCJ Buchmann <cj.buchmann@sendgrid.com>2012-01-12 19:24:30 -0800
committerCJ Buchmann <cj.buchmann@sendgrid.com>2012-01-12 19:24:30 -0800
commit13ea4240f2e863704320ae7c0dc62a6f59d592f0 (patch)
tree93774191f19422b6e61e4c16916f3f0c4ea1a7ce /SendGrid/SendGridMail/Utils.cs
parent48068853163d337f34cd1f971361d6caf97bd7a7 (diff)
downloadsendgrid-csharp-13ea4240f2e863704320ae7c0dc62a6f59d592f0.zip
sendgrid-csharp-13ea4240f2e863704320ae7c0dc62a6f59d592f0.tar.gz
sendgrid-csharp-13ea4240f2e863704320ae7c0dc62a6f59d592f0.tar.bz2
Got All parts of the REST api working, except file attachments.
Diffstat (limited to 'SendGrid/SendGridMail/Utils.cs')
-rwxr-xr-xSendGrid/SendGridMail/Utils.cs52
1 files changed, 52 insertions, 0 deletions
diff --git a/SendGrid/SendGridMail/Utils.cs b/SendGrid/SendGridMail/Utils.cs
new file mode 100755
index 0000000..cb6413c
--- /dev/null
+++ b/SendGrid/SendGridMail/Utils.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Pipes;
+using System.Linq;
+using System.Net;
+using System.Net.Mail;
+using System.Runtime.Serialization.Json;
+using System.Text;
+
+namespace SendGridMail
+{
+ public class Utils
+ {
+ public static string Serialize<T>(T obj)
+ {
+ var serializer = new DataContractJsonSerializer(obj.GetType());
+ using (var stream = new MemoryStream())
+ {
+ serializer.WriteObject(stream, obj);
+ var jsonData = Encoding.UTF8.GetString(stream.ToArray(), 0, (int)stream.Length);
+ return jsonData;
+ }
+ }
+
+ public static string SerializeDictionary(IDictionary<String, String> dic)
+ {
+ return "{"+String.Join(",",dic.Select(kvp => Serialize(kvp.Key) + ":" + Serialize(kvp.Value)))+"}";
+ }
+
+ public static Dictionary<String, Stream> PrepareAttachments()
+ {
+ var attach = new Attachment("D:/att_proj/21.jpg");
+ Console.WriteLine("preparing message attachment");
+ var sr = new StreamReader(attach.ContentStream);
+
+ Console.WriteLine(sr.ReadToEnd());
+
+ Console.WriteLine(":D");
+ var request = (HttpWebRequest)WebRequest.Create("");
+
+
+ //attach.ContentStream.CopyTo(request.GetRequestStream());
+
+ Console.WriteLine("attachment: ");
+
+ Console.WriteLine("DONE");
+
+ return new Dictionary<string, Stream>();
+ }
+ }
+}