private static void LoadConfigurationFile() { if (_appXmlDocument != null) { _appXmlDocument.Dispose(); _appXmlDocument = null; } _appXmlDocument = new ChoXmlDocument(_appConfigPath); _appIncludeConfigFilePaths = _appXmlDocument.IncludeFiles; if (_appXmlDocument != null && _appIncludeConfigFilePaths != null && _appIncludeConfigFilePaths.Length > 0) { _appXmlDocument.XmlDocument.Save(_appConfigPath); } if (_configurationChangeWatcher == null) { _configurationChangeWatcher = new ChoAppConfigurationChangeFileWatcher("configurations", _appConfigPath, _appIncludeConfigFilePaths); _configurationChangeWatcher.SetConfigurationChangedEventHandler(_key, new ChoConfigurationChangedEventHandler(_configurationChangeWatcher_ConfigurationChanged)); ChoEnvironmentSettings.SetEnvironmentChangedEventHandlerNoCall("configurations", (sender, e) => { ChoAppConfigurationChangeFileWatcher configurationChangeWatcher = _configurationChangeWatcher; _configurationChangeWatcher = null; _configurationChangeWatcher_ConfigurationChanged(null, null); configurationChangeWatcher.OnConfigurationChanged(); configurationChangeWatcher.Dispose(); configurationChangeWatcher = null; }); } else { _configurationChangeWatcher.Reset(_appConfigPath, _appIncludeConfigFilePaths); } if (_systemConfigurationChangeWatcher == null) { try { _systemConfigurationChangeWatcher = new ChoConfigurationChangeFileWatcher("systemConfigurations", AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); _systemConfigurationChangeWatcher.SetConfigurationChangedEventHandler(_key, new ChoConfigurationChangedEventHandler(_systemConfigurationChangeWatcher_ConfigurationChanged)); } catch (Exception ex) { ChoApplication.Trace(ex.ToString()); } } //Remove namespaces if (_appXmlDocument != null && _appIncludeConfigFilePaths != null && _appIncludeConfigFilePaths.Length > 0) { XDocument doc = XDocument.Load(_appConfigPath, LoadOptions.PreserveWhitespace); doc.Descendants().Attributes().Where(a => a.IsNamespaceDeclaration).Remove(); doc.Save(_appConfigPath, SaveOptions.DisableFormatting); } _configuration = _appXmlDocument.XmlDocument.DocumentElement.ToObject <ChoConfiguration>(); _configuration.Initialize(); }
private static void Refresh() { try { lock (_padLock) { _propDict.Clear(); } if (ChoMetaDataFilePathSettings.Me != null) { _metaDataFilepath = ChoMetaDataFilePathSettings.Me.OverridenConfigurationMetaDataFilePath; } if (!ChoAppFrxSettings.Me.DisableMetaDataConfig) { ChoXmlDocument.CreateXmlFileIfEmpty(_metaDataFilepath); _configurationChangeWatcher = new ChoAppConfigurationChangeFileWatcher("meta-data_configurations", _metaDataFilepath, _includeFiles); _configurationChangeWatcher.SetConfigurationChangedEventHandler("ChoMetaDataManager_Watcher", (sender, e) => { Refresh(); }); } if (!_metaDataFilepath.IsNullOrWhiteSpace() && File.Exists(_metaDataFilepath)) { using (ChoXmlDocument xmlDocument = new ChoXmlDocument(_metaDataFilepath)) { _rootNode = xmlDocument.XmlDocument.DocumentElement; _includeFiles = xmlDocument != null ? xmlDocument.IncludeFiles : null; } } } catch (Exception ex) { ChoTrace.Error(ex.ToString()); //throw; } }
internal static void OpenExeConfiguration() { //Expand Application configuration file string appConfigPath = AppConfigFilePath; // AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; if (!File.Exists(appConfigPath)) { return; } ChoFile.SetReadOnly(appConfigPath, false); if (_configurationChangeWatcher != null) { RestoreAppConfig(); _configurationChangeWatcher.StopWatching(); _configurationChangeWatcher = null; } //backup the current configuration string backupConfigFilePath = String.Format("{0}.cho", appConfigPath); File.Copy(appConfigPath, backupConfigFilePath, true); try { _appXmlDocument = new ChoXmlDocument(appConfigPath, false, true); _appIncludeConfigFilePaths = _appXmlDocument.IncludeFiles; if (_appXmlDocument != null && _appIncludeConfigFilePaths != null && _appIncludeConfigFilePaths.Length > 0) { _appXmlDocument.XmlDocument.Save(appConfigPath); } _configurationChangeWatcher = new ChoAppConfigurationChangeFileWatcher(ChoConfigurationManager.AppConfigFilePath, "Configurations"); _configurationChangeWatcher.SetConfigurationChangedEventHandler(_key, new ChoConfigurationChangedEventHandler(_configurationChangeWatcher_ConfigurationChanged)); //Remove namespaces if (_appXmlDocument != null && _appIncludeConfigFilePaths != null && _appIncludeConfigFilePaths.Length > 0) { XDocument doc = XDocument.Load(appConfigPath, LoadOptions.PreserveWhitespace); doc.Descendants().Attributes().Where(a => a.IsNamespaceDeclaration).Remove(); doc.Save(appConfigPath, SaveOptions.DisableFormatting); } _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //TODO: use XmlDocument to expand if (ChoEnvironmentSettings.HasAppConfigPathSpecified()) { appConfigPath = ChoEnvironmentSettings.GetAppConfigPath(); if (!String.IsNullOrEmpty(appConfigPath)) { _configuration = ConfigurationManager.OpenExeConfiguration(appConfigPath); } } } catch { //Rollback the configuration file File.Copy(backupConfigFilePath, appConfigPath, true); throw; } }