Design and implement a template engine – part 1

Recently, I got a task which is typical in many systems: Template with merge fields. The common usage is for email.

Given that an employee is created, the system will notify the manager by email with template:

Dear Manager,

New employee {Name} has been created on {DateTime.Now}.

From the above statement, we have template with 2 merged fields: Employee Name and Created Date. There are some solutions. But I name the old way of doing it here for reference:

Replace merge fields using string.Replace or Regex.

You can imagine it and how to do it. Or you event did it some times.

A better approach: Take advantages of Razor Engine.

The template will be in razor syntax

Dear Manager,

New employee @Model.EmployeeName has been created on @DateTime.Now.ToString(“s”).

In the next post, I will discuss about implementation.

Things i should pay attention and improve immediately

There are so many tittle but important things that I have not paid any attention to for 30 years. For the past couple of months, I started reading more books about self-improvement, and due to the fact that I am father of my daughter, and I want to be a good father, a good husband. I started to look around for improvement.

In this post, I will just list out all the things I want to improve. And for each section, I plan to write many posts about it.

Personal lifestyle

  1. Keep on gym exercise, focus a lot on running
  2. Improve sitting posture. I am a developer but I created a very bad posture which hurts me a lot in long term
  3. Read more book

Career

  1. Expand knowledge to other area such as: Node.js, ReactiveUI, ReactiveX (Rx). Can be anything, will design later
  2. Focus time for business, work smart and hard with 180-200 hours/month

Family

It is the most important thing. I place it last since I do not want to change it or to emphasize it. It is a fact. I always want to create a fun – healthy – wealthy family. All my goals, my plan, my to-do are for it.

Get started – again

It has been a while I have not written anything. And I almost forgot that I do have a blog. Fortunately, from this August, I set some big goals for my life, targeting in next 2 years. As I learn from “Getting things done”, I better write them down and get started. Goals are not goals without writing them down.

Here they are:

  1. Work for 180-200 hours per month
  2. Running 5 KM within 30 minutes
  3. Spend time with my family – this is always a priority for me
  4. Improve English – just by writing blog is a good way and a good start
  5. Quit smoking completely (I have done this at the time of writing, I have not smoked for 3 weeks)

I love drinking and I love hanging around with friends. To archive those goals, things will have a slightly change. I need time and power for my week days. Therefore, here are rules:

  1. No drinking in the week days, except: wedding party
  2. Drink only on Friday, Saturday nights
  3. Avoid drink on Sunday (can drink but not much). The purpose is to have energy for next week.