WebVize's WebLog

An independent C# Developer in the Netherlands

Building a CMS system Nr. 1

I intend to keep a record of my adventures in building a Content Management.
Yes, English is not my native tongue so it will have a lot of typo's and grammatical errors :-)
This is also helping me as being a soundboard to myself and hopefully other developers will kick in with ideas.

Building a CMS
Building a CMS seems to be a most common task in the internet development branch.
In 99 out of 100 times we tend to keep strictly to the requirements for the particular site.

Right now I am on nr 100 so I am trying to build a system that will be able to used on all the new sites I will need to build.

What is Content Management
In my opinion CMS is a complete management over the site. Not just the content but also the way things will be presented. The flow of the various pages and what to show on what page under what context of the user. Just imagine to build a Content Management System without any definition of what the site will be or what it will hold.

I will start  of with Content.
What is Content? I see content as visible data that is inputted by a user. This can be various things, ranging from traditional text to flash animations.
As we don't know what the site will be holding we need to be able to justify the content description without needing to recompile the complete source. Also we need to be able to store the data in a database. That is a tricky one if we know nothing about what the site will be.
Think of all the subjects a site can have. FAQ, Articles, Messages, etc, etc..

Definitions
This is where definitions kicks in. If we look at a content item we can clearly see it as an object having various properties. What if we can create an object that can have these properties and store this all in the database. I have seen solutions where a table with a lot of columns (off all types) was used and that the properties where mapped to these columns. This is not my idea to do it.
What if we can create the object and serialize it into the database. That would be a nice option. The problem is just that we need a binary object to do reflection. Sure there are other ways to do this. For example write your own XML schema to create an XML schema. But I settle for the binary version of objects and let the .Net framework handle the serialization and deserialization. I use the Soap formatter for serialization. This will put 'readable' content in the database and this will become handy when we nee to full-text index it to be searchable.

Code I do this serialization:

public string Serialize(object o)
{
string results;
// //Serialize the object
Stream stream=new MemoryStream();
SoapFormatter formatter=new SoapFormatter();
formatter.Serialize(stream,o);
//return the string
StreamReader sr =new StreamReader(stream);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
results=sr.ReadToEnd();
sr.Close();
return results;
}

public object Deserialize(string soap)
{
object o;
try
{
Stream stream=
new
MemoryStream(Encoding.UTF8.GetBytes(soap));
SoapFormatter formatter=new SoapFormatter();
o=formatter.Deserialize(stream);
stream.Close();
}
catch(Exception exc){
Console.Write(exc.Message);
o=new object();
}
return o;
}

But we need to have binary object for this..

How to get from definition to a binary Object.
What if we could generate a template and use the definition of the object to generate a dll from it.
Here is where I use the CodeSmith template compiler. So we have the same language as we all know so well. Sure you need to have the client buy a license for CodeSmith. (
http://www.ericjsmith.net/codesmith/)

In the definition you surely need to think about the common properties of a content object. Some of these properties are needed to be able to find the right data. These properties are defined in the template.

When you generated the template and have the object definition you then can let the CodeSmith compiler create a output file with compileable code. With the CSharpCodeProvider you can compile the file to a binary object.

To be able to serialize the object to the database I have set the [Serializable] attribute and inherited Iserializable to handle the mapping from the fields and handle any errors that will occur when you change the object definition.

Step 1 of many steps has been set to. You know can define objects and generate the objects to a binary object.
In the next phase I will fill the object by using reflection. (we have a binary object so we can use reflection!)

For any comment please drop a line..



 



 

Comments

Paschal said:

Good luck in your CMS adventure :-) You should have a look at the project dScribe on my blog.
Free CMS tool, and still developed by myself.
And of course really used for many projects.
Maybe we can share some ideas ? At the moment It's not working with XML but I am working on that for a version 2.
# October 9, 2004 12:46 PM

Michael HensenMichael Hensen said:

I have seen dscribe.. The problem I had is that it is vb and I wanted c# but I look at several systems and dscribe is 1 of them :-)

I love the way serialization helps me out in development.
I tend to build it in a quick and dirty way and will do a rewrite when I have a bit more time.. The timeschedule is tight.. delivery in about 4 weeks from now !!

But i love to discus with you in how you solved things or want to in V2. Ofcourse in comparison with how I saw and implemented it.

I am much further with the system then it looks. Right now I am processing the merging of data and presentation templates. That is the final stage of this part of CMS.
# October 9, 2004 7:02 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)