示例#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();
        }
        public static T Register <T>()
        {
            using (ChoCoreFrxConfigurationManager <T> coreFrxConfigurationManager = new ChoCoreFrxConfigurationManager <T>())
            {
                T instance = coreFrxConfigurationManager.ConfigObject;

                if (instance is IChoObjectChangeWatcheable)
                {
                    if (!ChoAppFrxSettings.Me.DisableFrxConfig)
                    {
                        ChoConfigurationChangeFileWatcher fileWatcher = null;
                        fileWatcher = new ChoConfigurationChangeFileWatcher("{0}_FileWatcher".FormatString(typeof(T).Name), coreFrxConfigurationManager.ConfigFilePath);
                        fileWatcher.DoNotUseGlobalQueue = true;
                        fileWatcher.SetConfigurationChangedEventHandler("{0}_FileWatcher".FormatString(typeof(T).Name), (sender1, e1) =>
                        {
                            using (ChoCoreFrxConfigurationManager <T> coreFrxConfigurationManager1 = new ChoCoreFrxConfigurationManager <T>())
                            {
                                T instance1 = coreFrxConfigurationManager1.ConfigObject;
                                if (instance1 is IChoObjectChangeWatcheable)
                                {
                                    ((IChoObjectChangeWatcheable)instance1).OnObjectChanged(instance1, null);
                                }
                            }
                        });

                        _dictService.AddOrUpdate(typeof(T), fileWatcher);

                        ChoEnvironmentSettings.SetEnvironmentChangedEventHandlerNoCall(typeof(T).Name, ((sender, e) =>
                        {
                            using (ChoCoreFrxConfigurationManager <T> coreFrxConfigurationManager1 = new ChoCoreFrxConfigurationManager <T>())
                            {
                                T instance1 = coreFrxConfigurationManager1.ConfigObject;
                                if (instance1 is IChoObjectChangeWatcheable)
                                {
                                    ((IChoObjectChangeWatcheable)instance1).OnObjectChanged(instance1, null);
                                }
                            }
                        }));

                        if (fileWatcher != null)
                        {
                            fileWatcher.StartWatching();
                        }
                    }
                }

                return(instance);
            }
        }
示例#3
0
        private static void StopGlobalQueuedExecutionService()
        {
            if (_configurationChangeWatcher != null)
            {
                _configurationChangeWatcher.Dispose();
            }
            _configurationChangeWatcher = null;

            if (_systemConfigurationChangeWatcher != null)
            {
                _systemConfigurationChangeWatcher.Dispose();
            }
            _systemConfigurationChangeWatcher = null;

            if (_appXmlDocument != null)
            {
                _appXmlDocument.Dispose();
                _appXmlDocument = null;
            }
        }