July, 2009 Archives

19
Jul

Content Management with Umbraco CMS v4

by Mikael Lundin in Technicalities

I’ve been having a couple of weeks vacation and been quite slow on blogging. But that will change now when I start working again. Strangely I thought I would blog every day on my vacation due to lack of things to do.

During my vacation I took some time to discover Umbraco, so I spent some hours building a website for my friend Karin and her hobby/business. I will try to review this CMS here.

The good things

Umbraco is a very easy CMS to get up and running. There are some good guides is you get stuck and the procedure is very straight forward. I believe that they could make it even easier with a simple MSI, but I found it easy enough.

When the CMS is installed on an IIS instance you are able to edit everything from within the web interface. This has its uses when you need to make a quick fix for some failing functionality, but it could be real dangerous if you start working without a version control system and also, it is not a very nice user interface for programming. However, this seems to be they way you should work with Umbraco.

All the standard stuff is there – the site tree with all the pages, the wastebasket and the user management with different roles and permissions. If you’ve been working with a CMS before you’ll know what to do immediately.

The page templates are ASPX pages and on these you can place your own user controls or Umbraco Macros.  These macros are like user controls as they represent parts of a page. But additional to ASCX they could be XSLT or Python. This is very useful because the whole site tree is XML. So, lets say that you need a menu for your site, you can transform the sitetree XML with an XSLT to create the menu. The result of this is that you only need hardcore backend coding when it is a backend hardcore task. Any pagetree/property manipulation could be done in XSLT which is nice.

The bad things

It is very easy to give up Visual Studio and do the whole development inside the CMS, especially if you’re developing a very small and simple site. My project was only 4 days and I only spent 2-3 hours of those in Visual Studio. This made me loose refactoring tools, code coloring and version control. This could be a discipline thing, but the CMS editor is too simple to exist and I actually wish that it was not there.

I would wish some more documentation. Most of the documentation I found was on blogs. Even such a simple thing as how I get a property value inside an html attribute took me two hours to figure out. I could not find a simple example anywhere.

I’m really missing some features like friendly URLs, customizable blog or contact/e-mail functionality. It is easy enough to code yourself, but these things are so general that they should be included.

The conclusion

Umbraco CMS v4 is a simple CMS platform that I could recommend for small websites. It has all the basic functionality and makes it easy enough for the editors to handle the content. The XSLT integration is fantastic but I would really expect more ready to use functions.

1
Jul

LUHN validation with F#

by Mikael Lundin in Programming

I’m on vacation, and since I’m a nerd I take that amount of spare time and use it to learn a new language. This year I decided to learn F#. I’ve been working with Lisp before, so the concept of functional oriented langauges is not new to me. The syntax however is.

After a couple of hours with the book Foundations of F# (Robert Pickering) I’ve already written my first program. It is a LUHN10 validator.

Every Swedish citizen has a personal identity number (almost like social security number) that uniquely identifies that person. The format of this number looks like this

y y M M d d x x x z
6 9 0 1 0 1 1 2 3 6

‘y’ is year, ‘M’ is month and ‘d’ is day. ‘x’ is some number and ‘z’ is a control digit. From this number you could tell when I was born (birth date), what region of Sweden I was born and my gender. The last digit is a control number used to validate the rest of the number. The LUHN10 validation works like this.

  6 9 0 1 0 1 1 2 3 6
* 2 1 2 1 2 1 2 1 2 1
---------------------
 12 9 0 1 0 1 2 2 6 6

You calculate the products as I shown above, and then you add every digit each of their own.

1 + 2 + 9 + 0 + 1 + 0 + 1 + 2 + 2 + 6 + 6 = 30

If the result is evenly divisible by 10, then this personal identity number is valid. That is where the LUHN10 name comes from. You can also use this to calculate the last digit of the personal identity number.

  6 9 0 1 0 1 1 2 3 x
* 2 1 2 1 2 1 2 1 2 1
---------------------
1 + 2 + 9 + 0 + 1 + 0 + 1 + 2 + 2 + 6 + x = y
24 + x = y

At this point you set x some a number that will make y evenly divisible with 10, and you have your control digit.

I wrote this validation algorithm in F# as practice. This piece of code probably looks like shit to those of you that are already fluent with F#.

// Product may be 1 or 2, largest possible double is 18
// If result of product is greater than 9 add the parts of
// the product together.
// Example 9 * 2 = 18 => 1 + 8 = 9
// Example 6 * 2 = 12 => 1 + 2 = 3
let calculateProduct x product =
    let double = x * product
    match double with
    | double when (double > 9) -> 1 + (double - 10)
    | double -> double

// 2, 1, 2, 1, 2, 1, 2, 1....
let indexProduct x = ((x + 1) % 2) + 1

// For each and every number in pidList add result of calcAtom
let rec luhnAlgorithm numberList index =
    match numberList with
    | head :: tail -> calculateProduct head (indexProduct index) + luhnAlgorithm tail (index + 1)
    | [] -> 0

// PID is valid if the result from luhnAlgorithm divides evenly with 10
let luhn10 pid = ((luhnAlgorithm pid 0) % 10) = 0

And the usage may look like this

let pid = [6; 9; 0; 1; 0; 1; 1; 2; 3; 6]
if luhn10 pid then
    printfn "Your personal identity number is valid"
else
    printfn "Your personal identity number is invalid"