WebVize's WebLog

An independent C# Developer in the Netherlands

October 2004 - Posts

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..



 



 

Finally .. Back working on a new content management system

Right now I finally am able to do some work on the new Content Management System for the Kids Community Kaboem. Kaboem was sold to Ilse last month so the pressure is on..

As I have said this is totally my idea of how Content Management should work. Being able to be flexible in all different parts and all aspects of what the site should be.

What is in my opinion the problem with current systems?
All current systems can do a hell of a job managing content in all its facets  but in my definition a site is a ordered collection of content and functionalities to interact with the user.
Here is where it goes wrong for many systems, at least you have to do some hard work to integrate your idea's within a 'boxed' product, the interactivity with the user.

How to maintain the option to integrate interact with the user?
Keep on using the power of ASP.NET.

So finally I am building a system that will hold the definition of the site eg. the definition of the content, the definition of a module and the definition of a page.
Combine these together in a build system, keep the option to have asp.net script tags within definitions and I keep the power of ASP.Net and pre-merge content in the modules so that performance is not depending on the speed of the SQL server.

Included is a link to a screen shot of the first partial working system.. Yes I do use a lot of win form user controls in ASP.NET. Why ? I like the presentation and the speed of the local objects.

Link to screen shot.
(if for whatever reason you would like to see more screen shots .. Leave me a comment and I will place some more!)

More Explained on my CMS view

As stated before a website is nothing more than a structured collection of content and interaction functions.

A page is nothing more than a collection of visible items ( I call them Modules) all pushed in a template so that the design of the site stays the same throughout the site itself
The Module is based on a design and has 'readable' content to it assigned.
The content of a module can be described by its elements. Like title,header,content and so on..

Ok. Enough talk I'll show some screens..


The definition of content can be desribed here


I want th generate the definitions to a DLL so I have at least one template I can use to generate the dataobject. The data of the objects will be stored in the database as serialized objects. Important elements of the objects will be stored as value in the table to be able to find the required data fast..


Running and compiling this template generates me a DLL i can resuse in either template or in additial written components.


Setting the design of the module.. You notice I bind it to a dataobject and make it easy for the user to create the datafields in the design..


We can even write script code so that we can run funtions in runtime on the site..


Then the page has a design. You see I have an element ~Content~ this will be a placeholder where modules are placed. See the next one


AS defined I had a element called ~Content~ .. Now this is extracted as a placeholder.


Dataobjects is one but ofcourse we need to fill the object with data..this is a CMS that is reflected from the object itself. Notice that the Is Active check wasn't defined. But in the generation template it is included as a required field.


We also can manage the data from the site structure ..later on we will create an option to have a preview on each seperate object.

Finally we need to deploy and generete the site.. I will place all content pre rendered in the Modules an place them as  a ASCX on the webserver. The Page will then include the ascx files and optiol code defined in the modules will be executed.

As you might notice I make use of winform user controls :-)

If you have any comments, ideas or anything to say please let me now.

More Posts