/// <summary> /// Constructs and scans a directory for compatible plugins /// </summary> /// <param name="dir">Directory to scan for DLLs</param> public PluginManager(string dir) { inst_ = this; string path = Path.Combine(Directory.GetCurrentDirectory(), dir); if (!Directory.Exists(path)) return; foreach (string file in Directory.GetFiles(path)) { if (Path.GetExtension(file).Equals(".dll") && File.Exists(file)) { try { Assembly asm = Assembly.LoadFile(file); Type[] types = asm.GetExportedTypes(); FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(asm.Location); PluginInfo plugin = new PluginInfo(asm.ManifestModule.Name, new string[] { myFileVersionInfo.ProductName, myFileVersionInfo.ProductVersion, myFileVersionInfo.CompanyName, myFileVersionInfo.Comments }); foreach (Type t in types) { if (t.GetInterface("PluginLib.IFileEditor") != null) { fileServices_.Add((PluginLib.IFileEditor)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } else if (t.GetInterface("PluginLib.ISearchService") != null) { searchServices_.Add((PluginLib.ISearchService)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } else if (t.GetInterface("PluginLib.ICompilerService") != null) { compilers_.Add((PluginLib.ICompilerService)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } else if (t.GetInterface("PluginLib.IInfoTab") != null) { infoTabs_.Add((PluginLib.IInfoTab)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } else if (t.GetInterface("PluginLib.IBackgroundService") != null) { backgroundServices_.Add((PluginLib.IBackgroundService)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } } if (plugin.Components.Count > 0) assemblies.Add(plugin); } catch (Exception ex) { ErrorHandler.inst().Error(ex); } } } }
/// <summary> /// Constructs and scans a directory for compatible plugins /// </summary> /// <param name="dir">Directory to scan for DLLs</param> public PluginManager(string dir) { inst_ = this; string path = Path.Combine(Directory.GetCurrentDirectory(), dir); if (!Directory.Exists(path)) { return; } foreach (string file in Directory.GetFiles(path)) { if (Path.GetExtension(file).Equals(".dll") && File.Exists(file)) { try { Assembly asm = Assembly.LoadFile(file); Type[] types = asm.GetExportedTypes(); FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(asm.Location); PluginInfo plugin = new PluginInfo(asm.ManifestModule.Name, new string[] { myFileVersionInfo.ProductName, myFileVersionInfo.ProductVersion, myFileVersionInfo.CompanyName, myFileVersionInfo.LegalCopyright, myFileVersionInfo.Comments }); foreach (Type t in types) { if (t.GetInterface("PluginLib.IFileEditor") != null) { fileServices_.Add((PluginLib.IFileEditor)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } else if (t.GetInterface("PluginLib.ISearchService") != null) { searchServices_.Add((PluginLib.ISearchService)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } else if (t.GetInterface("PluginLib.ICompilerService") != null) { compilers_.Add((PluginLib.ICompilerService)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } else if (t.GetInterface("PluginLib.IInfoTab") != null) { infoTabs_.Add((PluginLib.IInfoTab)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } else if (t.GetInterface("PluginLib.IBackgroundService") != null) { backgroundServices_.Add((PluginLib.IBackgroundService)Activator.CreateInstance(t)); plugin.Components.Add(t.Name); } } if (plugin.Components.Count > 0) { assemblies.Add(plugin); } } catch (Exception ex) { ErrorHandler.inst().Error(ex); } } } }