HaterAide ORM updated to 1.6

I've been quite for a while. The reason for this is two fold. First, I've been on vacation for a while with minimal access to the internet. The second reason is I've been working a lot on HaterAide ORM. For those that never read the series, HaterAide was a learning project for me. I wanted to see how difficult it was to create a basic ORM, what the "magic" was behind them, etc. I find that recreating the wheel is the best way for me to learn something and I've definitely learned a lot thus far from working on it. Since the initial postings and release it has added a number of features that put it up to the level of half way decent (we're even using it at my work now). This release added a number of features including:

1) Added transaction support
2) Added paging support
3) Added ability to override the default table and column names
4) Added ability to mark the database read only or write only
5) Added ability to do batch saving (calling Save when sending in a list of objects will save the entire list in one transaction).
6) Speed increases for all IEnumerables.
7) General speed increases for saving items.
8) Non int/GUID primary keys now work.
9) Size of DLLs reduced considerably.
10) Added the ability to save an object as a sub type.
11) Solution is now Visual Studio 2010
12) Separated database config data so that in the future multiple databases can be supported
13) Added switch so you can auto update the database or manually update the structure of the database.
14) DotCache, Aspectus, and Gestalt are integrated to make the system more modular.
15) Added better checks for null values/non existant objects in the database

Plus a number of fixes. I still need to add features like multiple databases, composite keys, etc. but it's coming along. So give it a look, try it out (usage documentation is included in this release), and happy coding.

Edit: It helps if I put a link to the new download...

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 8/17/2010 at 5:16 PM
Tags: , ,
Categories: General
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

UUID Doesn't Match Error When Using SVN

Just a quick update, for anyone who is using CodePlex for any sort of code repository (or you like getting the updates for my projects, etc), you'll notice a potential error that you'll get. You may end up getting something along the lines of "Repository UUID 'whatever' doesn't match expected UUID 'another GUID'. In order to fix this the people at CodePlex are saying to do a fresh checkout. That's all well and fine as long as you don't have 20 updates that need to go into the repository (which I did as I'm a bit lazy on the commits). An easier way (at least for me) was to find the "entries" file in the .svn directories and simply change the UUID from what they currently say to what svn wants. I did this simply using NotePad++, using "Replace In Files". Of course you need to make sure you set the files to writable first instead of Read Only but whatever. You can also go and take a look here for another approach.

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 7/30/2010 at 4:53 PM
Tags: ,
Categories: General
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Embedding an Image in an Email in C#

One of the things that I was tasked with this past week was creating an app to help with email marketing. And before you ask, not spam... Well sort of spam, but it's internal to the company. Anyway, the application was to send nice, HTML formatted emails. One of the things they wanted though was embedded images within the email's text. Turns out, it's incredibly simple to do:

public class EmailSender : Message

    {

        #region Constructors

 

        /// <summary>

        /// Default Constructor

        /// </summary>

        public EmailSender()

        {

            Attachments = new List<Attachment>();

            EmbeddedResources = new List<LinkedResource>();

            Priority = MailPriority.Normal;

        }

 

        #endregion

 

        #region Public Functions

 

        /// <summary>

        /// Sends an email

        /// </summary>

        /// <param name="Message">The body of the message</param>

        public void SendMail(string Message)

        {

            try

            {

                Body = Message;

                SendMail();

            }

            catch { throw; }

        }

 

        /// <summary>

        /// Sends a piece of mail asynchronous

        /// </summary>

        /// <param name="Message">Message to be sent</param>

        public void SendMailAsync(string Message)

        {

            try

            {

                Body = Message;

                ThreadPool.QueueUserWorkItem(delegate { SendMail(); });

            }

            catch { throw; }

        }

 

        /// <summary>

        /// Sends an email

        /// </summary>

        public void SendMail()

        {

            try

            {

                using (System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage())

                {

                    char[] Splitter = { ',' };

                    string[] AddressCollection = To.Split(Splitter);

                    for (int x = 0; x < AddressCollection.Length; ++x)

                    {

                        message.To.Add(AddressCollection[x]);

                    }

                    if (!string.IsNullOrEmpty(CC))

                    {

                        AddressCollection = CC.Split(Splitter);

                        for (int x = 0; x < AddressCollection.Length; ++x)

                        {

                            message.CC.Add(AddressCollection[x]);

                        }

                    }

                    if (!string.IsNullOrEmpty(Bcc))

                    {

                        AddressCollection = Bcc.Split(Splitter);

                        for (int x = 0; x < AddressCollection.Length; ++x)

                        {

                            message.Bcc.Add(AddressCollection[x]);

                        }

                    }

                    message.Subject = Subject;

                    message.From = new System.Net.Mail.MailAddress((From));

                    AlternateView BodyView = AlternateView.CreateAlternateViewFromString(Body, null, MediaTypeNames.Text.Html);

                    foreach (LinkedResource Resource in EmbeddedResources)

                    {

                        BodyView.LinkedResources.Add(Resource);

                    }

                    message.AlternateViews.Add(BodyView);

                    //message.Body = Body;

                    message.Priority = Priority;

                    message.SubjectEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");

                    message.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");

                    message.IsBodyHtml = true;

                    foreach (Attachment TempAttachment in Attachments)

                    {

                        message.Attachments.Add(TempAttachment);

                    }

                    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(Server, Port);

                    if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))

                    {

                        smtp.Credentials = new System.Net.NetworkCredential(UserName, Password);

                    }

                    if (UseSSL)

                        smtp.EnableSsl = true;

                    else

                        smtp.EnableSsl = false;

                    smtp.Send(message);

                }

            }

            catch { throw; }

        }

 

        /// <summary>

        /// Sends a piece of mail asynchronous

        /// </summary>

        public void SendMailAsync()

        {

            try

            {

                ThreadPool.QueueUserWorkItem(delegate { SendMail(); });

            }

            catch { throw; }

        }

 

        #endregion

 

        #region Properties

 

        /// <summary>

        /// Any attachments that are included with this

        /// message.

        /// </summary>

        public List<Attachment> Attachments { get; set; }

 

        /// <summary>

        /// Any attachment (usually images) that need to be embedded in the message

        /// </summary>

        public List<LinkedResource> EmbeddedResources { get; set; }

 

        /// <summary>

        /// The priority of this message

        /// </summary>

        public MailPriority Priority { get; set; }

 

        /// <summary>

        /// Server Location

        /// </summary>

        public string Server { get; set; }

 

        /// <summary>

        /// User Name for the server

        /// </summary>

        public string UserName { get; set; }

 

        /// <summary>

        /// Password for the server

        /// </summary>

        public string Password { get; set; }

 

        /// <summary>

        /// Port to send the information on

        /// </summary>

        public int Port { get; set; }

 

        /// <summary>

        /// Decides whether we are using STARTTLS (SSL) or not

        /// </summary>

        public bool UseSSL { get; set; }

 

        /// <summary>

        /// Carbon copy send (seperate email addresses with a comma)

        /// </summary>

        public string CC { get; set; }

 

        /// <summary>

        /// Blind carbon copy send (seperate email addresses with a comma)

        /// </summary>

        public string Bcc { get; set; }

 

        #endregion

    }

The code above is a helper class from my utility library. In it there are fields for To, From, the SMTP server location, etc. The field we're interested in is EmbeddedResources. That field is a list of LinkedResource. A LinkedResource is exactly like the name says, a linked resource. An image, etc. that is attached to the email and usable within it. In order to use it, you must first tell it where to look for the image (new LinkedResource(ImageLocation)) and then set a content ID (the ContentId property) which is just a string name. Once that is set, you can link to it from inside your email. For example, if we set the ContentId to "MyImage", we can use it like this:

<html><body><img src='cid:MyImage' /></body></html>

That's it. With that set as the body of our text and the LinkedResource added to our email, we're good. It doesn't work 100% on all systems (gmail seems to fail), but for most email apps (Outlook, etc.) it works rather well. Anyway, I personally can only think of one use for this but maybe I'm wrong. Maybe you're not going to use this for "marketing" purposes (ie spam). You never know. So try it out and happy coding.

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 7/29/2010 at 10:41 AM
Tags: , ,
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed