Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        //public static event EventHandler<ChoEventArgs<ChoPathEventArgs>> ResolveFullPath;

        #endregion Shared Data Members (Private)

        #region Constructors

        static ChoPath()
        {
            try
            {
                HttpContext ctx = HttpContext.Current;
                if (ctx == null)
                {
                    _assemblyBaseDirectory = Path.GetDirectoryName(ChoAssembly.GetEntryAssembly().Location);
                }
                else
                {
                    _assemblyBaseDirectory = HttpContext.Current.Request.PhysicalApplicationPath;
                }
            }
            catch (ChoFatalApplicationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ChoApplication.Trace(true, ex.ToString());
            }
        }