Anda di halaman 1dari 8

Diatom Enterprises

N2 CMS framework review


Key features

Alexander Shakhov 3/9/2010

Introduction
This document describes N2 CMS framework key features and some technical of its integration with existing systems. Auditory for this document is Web software developers familiar with Microsoft .NET technologies.

Key features
SEO friendly URLs
N2 CMS supports SEO friendly URLs by default. Data is structured as tree in N2 CMS and URL is path for this tree. Data tree is not related to aspx pages or code structure and easy customizable. This allows changing URLs using web interface.

Flexible data model


N2 CMS tree is consists of data items. Each data item represents class in C# which is derived from N2.ContentItem subclass. You can use inheritance and composition to create your data model. On the diagram bellow you can see example of structure to store articles in CMS.

Reach set of ready-to-use editors for data model


Data tree in N2 CMS consist of different type of objects defined in code. To edit object properties N2 CMS provides wide range of editors. Some of the editors: HTML editor (tinyMCE), text editor, number editors, date editor, image uploader, file uploader and others. Due this creating editor for data item is just decorating Class properties with attributes. It is possible to create your own editors using custom attribute and reference to ascx control.

Example of data item decorated with editing attributes.

N2 will convert this data item to flowing editor:

Using ASP.NET templates


To generate HTML representation of the data item you can use aspx pages or ascx user controls. You should derive your aspx page from N2.ContentPage<T> where T is class of your data item.

On the screenshot above you can see templates for Article data item described in previous chapter. When user navigates to some URL associated to with data item than template will be rendered with data item injected. Part of Article data item template:

Above CurrentPage is injected Article and is strongly typed.

Above you can see contents of CMSMetaControl. CurrentPage in CMSMetaControl is typed as CMSPageBase and is injected from page where control has been placed.

Using ASP.NET MVC


N2 supports ASP.NET MVC out of the box. Approach is similar to ASP.NET templates. When user requests URL or data item controller action is triggered and controller is responsible for preparing data for view. In most cases prepared data is data item itself but you can provide additional logic in controller. On the screenshot bellow you can see two controllers derived from ContentController<T> class. Each controller servers request for specified data objects type. URL pattern is <data object URL><action>.

Inside controller action you can access current data item by using Controller.CurrentItem. You can pass data item to the view or create ViewModel from it.

Using together with existing functionality


N2 CMS can be used with existing ASP.NET or ASP.NET solutions. By means of http handler N2 engine checks if requested URL is data item URL; if data item is found than N2 logic will be triggered otherwise request will proceed to default ASP.NET logic. The same approach is used in MVC applications by means of ContentRoute object; if ContentRoute finds that route matches N2 data item than it injects it into controller and triggers controller action, otherwise fallback to default Route logic occurs. Using this you can easily combine functionality based on N2 and standard ASP.NET/MVC.

Integration
Integration to solution consists of the following steps. 1) 2) 3) 4) Add reference to the binaries. Add folder Edit contains N2 edit interface. Configure N2 in web.config of your application. After this you just start application and follow 5 step wizards which helps you to create necessary database tables and some root elements of your data item tree.

DAL
N2 uses NHibernate ORM to access data and can be configured to work all major databases supported by NHibernate MSSQL 2008/2005/2000, MySQL, SQLLite and others. In database 4 tables are created with the flowing schema:

All NHibernate settings and mappings are encapsulated into N2 logic so you can escape dealing with them. To access data from you code N2 provides API. You can use N2.Find static class to find item by URL or its part. Also ContentItem
public virtual IEnumerable<NewsPage> GetNews() { return GetChildren(new AccessFilter(), new TypeFilter(typeof (NewsPage))).Cast<NewsPage>(); }

Example above retrieves News children data items from NewsContainer. You can use any technology to access your own tables together with N2. N2 uses separate connection string this allows to place N2 tables to separate database or event separate database server.

Anda mungkin juga menyukai