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);
        }
Пример #2
0
 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));
     }
 }
        static LocalConfigurationManager()
        {
            _systemConfig         = GetExeConfig();
            localBaseConfigFolder = Path.GetDirectoryName(_systemConfig.FilePath);
            instance = new LocalConfigurationManager();
            XmlDocument doc = new XmlDocument();

            if (File.Exists(_systemConfig.FilePath))
            {
                doc.Load(_systemConfig.FilePath);
            }
            else
            {
                doc.LoadXml("<configuration/>");
            }
            _systemConfigXml = doc;
        }