/// <summary> /// Updates or creates and updates configuration for specified plugin /// </summary> /// <typeparam name="TConfig">Plugin configuration type</typeparam> /// <param name="conf">Table configuration</param> /// <param name="pluginId">Plugin ID</param> /// <param name="pluginConfiguration">Configuration function</param> /// <param name="where">Specifies which plugin is mentioned</param> public static void UpdatePluginConfig <TConfig>(this TableConfiguration conf, string pluginId, Action <PluginConfigurationWrapper <TConfig> > pluginConfiguration, string where = null) where TConfig : new() { PluginConfiguration config = conf.GetPluginConfiguration(pluginId, where); if (config == null) { config = new PluginConfiguration(pluginId) { Configuration = new TConfig(), Placement = where }; conf.PluginsConfiguration.Add(config); if (config.Configuration is IProvidesTemplate) { config.TemplateId = ((IProvidesTemplate)config.Configuration).DefaultTemplateId; } } var wpapper = new PluginConfigurationWrapper <TConfig>(config); if (pluginConfiguration != null) { pluginConfiguration(wpapper); } }
/// <summary> /// Retrieves configuration for specified plugin /// </summary> /// <typeparam name="TConfig">Plugin configuration type</typeparam> /// <param name="conf">Table JSON configuration</param> /// <param name="pluginId">Plugin ID</param> /// <param name="placement">Plugin placement</param> /// <returns></returns> public static TConfig GetPluginConfig <TConfig>(this TableConfiguration conf, string pluginId, string placement = null) where TConfig : class { var config = conf.GetPluginConfiguration(pluginId, placement); if (config == null) { return(null); } return((TConfig)config.Configuration); }
/// <summary> /// Replaces plugin configuration with whole new configuration /// </summary> /// <param name="conf">Table configuration</param> /// <param name="pluginId">Plugin ID</param> /// <param name="pluginConfig">Configuration object</param> /// <param name="placement">Plugin placement</param> /// <param name="order">Order among particular placement</param> public static void ReplacePluginConfig(this TableConfiguration conf, string pluginId, object pluginConfig, string placement = null, int order = 0) { var config = conf.GetPluginConfiguration(pluginId, placement); if (config == null) { config = new PluginConfiguration(pluginId); conf.PluginsConfiguration.Add(config); } config.Configuration = pluginConfig; config.Placement = placement; config.Order = order; }