static ChoConfigurationMetaDataManager()
 {
     ChoEnvironmentSettings.SetEnvironmentChangedEventHandlerNoCall("meta-data_configurations",
                                                                    (sender, e) =>
     {
         Refresh();
     });
 }
Esempio n. 2
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. 3
0
 static ChoProfileBackingStoreManager()
 {
     Refresh();
     ChoEnvironmentSettings.SetEnvironmentChangedEventHandlerNoCall(PBS_DATA_KEY,
                                                                    (sender, e) =>
     {
         Refresh();
     });
 }
        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);
            }
        }
Esempio n. 5
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            XPathNavigator navigator = section.CreateNavigator();

            string path = (string)navigator.Evaluate("string(@path)");

            if (path != null && path.Length > 0)
            {
                bool envFriendly = false;
                try
                {
                    envFriendly = Boolean.Parse((string)navigator.Evaluate("string(@envFriendly)"));
                }
                catch { }

                if (envFriendly)
                {
                    path = ChoEnvironmentSettings.ToEnvSpecificConfigFile(path);
                }

                path = ChoPath.GetFullPath(path);
                if (!File.Exists(path))
                {
                    throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1002, path));
                }

                XmlDocument document = new XmlDocument();
                document.Load(path);

                section   = document.DocumentElement;
                navigator = section.CreateNavigator();
            }

            string typename = (string)navigator.Evaluate("string(@type)");

            if (typename == null || typename.Trim().Length == 0)
            {
                throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1003, section.Name));
            }

            Type type = Type.GetType(typename);

            if (type == null)
            {
                type = ChoType.GetType(typename);
            }

            if (type == null)
            {
                throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1004, typename));
            }

            ChoConfigFilesMapper.Add(section.Name, path);

            XmlSerializer serializer = new XmlSerializer(type);

            try
            {
                return(serializer.Deserialize(new XmlNodeReader(section)));
            }
            catch
            {
                if (section.Name != type.Name && section.Name.ToUpper() == type.Name.ToUpper())
                {
                    XmlNode newSection = new XmlDocument().CreateElement(type.Name);
                    newSection.InnerXml = section.InnerXml;
                    section             = newSection;
                }
                return(serializer.Deserialize(new XmlNodeReader(section)));
            }
        }
Esempio n. 6
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            XPathNavigator navigator = section.CreateNavigator();

            string path = (string)navigator.Evaluate("string(@path)");

            if (path != null && path.Length > 0)
            {
                bool envFriendly = false;
                try
                {
                    envFriendly = Boolean.Parse((string)navigator.Evaluate("string(@envFriendly)"));
                }
                catch { }

                if (envFriendly)
                {
                    path = ChoEnvironmentSettings.ToEnvSpecificConfigFile(path);
                }

                path = RITPath.GetFullPath(path);
                if (!File.Exists(path))
                {
                    throw new ApplicationException(String.Format("{0} not exists.", path));
                }

                XmlDocument document = new XmlDocument();
                document.Load(path);

                section   = document.DocumentElement;
                navigator = section.CreateNavigator();
            }

            string typename = (string)navigator.Evaluate("string(@type)");

            if (typename == null || typename.Trim().Length == 0)
            {
                throw new ApplicationException(String.Format("Missing type attribute in the '{0}' config section.", section.Name));
            }

            Type type = Type.GetType(typename);

            if (type == null)
            {
                type = new RITType().GetType(typename);
            }

            if (type == null)
            {
                throw new ApplicationException(String.Format("Can't find {0} type.", typename));
            }

            RITConfigFileLocator.Add(section.Name, path);

            XmlSerializer serializer = new XmlSerializer(type);

            try
            {
                return(serializer.Deserialize(new XmlNodeReader(section)));
            }
            catch
            {
                if (section.Name != type.Name && section.Name.ToUpper() == type.Name.ToUpper())
                {
                    XmlNode newSection = new XmlDocument().CreateElement(type.Name);
                    newSection.InnerXml = section.InnerXml;
                    section             = newSection;
                }
                return(serializer.Deserialize(new XmlNodeReader(section)));
            }
        }
        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;
            }
        }