Provides support for managing the loaded plugins.
        public NativeMethods.WObject[] GetObjects()
        {
            List<NativeMethods.WObject> items = new List<NativeMethods.WObject>();

            if(_assemblies == null) {
                throw new Exception("Assemblies not set");
            }

            if(_assemblies.Count == 0 || _pluginIds == null || (_pluginIds != null && _pluginIds.Count == 0)) {
                return null;
            }

            // initialize
            int count = _pluginIds.Count;
            manager = new PluginManager();
            loadedAssemblies = 0;
            stopped = false;

            try {
                Plugin p = null;

                for(int i = 0; i < _pluginIds.Count; i++) {
                    if(stopped) {
                        return null;
                    }

                    try {
                        p = GetPlugin(_pluginIds[i]);

                        if(p != null) {
                            if(p.Instantiated == false) {
                                Debug.ReportWarning("Plugin not instantiated. Plugin: {0}", p.Name);
                                continue;
                            }

                            // load the plugin
                            if(p.PluginObject.Load()) {
                                // set the settings
                                if(_pluginSettings != null) {
                                    if(_pluginSettings.LoadPluginSettings(p) == false) {
                                        Debug.ReportWarning("Failed to load settings. Plugin: {0}", p.Name);
                                        continue;
                                    }
                                }

                                // set the active plugin
                                activePlugin = p.PluginObject;
                                IWipeObject[] obj = activePlugin.GetWipeObjects();
                                activePlugin = null; // plugin no longer needed

                                if(obj == null || obj.Length == 0) {
                                    continue;
                                }

                                // add the objects
                                for(int j = 0; j < obj.Length; j++) {
                                    if(stopped) {
                                        return null;
                                    }

                                    if(obj[i] is PluginWipeObject) {
                                        // skip plugin objects
                                        continue;
                                    }

                                    obj[i].Options = _options;
                                    obj[i].WipeMethodId = _wipeMethodId;

                                    if(obj[i].SingleObject) {
                                        items.Add(obj[i].GetObject());
                                    }
                                    else {
                                        items.AddRange(obj[i].GetObjects());
                                    }
                                }
                            }
                            else {
                                Debug.ReportWarning("Failed to load plugin. Plugin: {0}", p.Name);
                            }
                        }
                    }
                    catch(Exception ex) {
                        // report the exception to the session
                        if(OnPluginException != null) {
                            OnPluginException(p, ex);
                        }
                    }
                }
            }
            catch(Exception e) {
                Debug.ReportError("Exception while running plugins. Exception {0}", e.Message);
            }
            finally {
                // unload the plugins
                manager.DestroyAllPlugins();
            }

            return items.ToArray();
        }
示例#2
0
        private void LoadPlugins()
        {
            loadingEvent.WaitOne();
            loadingEvent.Reset();

            // destroy previously loaded plugins
            if(manager != null) {
                manager.DestroyAllPlugins();
            }
            else {
                manager = new PluginManager();
            }

            // load all libraries from the plugin folder
            string[] files = SecureDeleteLocations.GetPluginAssemblies();
            if(files == null) {
                return;
            }

            foreach(string file in files) {
                if(manager.AddPlugins(file) == false) {
                    Debug.ReportError("Failed to load plugins from file {0}", file);
                }
            }

            PluginList.BeginInvoke(new MethodInvoker(PopulatePluginList));
        }