domingo, 21 de abril de 2013

Sending Email (Part 1)

Sending Email (Part 1)

Email functionality is a common feature in many applications, which can be triggered by user action (ex.: email confirmation after buying a online product) or direct email (ex.: newsletter).

Normally this is done in about 4 steps:
  1. Get template from some source: database, file, etc.. 
  2. Get a business object with information to be personalized;
  3. Configure message body to be sent;
  4. Send Email.
One important task is prepare the message to be sent (3), we have several solution, lets analyze some.

Solution 1: Make template with tags to be replaced later. Example:
var template = "Hi [Name], Here's some activity you may have missed on Facebook.";
string messageBody = template.Replace("[Name]", "Adilson");

Problem of this Solution:
  • Hard to configure the template according to the business data. Ex.: To send list of news we have to do more than find replace tags..

Solution 2: Using Razor Engine(open source project) to build templates. Example:
string template = "Hi @Model.Name, Here's some activity you may have missed on Facebook.";
string messageBody = Razor.Parse(template, new { Name = "Adilson" });

Problem of this Solution: 
  • Still less flexible..

Solution 3: Using XML and XSLT to transform documets and to get HTML.


This solution is more flexible than the previous two, as it allow us to use the power of XSLT to Transform documents. More about XSLT can be found in any search engine, but this is my suggestion: w3schools

How to get message body using solution 3:
  1. Get XSLT file (template);
  2. Get XML: serializing the business object;
  3. Call the processor given the XSLT and XML to generate the HTML(message body).

Suppose we are looking to send this newsletter:

Your Logo Here
Date Here
Issue #
Newsletter Title Here
USER GRETINGS...

NEWS TITLE 1
NEWS TITLE 2
advertisement here
TITLE 1

TEXT NEWS 1... Read Full Article
TITLE 2

TEXT NEWS 2 ... Read Full Article
Copyright © 2013 Your Company Name. All Rights Reserved.

So to implement solution 3, lets summarize the steps:
  1. Get template from some source: XSLT File;
  2. Get a business object with information to personalize: Serializing to XML;
  3. Configure message body to be sent: Applying XSLT Processor to get the message body;
  4. Send Email.
Implementation will be in the next Post.

quinta-feira, 18 de abril de 2013

.Net Developers vs Java Developers

.NET Developers vs .Java Developers

Is easy to find over internet, for example click here, forums discussing about .Net vs Java Developers. I would like add my point of view as well..

Typically, the goal of this discussion is to understand, which developers group, are better. I had similar discussion about 10 years ago, when I was at university in Portugal, discussing about which University was better!

Sometimes or most of the time, this discussion doesn't make sense, because people want to "know" the smarter groups, rather than they ability to build Applications.

For .NET developers, Microsoft is doing a great job putting a lot of effort to improve .NET (click here for more info) And this great job has some benefits for .Net Developers, as is making the live easy for them.

Java developers, doesn't have a big "daddy", like Microsoft! So they develop the ability to work together, and build thousands of Open source communities that have been doing a great job, helping and pushing the group to use the best available practices. So to talk each other effectively, as a big team, with no doubts about, they had to push for Design Patterns. Downside for Java developers is that, very easy to get lost, as there are, sometimes, many alternatives for the some thing, not good documentation and so hard to configure.

Going back to .Net developers, downside of Microsoft efforts, is that developers gain the habit of "eat a ready food". That was OK, for most of the project yeas ago, as they were small in the early years of .Net. But not Nowadays,  is not true as there are many big projects to build and maintain in a very powerful tool: .Net Framework.

Microsoft is pushing developers to work in agile environment, and build more open source communities much more than before, basically recognizing that isn't easy prescind the "eyes" and R&D of thousands of people around the world. One example is ASP.NET MVC Framework.

So as a .NET developer, for the next articles I will share my thoughts about Programming in .NET, based in my experiences and researches, with main focus on design patterns and data structure.

Thanks for your time:)