protected ConfigBase Instantiate(ConfigBaseMetadata metadata, PluginRuntime pluginRuntime) { ServiceRegistration.Get<ILogger>().Debug("ConfigurationNode: Loading configuration item '{0}'", metadata.Location); ConfigBase result; if (metadata.GetType() == typeof(ConfigGroupMetadata)) result = new ConfigGroup(); else if (metadata.GetType() == typeof(ConfigSectionMetadata)) result = new ConfigSection(); else if (metadata.GetType() == typeof(ConfigSettingMetadata)) { ConfigSettingMetadata csm = (ConfigSettingMetadata) metadata; try { ConfigSetting cs = (ConfigSetting) pluginRuntime.InstantiatePluginObject(csm.ClassName); if (cs == null) throw new ArgumentException(string.Format("Configuration class '{0}' not found", csm.ClassName)); cs.Load(); if (csm.ListenTo != null) foreach (string listenToLocation in csm.ListenTo) { IConfigurationNode node; if (FindNode(listenToLocation, out node)) if (node.ConfigObj is ConfigSetting) cs.ListenTo((ConfigSetting) node.ConfigObj); else ServiceRegistration.Get<ILogger>().Warn("ConfigurationNode '{0}': Trying to listen to setting, but location '{1}' references a {2}", Location, listenToLocation, node.ConfigObj.GetType().Name); } result = cs; } catch (Exception ex) { ServiceRegistration.Get<ILogger>().Error("Error loading configuration class '{0}'", ex, csm.ClassName); return null; } } else throw new NotImplementedException(string.Format("Unknown child class '{0}' of '{1}'", metadata.GetType().FullName, typeof(ConfigBaseMetadata).FullName)); result.SetMetadata(metadata); return result; }
public override void SetMetadata(ConfigBaseMetadata metadata) { base.SetMetadata(metadata); _metadata = metadata; _help = LocalizationHelper.CreateResourceString(SettingMetadata.HelpText); }
public virtual void SetMetadata(ConfigBaseMetadata metadata) { _metadata = metadata; _text = LocalizationHelper.CreateResourceString(_metadata.Text); }