Drive Digs Deeper into the CS Framework

This is one of those monkey-on-my-back posts that I need to write before we can get back to regularly scheduled programming.  I’ve been using the Drive code generation templates more and more.  I’ve been adding new templates to the library as well, releasing v1.0.3 over the weekend.

The new release includes a new template that creates a Community Server Module.  CSModules are functions that are triggered by Community Server global events, like when a new user is created or post updated.  As the title suggests, the new “Create CS Module.cst” template is blog-worthy because it digs deeper into the Community Server Framework.

I’m not necessarily pushing Drive or Community Server here.  The most interesting aspect of the new template is that it reflects a bit of artificial intelligence in how it generates code.  This may be an overstatement, but we’re not just spitting out the structures of C# classes with filled-in namespaces and empty methods.  The CS Module template demonstrates taking an action based on another action, requiring knowledge of both.

The template takes properties of the CS event type and category (User, Post, etc.) then generates the methods and method-specific parameters for the complete module.  Here’s the template form.

There’s a lot of “artificially intelligent” code rendering in Drive, but perhaps it was the simplicity of this particular template that made me appreciate the AI aspect of code generation.  The bottom line is that code generation, and CodeSmith in particular, is real smart.

Below is the generated code. 

using System;
using System.Collections;
using System.XML;
using CommunityServer.Components;
using DRIVE;

namespace DRIVE.Components

    public class UpdatePostStatistics : ICSModule
        public UpdatePostStatistics() {}

        public void Init(CSApplication csa, XmlNode node)
            csa.PostPostUpdate += new CSPostEventHandler(csa_PostPostUpdate);

        private void csa_PostPostUpdate(IContent content, CSPostEventArgs e)
            // Sample coding here follows
            //if (user != null && e.State == ObjectState.Create)

Statement for CommunityServer_Override.config

<!–Override xpath = “/CommunityServer/CSModules” mode = “add”>
    <add name = “UpdatePostStatistics”
                 type = “DRIVE.Components.UpdatePostStatistics, DRIVE” />

Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.