J-O Eriksson

Community Server on my mind

News

Subscribe via FeedBurner

Subscribe via email

<script type="text/javascript"><!-- google_ad_client = "pub-6305396639794057"; google_ad_width = 120; google_ad_height = 240; google_ad_format = "120x240_as"; google_ad_type = "text_image"; google_ad_channel ="5472463295"; google_color_border = "FFFFFF"; google_color_link = "0000FF"; google_color_bg = "FFFFFF"; google_color_text = "000000"; google_color_url = "008000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

Subscribe in NewsGator Online

Subscribe in Bloglines

Add to Google

<script type="text/javascript" src="http://embed.technorati.com/embed/tb2ijzxn26.js"></script>

Blogs I read

Links

CS2: My first CSModule: Enabling notifications for new users

Last weekend I said that I would probably not be able to keep up with posting each day, well I lied. :-) Last week I managed to do that again, but I know I won't be able to keep it up for ever. But as long as I am inspired I'll keep on going. Being mentioned each day in CS.org's daily news is one big inspiration, also to see from the statistics that there are a few people reading this blog.

A couple of year's ago I worked as a developer, mostly VB 6, ASP and COM+ applications, but also was on the early .NET train. This was also kind of a hobby for me. Unfortunealty I moved on to another job, where there was no developing at all. So for the last couple of years, there has been very little developing on my part. Just some short periods where I've done some small unfinnished projects on my spare time. And there hasn't been that much inspiration to do any development.

But when I started to read Keyvan Nayyeri's blog and his CS Dev Guide some of my inpiration came back. And the other day, I decided to try to do something from his example of how to write a CSModule. But what should I do with it?

One shortcoming of Community Server in my opinion is that you can't set defaults for some of the user settings for people that register on the site. One specific setting that I have been asking about a couple of times in the forums, is the ability to enable notifications for a new user. It's off by default in CS, and I haven't found anyway to set it to true. I want that to be on by default for my sites, since many users don't find their way in there and enable it. What I didn't want to do is to change the CS source code and recompile. If I did that, I might have to do the same for each new version of CS. In my opinion, it's best to keep off the original source code as long as you can, for your site to be as supportable as possible. So in this case, CSModules are perfect.

So, looking at Keyvan's example I ended up with the following code for enabling notifications for new users:


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.PostUserUpdate, New CSUserEventHandler(AddressOf csa_PostUserUpdate)

End Sub

Private Sub csa_PostUserUpdate(ByVal user As User, ByVal e As CSEventArgs)

If e.State = ObjectState.Create Then
   
user.EnableThreadTracking = True
End If

End Sub

End Class


Isn't it beautifully (is that an english word?) simple? :-) Just subscribe to the PostUserUpdate event, check if this is a new user that is created, and set the property.

I had some problems before I got it to work, since I did it with Visual Studio 2005, and had the target web running on ASP .NET 1.1, which I didn't realize at first. Just wandered why it didn't work. :-) I then downloaded the "MSBee" so I could compile it to ASP .NET 1.1, but that was a whole different story on it's own.

 

Comments

No Comments