Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Brendan Tompkins

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 License.

October 2007 - Posts

  • LOLCat Compiler for the CLR...

    How come I didn't know about this until today? I can't believe we got scooped by BoingBoing! 

    LOLCode is an emerging esoteric (and hilarious) language based on the dialect used in LOLCats images. It's been siezed upon by a group of people (myself included, now), and is being expanded into a real, workable, turing complete esoteric language (though nobody has proven its turing completeness yet!).

    Fantastic

  • Using Embedded Resources for HTML Email Templates

    Most web applications need to send out email for a variety of purposes, right?   I like to use email as a sort of extended user interface - allowing entry points to let the user conveniently do work by getting an email and clicking on a link.  I've struggled for a while with a good way of managing email templates to use in my applications.  I recently found a good project that simplifies the process of templating - See Alexander Kleshchevnikov's excellent solution for managing and sending emails inside a web application.

    I like his template approach, but I don't like to keep my template files in a directory with my web project, mainly because it tightly couples these files and a certain directory structure to the classes that actually do the email work.  This makes my classes harder to test, re-use and deploy.  I recently figured out how to embed these templates into my class' assembly files, making the class much more useful. 

    To embed a resource, just drop it in your project, and select "Embedded Resource" 


    Using Alexander's solution for templating, and an embedded resource html file for a template, the code to use this resource looks like this:

            public static void SendRegisterNotification(User user)
            {
                Hashtable templateVars = new Hashtable();
                templateVars.Add("FirstName", user.FirstName);
                templateVars.Add("LastName", user.LastName);
                templateVars.Add("Login", user.UserId);
                templateVars.Add("Password", user.Password);
    
                Parser parser = new Parser(templateVars);
                Assembly asm = Assembly.GetExecutingAssembly();
                Stream stream = asm.GetManifestResourceStream(asm.GetName().Name +
                    ".Registration.htm");
    
                using (StreamReader reader = new StreamReader(stream))
                {
                    parser.TemplateBlock  = reader.ReadToEnd();
                }
    
                // Send email
                System.Net.Mail.MailMessage message = 
                      new System.Net.Mail.MailMessage();
                message.To.Add(user.Email);
                message.From = new MailAddress("brendan.tompkins@gmail.com");
                message.Subject = "Your StreetTurns.Com Account Information";
                message.Body = parser.Parse();
                message.IsBodyHtml = true;
                SmtpClient sc = new SmtpClient("StreetTurns.Com");
                sc.Send(message);
            }
    

    Yes, but what about Modifying your Templates?

    As Jeremy Miller has pointed out, you shouldn't be afraid to compile and release your code.  If you are, you need some serious work on your build process.  To me, the benefit of having one class that I can drop anywhere without worrying about permissions, file paths, and all that far outweighs the need to re-build the DLL when I make a text change.

    I'm pretty happy about the way this all works.  For more on embedded resources, ther's some information here and here about how you can access your resources via a URL in a web app.

  • RE: MSDN Subscriptions - Are They Worth It?

    Mike asks a good question MSDN - Is it worth it?

    I have two, count em, two subscriptions (work + MVP) .. and other than the occasional download of an OS or SQL server installation for convenience, I almost never use either of them.  As a responsible employee (consultant in my case) I really should weigh my decision to continue having my client purchase this for me and the other developers here.   It's a good resource, but really only in the software-packrat/i have to have it all cause maybe I'll need it someday sense.  In reality, it think it's a bit wasteful.  

    I've often heard people comment that cost is no concern to them when their employer is footing the bill (Enterprise software vendors can thank their lucky stars for the prevalence of this attitude BTW). But as smart consultant once commented, every dollar I can save a client is a dollar they can afford to pay my invoices, and I believe it. Full time employees should think along those same lines, but even if you don't care about saving your employer money, wasting money is just plain, well wasteful. Like leaving a light on when you don't need it - it's not doing anyone anyone any good and doesn't help build an economy that is sustainable with healthy growth and innovation.

    While I'm on the topic waste, the MSDN DVDs are nice to have, but talk about putting a big dent in your carbon footprint.  I'd say I end up shredding 99% of the DVDs I get mailed and the other 1% I've lost somewhere...

    Does this sound preachy?  I hope not, in fact, I personally need to cancel one of my subscriptions and opt out of my DVD media coming in the mail.  I need to stop getting VAR business magazine and all those other magazines which I don't read. I need to help cut  my technical waste, be it financial or paper and plastic.

    On the other hand, I just may need that MOM 2005 with SP1 disk someday, you never know....
     

     

More Posts

Our Sponsors

Proudly Partnered With