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...