private IBioLinkExtension InstantiateExtension(Type type)
        {
            ConstructorInfo   ctor      = type.GetConstructor(new Type[] { });
            IBioLinkExtension extension = null;

            if (ctor != null)
            {
                extension = Activator.CreateInstance(type) as IBioLinkExtension;
            }
            else
            {
                throw new Exception(String.Format("Could not load extension {0} - no default constructor", type.FullName));
            }

            return(extension);
        }
        private void LoadPlugins(PluginAction pluginAction, params string[] paths)
        {
            using (new CodeTimer("Plugin loader")) {
                FileSystemTraverser t = new FileSystemTraverser();
                NotifyProgress("Searching for extensions...", -1, ProgressEventType.Start);

                List <Type> extensionTypes = new List <Type>();

                foreach (string pathelement in paths)
                {
                    string path       = pathelement;
                    string filterexpr = ".*[.]dll$";
                    if (path.Contains("|"))
                    {
                        path       = pathelement.Substring(0, pathelement.IndexOf("|"));
                        filterexpr = pathelement.Substring(pathelement.IndexOf("|") + 1);
                    }

                    Regex regex = new Regex(filterexpr, RegexOptions.IgnoreCase);

                    FileSystemTraverser.Filter filter = (fileinfo) => {
                        return(regex.IsMatch(fileinfo.Name));
                    };

                    Logger.Debug("LoadPlugins: Scanning: {0}", path);
                    t.FilterFiles(path, filter, fileinfo => { ProcessAssembly(fileinfo, extensionTypes); }, false);
                }

                NotifyProgress("Loading plugins...", 0, ProgressEventType.Start);
                int i = 0;

                foreach (Type type in extensionTypes)
                {
                    try {
                        Logger.Debug("Instantiating type {0}", type.FullName);

                        IBioLinkExtension extension = InstantiateExtension(type);

                        if (extension != null)
                        {
                            if (extension is IBioLinkPlugin)
                            {
                                IBioLinkPlugin plugin = extension as IBioLinkPlugin;
                                Logger.Debug("Initializing Plugin {0}...", plugin.Name);
                                plugin.InitializePlugin(User, this, this.ParentWindow);

                                Logger.Debug("Integrating Plugin...", plugin.Name);
                                // Allow the consumer to process this plugin...
                                if (pluginAction != null)
                                {
                                    pluginAction(plugin);
                                }
                            }

                            _extensions.Add(extension);

                            double percentComplete = ((double)++i / (double)extensionTypes.Count) * 100.0;
                            NotifyProgress(extension.Name, percentComplete, ProgressEventType.Update);
                        }

                        DoEvents();
                    } catch (Exception ex) {
                        GlobalExceptionHandler.Handle(ex);
                    }
                }

                // Fire an event signalling plugin loading is complete, and all plugins have been initialized
                if (this.PluginsLoaded != null)
                {
                    PluginsLoaded(this);
                }

                NotifyProgress("Plugin loading complete", 100, ProgressEventType.End);
            }
        }