CS中的配置管理(Configuration)
CommunityServer中的配置信息存在在Web/communityserver.config中。
其中,系统配置信心XML结构如下:
<?xml version="1.0" encoding="utf-8" ?>
<CommunityServer>
<Core
defaultLanguage="en-US"
disableEmail="false"
disableIndexing="false"
disableThreading="false"
cacheFactor="5"
systemType = "Self"
textEditorType = "Telligent.FreeTextBoxWraper.FTB, Telligent.FreeTextBoxWraper"
....
announcementRssUrl="http://communityserver.org/blogs/announcements/rss.aspx"
>
<providers>
<clear/>
<add
name = "CommonDataProvider"
type = "CommunityServer.Data.SqlCommonDataProvider, CommunityServer.SqlDataProvider"
connectionStringName = "SiteSqlServer" databaseOwnerStringName = "SiteSqlServerOwner"
/>
</providers>
<appLocation>
<add pattern = "/blogs" name="BlogPublic" type = "weblog" />
</appLocation>
<extensionModules>
<add name="PassportAuthentication"
extensionType="Security"
type="Telligent.CommunityServer.Security.PassportAuthentication, Telligent.CommunityServer.SecurityModules"
/> 
</extensionModules>
</Core>
....
</CommunityServer>
在Component/Configuration目录下有一个CSConfiguration类,主要负责将XML的解析成对象实体。例如,当我们编写下面代码获得系统配置实体:
CSConfiguration config = CSConfiguration.GetConfig();
在CSConfiguration类中,该方法代码如下:
public static CSConfiguration GetConfig()
{
CSConfiguration config = CSCache.Get(CacheKey) as CSConfiguration;
if(config == null)
{
string path = null;
HttpContext context = HttpContext.Current;
if(context != null)
path = context.Server.MapPath("~/communityserver.config");
else
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "communityserver.config");

XmlDocument doc = new XmlDocument();
doc.Load(path);
config = new CSConfiguration(doc);
CSCache.Max(CacheKey,config,new CacheDependency(path));

CSCache.ReSetFactor(config.CacheFactor);
}
return config;
}
首先,从Cache中读取对象,注意,该Cache对象与Config文件有依赖关系。接着,调用new CSConfiguration(doc)将配置文件中的Core节点内容读入config对象中。
其中,系统配置信心XML结构如下:
<?xml version="1.0" encoding="utf-8" ?>
<CommunityServer>
<Core
defaultLanguage="en-US"
disableEmail="false"
disableIndexing="false"
disableThreading="false"
cacheFactor="5"
systemType = "Self"
textEditorType = "Telligent.FreeTextBoxWraper.FTB, Telligent.FreeTextBoxWraper"
....
announcementRssUrl="http://communityserver.org/blogs/announcements/rss.aspx"
>
<providers>
<clear/>
<add
name = "CommonDataProvider"
type = "CommunityServer.Data.SqlCommonDataProvider, CommunityServer.SqlDataProvider"
connectionStringName = "SiteSqlServer" databaseOwnerStringName = "SiteSqlServerOwner"
/>
</providers>
<appLocation>
<add pattern = "/blogs" name="BlogPublic" type = "weblog" />
</appLocation>
<extensionModules>
<add name="PassportAuthentication"
extensionType="Security"
type="Telligent.CommunityServer.Security.PassportAuthentication, Telligent.CommunityServer.SecurityModules"
/> 
</extensionModules>
</Core>
....
</CommunityServer>
CSConfiguration config = CSConfiguration.GetConfig();在CSConfiguration类中,该方法代码如下:
public static CSConfiguration GetConfig()
{
CSConfiguration config = CSCache.Get(CacheKey) as CSConfiguration;
if(config == null)
{
string path = null;
HttpContext context = HttpContext.Current;
if(context != null)
path = context.Server.MapPath("~/communityserver.config");
else
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "communityserver.config");
XmlDocument doc = new XmlDocument();
doc.Load(path);
config = new CSConfiguration(doc);
CSCache.Max(CacheKey,config,new CacheDependency(path));
CSCache.ReSetFactor(config.CacheFactor);
}
return config;
}

浙公网安备 33010602011771号