/// <summary> /// Only for use by plugins during IPlugin.Install. Call Plugin.Install instead of this method, since plugins often must perform other initialization actions. /// Adds the specified plugin to AllPlugins, QuerystringPlugins, CachingSystems, ImageEncoders, and ImageBuilderExtensions, based /// on which interfaces the instance implements. For ICache and IEncoder, the plugin is inserted at the beginning of CachingSystems and ImageEncoders respectively. /// To reiterate, plugins may register event handlers and modify settings - thus you should use the plugin's method to uninstall them vs. using this method. /// Will not register a plugin that is already installed, unless it implements IMultiInstancePlugin. /// </summary> /// <param name="plugin"></param> public void add_plugin(IPlugin plugin) { if (!(plugin is IMultiInstancePlugin) && HasPlugin(plugin.GetType())) { AcceptIssue(new Issue("An instance of the specified plugin (" + plugin.GetType().ToString() + ") has already been registered.", "The plugin should implement IMultiInstancePlugin to support multiple instances.", IssueSeverity.Error)); return; } AllPlugins.Add(plugin); if (plugin is IQuerystringPlugin) { QuerystringPlugins.Add(plugin as IQuerystringPlugin); } if (plugin is IFileExtensionPlugin) { FileExtensionPlugins.Add(plugin as IFileExtensionPlugin); } if (plugin is ICache) { CachingSystems.AddFirst(plugin as ICache); } if (plugin is IEncoder) { ImageEncoders.AddFirst(plugin as IEncoder); } if (plugin is BuilderExtension) { ImageBuilderExtensions.Add(plugin as BuilderExtension); } if (plugin is IVirtualImageProvider) { VirtualProviderPlugins.Add(plugin as IVirtualImageProvider); } if (plugin is ISettingsModifier) { SettingsModifierPlugins.Add(plugin as ISettingsModifier); } if (plugin is ICurrentConfigProvider) { ConfigProviders.Add(plugin as ICurrentConfigProvider); } if (plugin is ILogManager) { LogManager = plugin as ILogManager; } if (plugin is ILicensedPlugin || plugin is ILicenseProvider) { FireLicensePluginsChange(); } }
/// <summary> /// Initializes the List of Plugins by collecting Plugins from the project and given .dll files. /// </summary> public PluginManager() { string wdir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var lst = Directory.GetFiles(wdir) .Where(i => new[] { ".dll", ".exe" }.Contains(Path.GetExtension(i))) .SelectMany(i => Assembly.LoadFrom(i).GetTypes()) .Where(myType => myType.IsClass && !myType.IsAbstract && myType.GetCustomAttributes(true).Any(i => i.GetType() == typeof(AutoLoadPluginAttribute)) && myType.GetInterfaces().Any(i => i == typeof(IPlugin))); foreach (Type type in lst) { AllPlugins.Add((IPlugin)Activator.CreateInstance(type)); } }
public static void EnablePlugin(PluginPair plugin) { var actionKeywords = plugin.Metadata.ActionKeywords; if (actionKeywords == null || actionKeywords.Count == 0 || actionKeywords[0] == Query.GlobalPluginWildcardSign) { GlobalPlugins.Add(plugin); } else { foreach (var actionkeyword in plugin.Metadata.ActionKeywords) { NonGlobalPlugins[actionkeyword] = plugin; } } AllPlugins.Add(plugin); }
/// <summary>Registers the plugin.</summary> /// <typeparam name="T"></typeparam> /// <param name="plugin">The plugin.</param> /// <returns></returns> public T RegisterPlugin <T>(T plugin) where T : IHzPlugin { // ExecuteEvent += plugin.OnExcecuteAsync; AllPlugins.Add(plugin); return(plugin); }