Beispiel #1
0
        private static T GetSourcedObject <T>(string configSource) where T : class
        {
            T    sourcedObject = default(T);
            Type objectType    = typeof(T);

            try
            {
                XmlSerializer ser = new XmlSerializer(objectType);

                if (!String.IsNullOrEmpty(configSource))
                {
                    string    path   = GetFilePath(configSource);
                    XmlReader reader = XmlReader.Create(path);
                    sourcedObject = ser.Deserialize(reader) as T;
                    reader.Close();
                    ConfigurationWatcher.WatchFile(path, ReloadConfig);
                }
            }
            catch (Exception ex)
            {
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat("Error getting sourced config of type {0}: {1}", objectType.FullName, ex);
                }
                //we want callers to know there was a problem, also all of the config file needs to be loaded,
                //for relay to function
                throw;
            }
            return(sourcedObject);
        }
Beispiel #2
0
        private static void WatchConfig(RelayNodeConfig mainConfig)
        {
            //either way, watch the file that represents it, since it might switch between local and not
            ConfigurationSection relayNodeConfigSection = ConfigurationFile.GetSection(ConfigSectionName);
            string configSource = String.Empty;

            if (relayNodeConfigSection != null)
            {
                configSource = relayNodeConfigSection.SectionInformation.ConfigSource;
            }

            string configPath = String.Empty;

            if (!String.IsNullOrEmpty((configSource)))
            {
                //if there's no config source, then the info is embedded in the app config, and that's the file we need to watch
                if (HttpContext.Current == null)
                {
                    //but if there's an httpcontext, then we're in a web context, and you can't update an IIS config file without bouncing
                    //the appdomain, so there's no point in watching it.
                    configPath = Path.Combine(BasePath, configSource);
                }
            }
            else
            {
                configPath = Path.GetFullPath(ConfigurationFile.FilePath);
            }

            if (!string.IsNullOrEmpty(configPath))
            {
                ConfigurationWatcher.WatchFile(configPath, ReloadConfig);
            }

            //if it came from config server, then register reload notification there
            if (mainConfig.UseConfigurationServer)
            {
                ConfigurationWatcher.WatchRemoteSection(mainConfig.ConfigurationServerSectionName, ReloadConfig);
            }
        }