I'm Keyvan Nayyeri, a 25 years old Ph.D. student at
the Computer Science department of
the University of Texas at San Antonio.
I'm also
a Software Architect and Developer and previously held a B.Sc.
degree in Applied Mathematics.
This is my blog where I publish content about various topics specifically Programming Languages and Compilers, Software
Engineering and Programming.
First let’s make it clear what’s a CSModule? If you’re a .NET developer, you know that what HTTPModule is. CSModule is something similar to this which works for Community Server. By HTTPModule you could work on incoming requests and manipulate the response. Here is as same as there in smaller scale for this special application.
By CSModule you can govern on your response and add something to it or edit it. The best way to know more about CSModule functionalities is to take a look at some written CSModules. Some of them are here and I have some CSModules that you can find them in my files gallery.
But how we can write a CSModule? All you need is a good background in OOP and Community Server APIs. CSModule isn’t more than an implementation of an interface and adding a delegate to a handler. You can do this in a class library project. Anyway you need to have final class in a DLL to use your CSModule.
In CommunityServer.Components namespace, you have an interface which is named ICSModule. You must implement this interface to write a CSModule. To implement this you must implement your own Init() method. This method gets two parameters: An object of type CommunityServer.Components.CSApplication and an object of type System.Xml.XmlNode. Hence you need to import at least two namespaces to your class: System.Xml and CommunityServer.Components.
In your own Init() method, you must add a handler to one of available events in your CSApplication object. Currently CommunityServer supports several events to help you write good CSModules. Some of them are: PreRenderPost, PrePostUpdate, PreSearch, CSException and … I think names are self-explanatory and I don’t talk about them here. Use Intellisense to find full list.
You need to add a new handler to one of these events and this isn’t something more than adding a delegate to this event. For more information go to OOP in .NET! If you don’t have a good background in OOP, you’re not a developer!
Now you write your own method based on which you have added to this handler and develop it based on your needs. To do this you should use Community Server APIs and what is available for you in two passed objects as your parameters. They provide some common properties and methods for you to write a CSModule. Here I give the base structure of a CSModule:
VB:
Imports System.Xml
Imports CommunityServer.Components
Public Class MainModule
Implements CommunityServer.Components.ICSModule
Public Sub Init(ByVal csa As CSApplication, ByVal node As System.Xml.XmlNode) _
Implements ICSModule.Init
AddHandler csa.PreRenderPost, New CSPostEventHandler(AddressOf csa_PreRenderPost)
End Sub
Private Sub csa_PreRenderPost(ByVal Content As IContent, ByVal e As CSPostEventArgs)
' Put your logic here
End Sub
End Class
C#:
using System.Xml;
using CommunityServer.Components;
namespace CSModuleDemo_CSharp
{
/// <summary>
/// This is a sample for CSModule implementation
/// </summary>
public class MainModule : CommunityServer.Components.ICSModule
{
public void Init(CSApplication csa, XmlNode node)
{
csa.PreRenderPost += new CSPostEventHandler(csa_PreRenderPost);
}
private void csa_PreRenderPost(IContent Content, CSPostEventArgs e)
{
// Put your logic here
}// csa_PreRenderPost
}
}
Once you wrote your class and compiled it, you can go to your communityserver.config file and find the <CSModules> node to add this CSModule to your application and test it. To accomplish this task, you should add something similar to what I’ve added below:
<add name = "MyCSModule" type = "CSModuleDemo_CSharp.MainModule, CSModuleDemo_CSharp" />
That’s it! Writing a CSModule can be a good and sweet practice around Community Server code. After talking about some common APIs, I’ll write a sample CSModule and explain it here. But for now, you can take a look at my CSModules in file gallery. They are simple and can help you to find more about the process.
Community Server Daily News
May 12, 2006 1:33 PM
#
The Original .NET Geek
Jun 04, 2006 1:00 PM
#
Simone
Jun 21, 2006 9:47 AM
#
Keyvan Nayyeri
Jun 21, 2006 11:55 PM
#
Simone
Jun 28, 2006 6:45 AM
#
Keyvan Nayyeri
Jun 28, 2006 7:04 AM
#
Simone
Jun 28, 2006 2:30 PM
#
rape videos
Jul 05, 2006 7:14 AM
#
TrackBack
Jul 08, 2006 12:55 AM
#
protected virtual void jaysonBlog {
Aug 01, 2006 5:39 PM
#
Richard
Aug 21, 2006 7:40 PM
#
J-O Eriksson's blog
Oct 30, 2006 11:48 AM
#
Alpha's Blog
Nov 10, 2006 3:44 AM
#
Scott Gettis
Mar 21, 2007 5:43 PM
#
slnavn2000
Sep 09, 2008 9:57 PM
#
Thanks Keyvan for your article!
Leave a Comment