private void MainForm_Load(object sender, EventArgs e) { try { List <PluginInfo> skeletonLoaders = PluginManager.GetInst().GetPlugins(typeof(MoCapPluginLib.ISkeletonImporter)); foreach (PluginInfo pi in skeletonLoaders) { ToolStripMenuItem item = new ToolStripMenuItem(pi.Name); item.Click += delegate(object src, EventArgs args) { MessageBox.Show(pi.Name); }; loadSkeletonToolStripMenuItem.DropDownItems.Add(item); } List <PluginInfo> animExporters = PluginManager.GetInst().GetPlugins(typeof(MoCapPluginLib.IAnimationExporter)); foreach (PluginInfo pi in animExporters) { ToolStripMenuItem item = new ToolStripMenuItem(pi.Name); item.Click += delegate(object src, EventArgs args) { MessageBox.Show(pi.Name); }; exportToolStripMenuItem.DropDownItems.Add(item); } } catch (Exception ex) { ErrorHandler.GetInst().PushError(ex); } loaded = true; }
private PluginManager() { Assemblies = new List <PluginAssemblyInfo>(); Plugins = new Dictionary <Type, List <PluginInfo> >(); Selected = new Dictionary <Type, PluginInfo>(); // Build lists Plugins[typeof(MoCapPluginLib.IAnimationExporter)] = new List <PluginInfo>(); Plugins[typeof(MoCapPluginLib.ISkeletonImporter)] = new List <PluginInfo>(); string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins"); if (!System.IO.Directory.Exists(path)) { return; } foreach (string file in System.IO.Directory.GetFiles(path)) { if (System.IO.Path.GetExtension(file).Equals(".dll") && System.IO.File.Exists(file)) { try { Assembly asm = Assembly.LoadFile(file); Type[] types = asm.GetExportedTypes(); FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(asm.Location); PluginAssemblyInfo plugin = new PluginAssemblyInfo(asm.ManifestModule.Name, new string[] { myFileVersionInfo.ProductName, myFileVersionInfo.ProductVersion, myFileVersionInfo.CompanyName, myFileVersionInfo.Comments }); Assemblies.Add(plugin); foreach (Type t in types) { foreach (Type keyType in Plugins.Keys) { if (t.GetInterfaces().Contains(keyType)) { object plugObject = Activator.CreateInstance(t); if (plugObject != null) { string plugName = t.Name; MoCapPluginLib.AdvertiseSettings settingsRoot = t.GetCustomAttribute <MoCapPluginLib.AdvertiseSettings>(); if (settingsRoot != null) { plugName = settingsRoot.Name; } PluginInfo plugInfo = new PluginInfo(plugObject, plugName); Plugins[keyType].Add(plugInfo); } } } } if (plugin.Components.Count > 0) { Assemblies.Add(plugin); } } catch (Exception ex) { ErrorHandler.GetInst().PushError(ex); } } } }