private static NestedConfig InitConfig() { var configs = ConfigurationManager.GetSection("projects.resource") as NameValueCollection; if (configs == null) { throw new Exception("配置文件中缺少projects.resource节点"); } var config = new NestedConfig(); //Debug if (!String.IsNullOrEmpty(configs["Debug"])) { config.Debug = Convert.ToBoolean(configs["Debug"]); } //Version if (!String.IsNullOrEmpty(configs["Version"])) { config.Version = Convert.ToString(configs["Version"]); } //ServierList if (String.IsNullOrEmpty(configs["StaticSite"])) { throw new Exception("配置节点StaticSite不能为空"); } var servers = configs["StaticSite"].Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var url in servers) { string server = String.Empty; if (!url.StartsWith("http")) { server = String.Concat("http://", url); } else { server = url; } if (!url.EndsWith("/")) { server += "/"; } config.ServerList.Add(url); } return(config); }
static GlobalConfig() { mConfig = InitConfig(); }