Community Server on my mind

J-O Eriksson's blog


  • Running on CS 2.1 SP 2

    See top menu for subscription options

    Technology Blogs - Blog Top Sites

    BlogRankers.com

    Add to Technorati Favorites



Building a simple CSModule that uses CS Text Parts (The SoapBox Sample)

Last Friday I posted about a new CSModule that I had just created for showing MSN SoapBox videos in Community Server. Inspired by Gary McPherson's YouTube CSModule which is included in the Alabaster CSModule Package, and by looking through the source code of Ken Robertson's Qgyen.Lightbox CSModule.

I also said in last Fridays post that I would go through the code I used to create it, so it might be used as an sample on how to create a really simple CSModule that works with the Text Parts architecture of Community Server. As you will see in the code presented in this article, it was very easy to accomplish this functionality in a CSModule thanks to the great CS API.

I am using screenshots of the code instead of pasting it in here, because my code highlighter plugin in Live Witer stopped working after upgrading Live Writer.


Click on the image to view it in original size

In this code section I use the node object given to me by the Init Method of the CSModule. I use it to check if there are an attribute called SyndicationMessage in the CSModule tag in communityserver.config. For example, it could look like:

<add name="SoapBox" type="CSSoapBox.CSMVPs.CSModules.JOEriksson.CSSoapBox,CSSoapBox"
SyndicationMessage="[On the site you would see an embedded video player here]" />

I didn't want to SoapBox Text Part to show as just text when viewed in a RSS reader. As you can see, if you don't put a SyndicationMessage attribute into the communityserver.config entry for the CSModule, it will use a standard message of "[Go to the site to view embedded SoapBox video]".


Click on the image to view it in original size

Here's the beginning of the method that runs on the PreRenderPost event. First I check if the post that are going to be rendered is from a forum or a blog. So for example if it were a post in a File Gallery it wouldn't continue to look for SoapBox Text Parts within it. Just Forums and Weblogs.

Then I loop through all or any Text Parts within the post, and checks if there's any SoapBox Text Parts. I didn't know before that it was so easy to do this in the CS API, and that it had a collection to the CSPostEventArgs.


Click on the image to view it in original size

I continue with getting the first parameter of the Text Part, and put it in a variable. The I build the HTML chunk to embed the SoapBox video player with the specified VideoID.

Lastly I replace the SoapBox Text Part with either my HTML for embedding the videoplayer, or with the SyndicationMessage, depending on where the post is shown. Notice the Replace method of the Text Part. I didn't know about that either before. I sat down trying to figure out how to do a RegEx replace, and I am really not very good with RegEx. I learned about the Text Parts replace method by looking in Ken Robertson's Qgyen.Lightbox source code.

I will add the source project to the downloadable ZIP file of SoapBox CSModule as soon as I can, but also there's really nothing more to it than the code presented in this article.

If you enjoyed this post Subscribe to my feed via RSS or e-mail!
Posted: Monday, October 02, 2006 9:00 AM by J-O Eriksson

Comments

Community Server Daily News said:

news of the day a grab bag for what's happening in Community Server J-O Eriksson walks us through his

# October 2, 2006 2:08 PM

devmain said:

Hi, How can I customize my VS2005 to look like yours?
# October 2, 2006 8:32 PM

J-O Eriksson said:

# October 3, 2006 7:42 AM

J-O Eriksson's blog said:

Whether you are a developer, or a Community Server admin that haven't got much experience of .NET Development,

# October 30, 2006 11:48 AM

Community Server Bits said:

J-O Eriksson walks us through his new TextPart-based SoapBox CSModule, demonstrating how to check if

# March 12, 2007 5:55 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS