CSharpFeeds - All your C# feeds in one place.

Sponsors

Friday, September 08, 2006

CS Dev Guide: Configuration

by Keyvan Nayyeri via Keyvan Nayyeri on 9/8/2006 4:42:34 PM

Configuration is the key part of any application to make it works for user needs.  Community Server uses communityserver.config file as the main configuration file.  There are some options that can be configured via Control Panel as well.

Any developer who needs to get information about Community Server configuration as can accomplish this very easy via APIs.

All the configurations in communityserver.config file are accessible via a set of ReadOnly properties in CommunityServer.Configuration.CSConfiguration object.

Before using these properties you need to set this object to appropriate value.  To do this, you can call CSConfiguration.GetConfig() method.  This method returns an instance of CSConfiguration object for current site.

private CSConfiguration GetCurrentSiteConfig()

{

    CSConfiguration configuration =

        CSConfiguration.GetConfig();

    return configuration;

}

After getting this object you can have access to those properties.  For instance you can get the CacheFactor of your site to write your customized codes based on whole site cache factor to keep consistency or get the WWWStatus enumeration value to decide on how to handle requests to homepage (redirect them to domain.com/Default.aspx or keep them as are).

private void CheckSomeConfigurations()

{

    CSConfiguration configuration =

        CSConfiguration.GetConfig();

 

    // Get Cache Factor

    int cacheFactor = configuration.CacheFactor;

 

    // Get WWWStatus

    WWWStatus wwwStatus = configuration.WWWStatus;          

}

Another concept that should be described here is AppLocationAppLocation is an object that represents the current location for each user in a site.  While your viewing a Community Server site, you're navigating between several applications such as Weblog, Forum, Gallery and some other known applications.  AppLocation is a mean to help developers deal with these information for user requests.

For instance you can check through known application enumerations to see which application your current request is viewing.

Or also you can check to see if current request is viewing a known application or not.  For example if you try to extend Community Server for your needs, probably we'll create an unknown application.

private void CheckAppLocation()

{

    CSConfiguration configuration =

        CSConfiguration.GetConfig();

 

    if (configuration.AppLocation.CurrentApplicationType

        == ApplicationType.Weblog)

    {

        // Below code is just an example

        string BlogAppKey;

        BlogAppKey = CSContext.Current.ApplicationKey;

    }

 

    if (!configuration.AppLocation.IsKnownApplication)

        throw new CSException

            (CSExceptionType.UnknownError,

            "Application is unknown");

}

Another important part of CSConfiguration object is GetConfigSection() method.  This is a great tool for you to add your own configuration nodes to communityserver.config file then retrieve them via your code.  Also you can get access to Community Server default configuration nodes via it.  This method simply gets an XPath expression and returns its appropriate XmlNode.  Using this XmlNode object you can retrieve whatever you want from configuration file.

private string GetAnnouncementRSSUrl()

{

    XmlNode node = CSConfiguration.GetConfig()

        .GetConfigSection("/CommunityServer/Core");

    if (XmlNode != null)

    {

        return node.Attributes

            ["announcementRssUrl"].InnerText;

    }

    return null;

}

Note that Community Server configurations are more than this but some of them were important enough to be covered in other APIs.  For instance for CSModules or CSJobs there are independent providers which help you to deal with their configurations.  These were remained common things that had to be mentioned.

email it!bookmark it!digg it!

Original Post: CS Dev Guide: Configuration

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us