/// <summary> /// Loads the plugins found in the given assembly /// </summary> /// <param name="assembly">The assembly to get the plugins from</param> /// <param name="config">Plugins config section</param> /// <param name="context">The plugin context to feed the plugin</param> static void LoadPlugins(Assembly assembly, Config config, IPluginContext context) { // Get reference to plugin interface Type pluginType = typeof(IPlugin); // Get the type which implements IPlugin var types = assembly.GetTypes().Where(p => pluginType.IsAssignableFrom(p) && p != pluginType); // No plugin found if (types.Count() == 0) { Logger.Log("No types found which implements IPlugin in assembly: " + assembly.FullName); return; } // Go through all plugins var thisAssembly = Assembly.GetExecutingAssembly(); foreach (var type in types) { bool ok = true; IPlugin plugin; // Get the configuration Config pluginConfig = null; var name = type.Assembly == thisAssembly ? type.Name : type.Assembly.GetName().Name; bool disabled = false; if (config != null) { pluginConfig = config.Sub(name); if (pluginConfig != null) disabled = pluginConfig.Contains("disabled"); } // Do next if disabled if (disabled) continue; // Create instance of plugin try { plugin = (IPlugin)Activator.CreateInstance(type); } catch (Exception e) { Logger.Log("Cannot instantiate plugin: " + name + " : " + e.Message, Logger.LogLevel.Error); continue; } // Boot the plugin ok = plugin.StartPlugin(pluginConfig, context); // Store plugin if successfull if (ok) { PluginManager.Register(plugin); Logger.Log("Plugin loaded: " + plugin.Name); } else { Logger.Log("Start of plugin failed: " + name, Logger.LogLevel.Error); } } }
/// <summary> /// Loads the plugins found in the given assembly /// </summary> /// <param name="assembly">The assembly to get the plugins from</param> /// <param name="config">Plugins config section</param> /// <param name="context">The plugin context to feed the plugin</param> static void LoadPlugins(Assembly assembly, Config config, IPluginContext context) { // Get reference to plugin interface Type pluginType = typeof(IPlugin); // Get the type which implements IPlugin var types = assembly.GetTypes().Where(p => pluginType.IsAssignableFrom(p) && p != pluginType); // No plugin found if (types.Count() == 0) { Logger.Log("No types found which implements IPlugin in assembly: " + assembly.FullName); return; } // Go through all plugins var thisAssembly = Assembly.GetExecutingAssembly(); foreach (var type in types) { bool ok = true; IPlugin plugin; // Get the configuration Config pluginConfig = null; var name = type.Assembly == thisAssembly ? type.Name : type.Assembly.GetName().Name; bool disabled = false; if (config != null) { pluginConfig = config.Sub(name); if (pluginConfig != null) { disabled = pluginConfig.Contains("disabled"); } } // Do next if disabled if (disabled) { continue; } // Create instance of plugin try { plugin = (IPlugin)Activator.CreateInstance(type); } catch (Exception e) { Logger.Log("Cannot instantiate plugin: " + name + " : " + e.Message, Logger.LogLevel.Error); continue; } // Boot the plugin ok = plugin.StartPlugin(pluginConfig, context); // Store plugin if successfull if (ok) { PluginManager.Register(plugin); Logger.Log("Plugin loaded: " + plugin.Name); } else { Logger.Log("Start of plugin failed: " + name, Logger.LogLevel.Error); } } }