I blogged about my CodeSmith project named CSTiers when it was born. I’ve been using it quite a bit to generate custom Chameleon controls, Provider classes, and business objects. This weekend I added templates to generate custom Configuration, Roles, Context, urls and user, along with a CSModule to create the custom user on CS CreateUser. With the addition of the new templates to the CodeSmith project I am now generating a complete ready-to-use custom Community Server class library project.
You’ll have to do a bit of scrolling here, but not much more reading. Below are the CodeSmith templates that comprise CSTiers. Also in the picture are the template folders containing the CodeSmith templates I use in everyday CS development.
The templates give you a good idea of the objects that are created in an empty Visual Studio project. The generated project is shown below. You might have noticed the SiteUrls_Override.config, a DBVT.config, DBVT.xml resources file and a couple of Dummy.aspx files in the CodeSmith templates. We’ll output those to the Web directories. Dummy.aspx is used to confirm that the project is fully operational. We’ll do that by displaying a Dummy Chameleon control that’s included in our CodeSmith-generated project files. We’ll see that in a bit.
Our project handles the requirements of most custom Community Server projects, where we’ll need a data provider, a custom user object, our own context, configuration and roles support, and the ability to create urls. Nearly all of the classes are derived from existing Community Server objects so we can do things like
DBVTUser user = DBVTContext.Current.DBVTUser;
DBVTConfiguration dbvtConfig = DBVTConfiguration.GetConfig();
image.ImageUrl = Globals.ApplicationPath + “/images/” + dbvtConfig.UploadImageFileName;
It also means that I’ll probably be rewriting a lot of CSTiers when CS2008 hits the streets. 🙂
The process of creating a working project starts with creating an empty class library in the Community Server solution. Then I run a single SQL script to create dbvt_users and dbvt_dummy tables and a couple of stored procedures. The CodeSmith project then creates all of the files in my Visual Studio project, which builds successfully with no additional modification. Two CommunityServer.config updates and a web.config file update in the Community Server Web project and we’re good to go.
Since I try to use CodeSmith as much as possible to do the work for me, I added a CodeSmith template that does the .config coding for me as well, writing it to a .TXT file for cut and pasting. Here’s a sample of that output.
Steps to complete new project setup:
1) Add DBVTDataProvider to communityserver.config <Providers />
name = “DBVTDataProvider”
type = “DBVT.Sample.Components.DBVTSqlDataProvider, DBVT.Sample”
connectionStringName = “SiteSqlServer” databaseOwnerStringName = “SiteSqlServerOwner”
2) Add CreateDBVTUser module to communityserver.config <CSModules />
<add name = “CreateDBVTUser” type = “DBVT.Sample.Components.CreateDBVTUser, DBVT.Sample” />
3) Add DBVT control to web.config Controls area
<add tagPrefix=”DBVT” namespace=”DBVT.Sample.Controls” assembly=”DBVT.Sample” />
The final step is to make sure everything works. First we’ll create a new account to confirm that the CreateDBVTUser CSModule is entering a new record into the dbvt_users table, then we’ll view our dummy.aspx page.