To write CSModules you must implement an interface called ICSModule.The ICSModule is defined in the CommunityServer.Components.dll. You must add a reference to this .dll before you can write any CSModules.
You should also add references to any application-specific .dlls you will need.
public interface ICSModule
{
void Init(CSApplication csa, XmlNode node);
}
The interface has just one method to implement, Init with two parameters:
After you create and compile your, use the following steps to deploy it:
<add name="Your_Module_Name" type = "Namespace.ClassName, Assembly" />
Community Server does not throw a public exception if a module fails to load. You will need to check your Community Server Event log to see if there are any problems. As long as the log does not mention your module by name or type, you are in the clear.
A couple of other points:
Here is a sample CSModule:
using System.Xml;
using CommunityServer.Components;
namespace Telligent.Samples
{
/// <summary>
/// Sample CSModule which can be used to invoke an action after a new user registers an account
/// </summary>
public class UserCreateModule : ICSModule
{
public UserCreateModule()
{
}
public void Init(CSApplication csa, XmlNode node)
{
//wire up an event which is fired after the user change has been committed to the database
csa.PostUserUpdate += new CSUserEventHandler(csa_PostUserUpdate);
}
private void csa_PostUserUpdate(User user, CSEventArgs e)
{
//we only care about new users, so let's filter for it
if (e.State == ObjectState.Create)
{
//now we can do something such as assign roles, send email, etc.
//Send Email, etc.
//NOTE: If you want to make a change to a user value (or profile) you need an editable user object
User editableUser = Users.GetUserWithWriteableProfile(user.UserID,null,true);
//Do Something
Users.UpdateUser(editableUser);
*/
}
}
}
}
In the above code you complete the following tasks:
To finish off this module, you only need to add the following line to the CSModules section in the CommunityServer.config file:
<add name = "UserSample" type = "Telligent.Samples.UserCreateModule, Telligent.Samples" />
Note: This assumes the assembly name is Telligent.Samples.dll.