private static string GetRemoteConfigFile() { string remoteFile = System.Web.Configuration.WebConfigurationManager.AppSettings[RemoteConfigFileAppSettingKey]; if (remoteFile == null) { remoteFile = LocalConfigurationManager.MapConfigPath(RemoteConfigurationManagerConfigFileName); } else { remoteFile = LocalConfigurationManager.MapConfigPath(remoteFile); } if (!File.Exists(remoteFile)) { LoggerWrapper.Logger.Info("配置文件" + remoteFile + "' 不存在, 将会在 '" + ConfigUtility.DefaultApplicationConfigFolder + "'创建新的默认配置文件"); remoteFile = ConfigUtility.Combine(ConfigUtility.DefaultApplicationConfigFolder, RemoteConfigurationManagerConfigFileName); // 如果 "RemoteConfigurationManager.config" 不存在时必须在此创建默认配置 if (!File.Exists(remoteFile)) { Directory.CreateDirectory(ConfigUtility.DefaultApplicationConfigFolder); using (XmlTextWriter writer = new XmlTextWriter(remoteFile, Encoding.UTF8)) { writer.WriteStartElement(RemoteConfigurationManagerConfiguration.TagName); RemoteConfigurationManagerConfiguration.DefaultConfig.WriteXml(writer); writer.WriteEndElement(); } } } return(remoteFile); }
public static T GetSection <T>(string name, string path, out bool fromRemote) { if (System.IO.File.Exists(path)) { fromRemote = false; return(ConfigWatcher.CreateAndSetupWatcher <T>(LocalConfigurationManager.MapConfigPath(path))); } else { fromRemote = true; return(RemoteConfigurationManager.Instance.GetSection <T>(name)); } }