private void LoadPlugins(string folder) { string[] dllInFolder = Directory.GetFiles(folder, "*.dll"); _context.Log(string.Format("No of files in folder [{0}]", dllInFolder.Count().ToString())); foreach (string dll in dllInFolder) { _context.Log(string.Format("Scanning [{0}] for plugins", Path.GetFileName(dll))); Assembly assembly = Assembly.LoadFrom(dll); //find every type in each assembly that implements IPlugin Type[] allTypes = assembly.GetTypes() .Where(type => type.GetInterface(typeof(IPlugin).Name) != null) .ToArray <Type>(); foreach (Type type in allTypes) { // if (type.GetInterface("IPlugin") == typeof(IPlugin) ) //typeof(IPlugin).IsAssignableFrom(type)) { _context.Log(string.Format("+ Adding [{0}] to repository", type.Name)); IPlugin plu = Activator.CreateInstance(type) as IPlugin; PluginsList[type.Name] = (plu); } } assembly = null; } }
public PluginManager(ref IPluginContext pluginContext) { _context = pluginContext; string pluginDirectory = string.Format("{0}plugins", AppDomain.CurrentDomain.BaseDirectory); if (!Directory.Exists(pluginDirectory)) { pluginDirectory = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["pluginfolder"]); } _context.Log(string.Format("Loading plugins from [{0}]", pluginDirectory)); LoadPlugins(pluginDirectory); }