cs config(cs配置文件的获取方式_csr-active-config)

发布时间:2025-12-10 19:25:27 浏览次数:5

cs配置文件的获取方式_csr-active-config-cs config在哪

cs配置文件的获取方式_csr-active-config类多了,看都看晕了.本着职责明确的思想,在n个类的配合下,我们终于得到了我们想要的结果.有时候还真是烦我本意是不想看配置文件如何读取的,但我就不知不觉的遇到这个问题了,只有耐着性子看了.在此我们只先需要明白,他该做什么,不该做什么就可以了CSConfiguration负责读取配置文件下面是我遇到的经

类多了,看都看晕了.本着职责明确的思想,在n个类的配合下,我们终于得到了我们想要的结果.有时候还真是烦

我本意是不想看配置文件如何读取的,但我就不知不觉的遇到这个问题了,只有耐着性子看了.在此我们只先需要明白,他该做什么,不该做什么就可以了

CSConfiguration负责读取配置文件

下面是我遇到的经历

当我想看看如何获取SiteUrls.config的数据时,我就是找不到读取这个路径的url,且看
SiteUrls的Instance方法

path为载入的SiteUrls.config配置文件


string
path
=
csContext.PhysicalPath(siteUrlProvider.Attributes[

path

]);

string
overridePath
=
csContext.PhysicalPath(siteUrlProvider.Attributes[

overridePath

]);
Typetype
=
Type.GetType(siteUrlProvider.Type);

XmlDocumentdoc
=

null
;


if
(File.Exists(overridePath))


{
doc=Merger.MergeXmlFiles(path,overridePath);
}


else



{
doc=newXmlDocument();
doc.Load(path);
}

于是我找到了Provider类


CSConfigurationconfig
=
CSConfiguration.GetConfig();

ProvidersiteUrlProvider
=
config.Providers[

SiteUrlsDataProvider

]
as
Provider;

继续看CSConfiguration的Providers,其为一个哈希表,我们还不知道如何获取,CSConfiguration让我们看到了唯一的操作就是GetConfig



public
HashtableProviders

{get{returnproviders;}}

让我们再看GetConfig方法,下面的代码有点眉目了,我们终于看到了communityserver.config配置文件,好象跟我们想要的SiteUrls没关系,我们只要一个SiteUrls的路径而已.


string
path
=

null
;

string
overridePath
=

null
;
XmlDocumentdoc
=

null
;
HttpContextcontext
=
HttpContext.Current;

if
(context
!=

null
)


{
path=context.Server.MapPath(“~/communityserver.config“);
overridePath=context.Server.MapPath(“~/communityserver_override.config“);
}


else



{
path=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,“communityserver.config“);
overridePath=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,“communityserver_override.config“);
}




if
(File.Exists(overridePath))


{
doc=Merger.MergeXmlFiles(path,overridePath);
}


else



{
doc=newXmlDocument();
doc.Load(path);
}

再看下来,开始真正实例化了


//
实例化


config
=

new
CSConfiguration(doc);

接着我们去看构造函数干了什么



public
CSConfiguration(XmlDocumentdoc)


{
XmlDoc=doc;
LoadValuesFromConfigurationXml();
}

再看LoadValuesFromConfigurationXml方法,看来真正做事情的是他

看到这里


foreach
(XmlNodechild
in
node.ChildNodes)


{

if(child.Name==“providers“)
GetProviders(child,providers);

if(child.Name==“appLocation“)
GetAppLocation(child);

if(child.Name==“extensionModules“)
GetProviders(child,extensions);

if(child.Name==“roleConfiguration“)
GetRoleConfiguration(child);

if(child.Name==“filterLanguages“)
GetFilterLanguages(child);

if(child.Name==“editors“)
GetEditors(child);
}

打开配置文件看看发现以下节点



<
add

name
=“SiteUrlsDataProvider”

type
=“CommunityServer.Urls.UrlsData,CommunityServer.Urls”

path
=“SiteUrls.config”

overridePath
=”SiteUrls_override.config”


/>




internal

void
GetProviders(XmlNodenode,Hashtabletable)

{

foreach(XmlNodeproviderinnode.ChildNodes){

switch(provider.Name){
case“add“:
table.Add(provider.Attributes[“name“].Value,newProvider(provider.Attributes));
break;

case“remove“:
table.Remove(provider.Attributes[“name“].Value);
break;

case“clear“:
table.Clear();
break;

}

}

}

好了,我们应该差不多搞明白了.其他的应该类似.慢慢的记录.

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477