Update of /cvsroot/magicajax/magicajax/Core/Configuration
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6302/Core/Configuration
Added Files:
MagicAjaxConfiguration.cs MagicAjaxSectionHandler.cs
Log Message:
Put source files to module 'magicajax' divided in directories Core, Examples, and CustomControls.
--- NEW FILE: MagicAjaxConfiguration.cs ---
using System;
using System.Xml;
using System.Configuration;
using System.Collections.Specialized;
namespace MagicAjax.Configuration
{
public enum PageStoreMode
{
NoStore,
Session,
Cache
}
public struct PageStore
{
private PageStoreMode _mode;
private int _cacheTimeout;
private int _maxConcurrentPages;
private bool _maxPagesLimitAlert;
public PageStoreMode Mode
{
get { return _mode; }
}
public int CacheTimeout
{
get { return _cacheTimeout; }
}
public int MaxConcurrentPages
{
get { return _maxConcurrentPages; }
}
public bool MaxPagesLimitAlert
{
get { return _maxPagesLimitAlert; }
}
public PageStore(PageStoreMode mode, int cacheTimeout, int maxConcurrentPages, bool maxPagesLimitAlert)
{
_mode = mode;
_cacheTimeout = cacheTimeout;
_maxConcurrentPages = maxConcurrentPages;
_maxPagesLimitAlert = maxPagesLimitAlert;
}
}
/// <summary>
/// Summary description for MagicAjaxConfiguration.
/// </summary>
public class MagicAjaxConfiguration
{
private string _scriptPath;
private PageStore _pageStore;
public string ScriptPath
{
get { return _scriptPath; }
}
public PageStore PageStore
{
get { return _pageStore; }
}
public MagicAjaxConfiguration(XmlNode xml)
{
// Default values
_scriptPath = null; // Null implicates that the embedded javascripts will be used (default)
PageStoreMode mode = PageStoreMode.NoStore;
int cacheTimeout = 5;
int maxPages = 5;
bool maxPagesLimitAlert = false;
if (xml != null)
{
XmlAttribute attrib = (XmlAttribute)xml.Attributes.GetNamedItem("callBackScriptPath");
if (attrib != null)
{
// Resolve relative scriptPath url's (starting with "~")
_scriptPath = CallBackHelper.ResolveUrl(attrib.Value);
}
XmlNode pageStore = xml["pageStore"];
attrib = (XmlAttribute)pageStore.Attributes.GetNamedItem("mode");
if (attrib != null)
{
switch (attrib.Value.ToLower())
{
case "nostore":
mode = PageStoreMode.NoStore;
break;
case "session":
mode = PageStoreMode.Session;
break;
case "cache":
mode = PageStoreMode.Cache;
break;
default:
throw new ConfigurationException("MagicAjax configuration: mode for pageStore must be \"NoStore\" or \"Session\" or \"Cache\".");
}
}
attrib = (XmlAttribute)pageStore.Attributes.GetNamedItem("cacheTimeout");
if (attrib != null)
{
try
{
cacheTimeout = Int32.Parse(attrib.Value);
}
catch
{
throw new ConfigurationException("MagicAjax configuration: cacheTimeout for pageStore must be integer.");
}
if (cacheTimeout < 1)
throw new ConfigurationException("MagicAjax configuration: cacheTimeout for pageStore must be 1 or greater.");
}
attrib = (XmlAttribute)pageStore.Attributes.GetNamedItem("maxConcurrentPages");
if (attrib != null)
{
try
{
maxPages = Int32.Parse(attrib.Value);
}
catch
{
throw new ConfigurationException("MagicAjax configuration: maxConcurrentPages for pageStore must be integer.");
}
if (maxPages < 1)
throw new ConfigurationException("MagicAjax configuration: maxConcurrentPages for pageStore must be 1 or greater.");
}
attrib = (XmlAttribute)pageStore.Attributes.GetNamedItem("maxPagesLimitAlert");
if (attrib != null)
{
try
{
maxPagesLimitAlert = bool.Parse(attrib.Value);
}
catch
{
throw new ConfigurationException("MagicAjax configuration: maxPagesLimitAlert for pageStore must be boolean.");
}
}
}
_pageStore = new PageStore(mode, cacheTimeout, maxPages, maxPagesLimitAlert);
}
}
}
--- NEW FILE: MagicAjaxSectionHandler.cs ---
using System;
using System.Xml;
using System.Configuration;
namespace MagicAjax.Configuration
{
/// <summary>
/// Summary description for MagicAjaxSectionHandler.
/// </summary>
public class MagicAjaxSectionHandler : IConfigurationSectionHandler
{
#region IConfigurationSectionHandler Members
public object Create(object parent, object configContext, XmlNode section)
{
return new MagicAjaxConfiguration(section);
}
#endregion
}
}
|