Continuing the journey in Sense/Net, after my first post where I highlighted some hints to speed the process of creating a development environment, I want to spend two words on the following Sense/Net wiki how-to: How to create a ContentHandler.
It explains how to create a content handler for the content types you may have included in your custom business logic.
Btw, "Content Type" is an important bluilding block of Sense/Net platform: it is a collection of reusable settings that define the attributes and behaviours of a specific kind of content. From a conceptual point it is identical to a Sharepoint Content Type, what differs is the implementation.
The how-to above mentioned is clear and easy to follow, but on point 7, after the creation of the content handler, it suggests you to install the relevant content type through the on-line Content Repository. This is not what I want, because you may end with the result of a content handler not aligned with the content type previously defined, it is up to you to keep them synchronized.
Why not install or modify your content type during the building process? After all, this would be the best way to keep in sync both the content handler and the content type.
After a series of attempts I finalized the following procedure:
1. Put your CTD xml file under /Root/System/Schema/ContentTypes/ folder as in the image below:
if you do not have the full tree but just the Root folder, create it from inside Visual Studio.
2. Add a post-build event.
and insert the following commands:
$(TargetDir)Import.exe -SOURCE $(ProjectDir)Root -TARGET /Root -ASM $(TargetDir) -SCHEMA $(ProjectDir)Root\System\Schema
The first line imports in the content database what is contained in the Root folder of your web app. The second line runs indexpopulator.exe to reindex the content repository. Make sure you have import.exe and indexpopulator.exe tool on your bin webfolder.
The architecture of Sense/Net allows you to define a content type as a set of properties and attributes to be assigned to a specific kind of content, in a way that is very similar to what Sharepoint does. This is great because you do not have to rethink integrally to your project from the basis if you want to migrate it to Sense/Net.
In this post I showed how we can leverage a post-build event of Visual Studio to ensure that both the content handler and the content type are installed at the same time so that you can minimize wrong reference errors. This trick may be applied to other cases.