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); }
// At the moment, we simply use an InstanceBuilder here. In the future, we could provide the option to // give a set of supported file extensions in the player builder item registration, which can be evaluated before // requesting the player builder -> lazy load the player builders on request public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin) { BuilderHelper.CheckParameter("ClassName", itemData); int priority = 0; string prioString; if (itemData.Attributes.TryGetValue("Priority", out prioString)) { int.TryParse(prioString, out priority); } return(new PlayerBuilderWrapper(itemData.Id, plugin.InstantiatePluginObject(itemData.Attributes["ClassName"]) as IPlayerBuilder, priority)); }
public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin) { BackgroundType type; string value = GetBackgroundAndType(itemData.Attributes, out type); switch (type) { case BackgroundType.Static: return(new StaticBackgroundManager(value)); case BackgroundType.Manager: // The cast is necessary here to ensure the returned instance is an IBackgroundManager return((IBackgroundManager)plugin.InstantiatePluginObject(value)); default: throw new NotImplementedException(string.Format( "Background builder: Background type '{0}' is not implemented", type)); } }
public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin) { BuilderHelper.CheckParameter("ServiceClassName", itemData); string serviceClassName = itemData.Attributes["ServiceClassName"]; object serviceInstance = plugin.InstantiatePluginObject(serviceClassName); if (serviceInstance == null) { ServiceRegistration.Get <ILogger>().Warn("ServiceBuilder: Could not instantiate service class '{0}' in plugin '{1}' (id: '{2}')", serviceClassName, itemData.PluginRuntime.Metadata.Name, itemData.PluginRuntime.Metadata.PluginId); return(null); } string registrationClassAssembly; if (!itemData.Attributes.TryGetValue("RegistrationClassAssembly", out registrationClassAssembly)) { registrationClassAssembly = null; } string registrationClassName; if (!itemData.Attributes.TryGetValue("RegistrationClassName", out registrationClassName)) { registrationClassName = null; } Type registrationType; if (string.IsNullOrEmpty(registrationClassName)) { registrationType = serviceInstance.GetType(); } else { registrationType = string.IsNullOrEmpty(registrationClassAssembly) ? plugin.GetPluginType(registrationClassName) : Type.GetType(registrationClassName + ", " + registrationClassAssembly); } if (registrationType == null) { ServiceRegistration.Get <ILogger>().Warn("ServiceBuilder: Could not instantiate service registration type '{0}' (Assembly: '{1}') in plugin '{2}' (id: '{3}')", registrationClassName, registrationClassAssembly, itemData.PluginRuntime.Metadata.Name, itemData.PluginRuntime.Metadata.PluginId); return(null); } return(new ServiceItem(registrationType, serviceInstance)); }
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(); 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 object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin) { BuilderHelper.CheckParameter("ClassName", itemData); return(plugin.InstantiatePluginObject(itemData.Attributes["ClassName"])); }