public class Log : LogDataService
{
/// <summary>
/// key is envrionment name, value is envrionment path
/// </summary>
/// <returns></returns>
protected override Dictionary<string, string> GetEnvironment()
{
//NameValueCollection keyValues = ConfigurationManager.AppSettings;
//Dictionary<string, string> dicNameAndPath = new Dictionary<string, string>();
//foreach (var item in keyValues.AllKeys)
//{
// dicNameAndPath.Add(item, keyValues[item]);
//}
//return dicNameAndPath;
Dictionary<string, string> dicNameAndPath = new Dictionary<string, string>();
List<Environment> lstEnvironment = ConfigurationManager.GetSection("EnvironmentList") as List<Environment>;
foreach (Environment info in lstEnvironment)
{
dicNameAndPath.Add(info.EnvironmentName, info.EnvironmentPath);
}
return dicNameAndPath;
}
protected override string GetConfigPath()
{
return HttpContext.Current.Server.MapPath("~/App_Data/Config/Log/");
}
}
public class Environment
{
public Environment(XmlNode siteinfo)
{
XmlElement info = (XmlElement)siteinfo;
this.EnvironmentName = info.SelectSingleNode("EnvironmentName").InnerText;
this.EnvironmentPath = info.SelectSingleNode("EnvironmentPath").InnerText;
}
public string EnvironmentName { get; set; }
public string EnvironmentPath { get; set; }
}
public class ConvertCfgHandler : IConfigurationSectionHandler
{
public object Create(object parent, object configContext, XmlNode section)
{
List<Environment> lstEnvironment = new List<Environment>();
foreach (XmlNode xmlEnvironment in section.SelectNodes("//Environment"))
{
Environment environment = new Environment(xmlEnvironment);
lstEnvironment.Add(environment);
}
return lstEnvironment;
}
}
web.config文件
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="EnvironmentList" type="FuturMaster.Web.Services.ConvertCfgHandler,FuturMaster.Web.WebApp"/>
</configSections>
<EnvironmentList>
<Environment>
<EnvironmentName>Product</EnvironmentName>
<EnvironmentPath>Z:\ZhiqiangXu\</EnvironmentPath>
</Environment>
<Environment>
<EnvironmentName>Test</EnvironmentName>
<EnvironmentPath>C:\FMRobotLog\Script and Log\</EnvironmentPath>
</Environment>
<Environment>
<EnvironmentName>Release</EnvironmentName>
<EnvironmentPath>E:\FMWork\BatchLogs\</EnvironmentPath>
</Environment>
<Environment>
<EnvironmentName>Samples</EnvironmentName>
<EnvironmentPath>M:\Buny\FMLogServer\Requirement\Samples\Logs and scripts\</EnvironmentPath>
</Environment>
</EnvironmentList>
<location path="FMBiz4Browser.svc">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<system.web>
</system.web>
</configuration>