Below is the first in a series of “Patterns and Origins” documents on Sueetie.Core now available on the Sueetie Wiki.
As a reminder, “Patterns” focuses on the source code while “Origins” describes the code’s Open Source points of origin, or otherwise the thinking that went into the code’s creation.
Tonight’s Patterns and Origins Installment: The SueetieConfiguration Class
__________________
SueetieConfiguration.cs is one of the classes located in Sueetie.Core Business folder. It enables us to share properties and objects throughout a Sueetie Community Site regardless of application.
SueetieConfiguration – Patterns
Put simply, SueetieConfiguration reads an XML file and stores properties specified in SueetieConfiguration for use in various business processes. Here's a screenshot of the Sueetie.Config file.

.
The SueetieConfiguration process came into play when User Avatars were introduced, which also required the creation of a data provider. Thus in Sueetie.Config you'll see properties of the UserAvatar object and Data Provider type.
We can then reference the site's UserAvatar properties anywhere in Sueetie using something like
int height = SueetieConfiguration.Get().AvatarSettings.Height; Notice the
Get() method in the above line. This is a well-established .NET pattern where the Sueetie.Config XML file is read and stored in SueetieCache.
public static SueetieConfiguration Get()
{
SueetieConfiguration config = SueetieCache.Current[configKey]
as SueetieConfiguration;
if (config == null)
{
lock (configLocker)
{
config = SueetieCache.Current[configKey] as SueetieConfiguration;
if (config == null)
{
string configPath =
ConfigurationManager.AppSettings["rootpath"].ToString() +
"Sueetie.config";
XDocument doc = XDocument.Load(configPath);
config = new SueetieConfiguration(doc);
SueetieCache.Current.InsertMax(configKey,
config, new CacheDependency(configPath));
}
}
}
return config;
}
Notice that the location of Sueetie.config file is obtained through an AppSetting property.
ConfigurationManager.AppSettings["rootpath"].ToString() + "Sueetie.config"; Because Sueetie is a collection of web applications we need a way for them to access a configuration file found outside of the application, i.e., above the application’s root directory. So rather than using multiple
sueetie.config files, all applications using SueetieConfig must specify the physical location of sueetie.config. This is done in an app.config file in the application's root directory, referenced from the application's web.config. The app.config Site RootPath setting would look like the following:
<appSettings>
<add key="rootpath" value="D:\Burkeland\Sueetie\source\Sueetie.Web\"/>
</appSettings>
Back to the Patterns of SueetieConfiguration.Get(), you'll notice we're using LINQ-to-XML's XDocument to read in nodes in sueetie.config. This makes things clean and efficient, not to mention easy. Here's an example of reading in the AvatarSettings object.
private void PopulateAvatarSetting()
{
var avatarsettings =
from avatarsetting in configXML.Descendants("AvatarSettings")
select new AvatarSetting
{
Height = (int)avatarsetting.Attribute("Height"),
Width = (int)avatarsetting.Attribute("Width"),
ThumbnailHeight = (int)avatarsetting.Attribute("ThumbnailHeight"),
ThumbnailWidth = (int)avatarsetting.Attribute("ThumbnailWidth"),
Size = (int)avatarsetting.Attribute("Size"),
AvatarFolderPath = (string)avatarsetting.Attribute("AvatarFolderPath"),
ImageQuality = (int)avatarsetting.Attribute("ImageQuality")
};
AvatarSettings = avatarsettings.Single();
}
Now as we’ve shown before, when we want to reference, say, the SiteAvatar Height setting we use
int height = SueetieConfiguration.Get().AvatarSettings.Height;
SueetieConfiguration – Origins
I've been using an ASPNET Configuration model for years in one form or another. With Sueetie I took the opportunity to investigate how the applications that comprise Sueetie handled configuration. The app in Sueetie that uses the most robust Configuration model is Gallery Server Pro. GSP uses Microsoft's ConfigurationManager library for reading and writing to an application .config file, in GSP's case galleryserverpro.config.
After studying the GSP model for a while I realized it wouldn't meet Sueetie framework needs because of the ConfigurationManager's .config file location requirements. The .config file location must be in the application as specified in the configSource attribute of the Section Group web.config. In GSP the web.config statement would be
<galleryServerPro configSource="gs\config\galleryserverpro.config"/>
For site-wide Sueetie use of a single .config file we need something like
<Sueetie configSource="..\..\config\sueetie.config"/>
but that's contrary to System.Configuration ConfigurationManager rules.
We also didn't need a Read-Writeable Sueetie.config model. You pay a lot in overhead for that capability. The Sueetie Framework strives to be as lean and as fast as possible, so when it comes down to choosing between backend amenities or performance, we'll choose performance every time.
So SueetieConfiguration ended up as a simple XML reader using .NET 3.5's LINQ-to-XML XDocument object to create shared properties, data and list objects. Caching was added to eliminate the need to read the physical .config file on each access, and a site-wide approach using app.config AppSettings to share a single .config file among multiple ASPNET applications completes the design.
Sueetie.Core Patterns and Origins Documents: