Dave Burke : Freelance .NET Web Developer specializing in Online Communities

CS Nuglet: Extending the CSContext Object

The CSContext object in Community Server is more popular than Renee Mattioli in my sixth grade class, and she was the tops.  If you scan through Community Server source code you'll find the CSContext object all over the place.  Keyvan Nayyeri wrote a great CS Dev Guide on it back in May and demonstrated clearly how to retrieve useful data out of it.  The purpose of this CS Nuglet is to demonstrate how to put stuff into it that you can use in your Community Server mods and add-ons.  You'll discover that extending the CSContext object is way easy, so this CS Nuglet should technically be called a Nugletti.  Still cool though.

The Queen Mother CSContext object is located in CS.Components.CSContext.  We're going to add a property that does something based on the current CS Application.  In the CSContext class you'll find a "Private Members" region.  All we're doing is creating a property, albeit one with a little bit of smarts, so we add the private property, "dbvtString."


#region Private Members

int sectionID = -2;
int categoryID = -2;
...
string dbvtString = null;

#endregion


Now for the Public Member DBVTString.


public string DBVTString
{
get {
if (this.ApplicationType == ApplicationType.Weblog)
   dbvtString = "We be in blogs!"
else if (this.ApplicationType == ApplicationType.Gallery)
   dbvtString = "We be in galleries!"
else
   dbvtString = "We don't know WHERE we be!"
return dbvtString;
}
set { dbvtString = value; }
}

 

To test my extended CSContext object I picked two random locations in the blogs and photo galleries to see if my DBVTString was available.  Here are undoctored screen snips.

 


If Renee Mattioli could see me now...

Comments (5) | Post RSS RSS comment feed

Posted on 9/28/2006 8:02:26 PM by Dave Burke
Categories: Community Server
Tags:

Related posts

Comments (5) -

9/28/2006 11:00:18 PM Permalink

Nice one.
I have 2 questions about your example:
1. You are modifying core code instead of deriving from it in your own custom object.  You'd have to reapply your mods in the next release?
2. ApplicationType is an enum with a fixed set of values.  If I wanted to add a custom app I'd have to modify more core code?

Vince |

9/29/2006 12:28:28 AM Permalink

ROFL (Really!!!) about the Renee Mattioli comments... Excellent! Keep it up!

Dennis van der Stelt |

9/29/2006 5:35:51 AM Permalink

Dennis, there really was a Renee Mattioli.  Yet another girl who never let me get close to her.  Glad you enjoyed my pain. Smile

Vince, you're exactly right.  I'm a huge advocate for never touching the source code.  Yet I've found that in some instances it simply makes since to add a few lines rather than derive from a class, duplicate any non-virtual methods, etc.  I wrap any such changes with "// DBVT Modified" along with a DBVT.txt in the project root for upgrades.  It also depends on the implementation, too, and how extensively the CSContext is used throughout CS.  That could be a lot of changes pointing to a derived CSContext object.  

And yes, that would apply to ApplicationType, too, which is a different animal, especially if several add-on developers decide to add a new ApplicationType enum and there's a conflict.  That was actually one of the things discussed at last week's Summit.  Pretty interesting.

daveburke |

9/29/2006 12:23:53 PM Permalink

Now if I only knew what y'all talking about I would be golden! Smile

Did I say y'all.....

The Wizard |

9/29/2006 12:56:01 PM Permalink

You must've really liked Dallas, Wiz!

daveburke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke