Wrapper for a IPlugin interface derived object. Provides support for instantiating the plugin.
コード例 #1
0
        /// <summary>
        /// Save the settings
        /// </summary>
        /// <param name="plugin">The plugin for which to save the settings.</param>
        public void SavePluginSettings(Plugin plugin)
        {
            // check the parameters
            Debug.AssertNotNull(plugin, "Plugin is null");
            Debug.Assert(plugin.Instantiated, "Cannot save data for uninstantiated plugin");

            StoreId id = CreateStoreId(plugin);
            StoreItem item;
            bool alreadyAdded = false;

            // check if the plugin is already added to the category
            if(settings.ContainsKey(id)) {
                item = settings[id];
                alreadyAdded = true;
            }
            else {
                item = new StoreItem();
                item.id = id;
            }

            // get the settings
            try {
                item.data = plugin.PluginObject.SaveSettings();
            }
            catch(Exception e) {
                Debug.ReportWarning("Failed to save settings for plugin {0}. Exception: {1}", id, e.Message);
                return;
            }

            if(item.data != null && item.data.Length > 0) {
                if(alreadyAdded == false) {
                    settings.Add(id, item);
                }
                else {
                    settings[id] = item;
                }
            }

            // save the settings to the file
            if(_settingsFile != null) {
                SaveSettings();
            }
        }
コード例 #2
0
        /// <summary>
        /// Load the settings
        /// </summary>
        /// <param name="plugin">The plugin for which to load the settings.</param>
        public bool LoadPluginSettings(Plugin plugin)
        {
            // check the parameters
            Debug.AssertNotNull(plugin, "Plugin is null");
            Debug.Assert(plugin.Instantiated, "Cannot load data for uninstantiated plugin");

            // check if the plugin is in the category
            StoreId id = CreateStoreId(plugin);

            if(settings.ContainsKey(id)) {
                StoreItem item = settings[id];

                // load the settings
                if(item.data != null && item.data.Length > 0) {
                    bool result = false;

                    try {
                        result = plugin.PluginObject.LoadSettings(item.data);
                        return true;
                    }
                    catch(Exception e) {
                        Debug.ReportWarning("Failed to load settings for plugin {0}. Exception: {1}", id, e.Message);
                        result = false;
                    }

                    return result;
                }
            }

            return true;
        }
コード例 #3
0
        /// <summary>
        /// Remove the settings
        /// </summary>
        /// <param name="plugin">The plugin for which to remove the settings.</param>
        public bool RemovePluginSettings(Plugin plugin)
        {
            // check the parameters
            Debug.AssertNotNull(plugin, "Plugin is null");
            Debug.Assert(plugin.Instantiated, "Cannot remove data for uninstantiated plugin");

            // check if the plugin is in the category
            StoreId id = CreateStoreId(plugin);

            if(settings.ContainsKey(id)) {
                settings.Remove(id);

                // save the settings to the file
                if(_autoSave != AutoSaveMethod.None && _settingsFile != null) {
                    SaveSettings();
                }
            }

            return false;
        }
コード例 #4
0
ファイル: PluginTool.cs プロジェクト: gratianlup/SecureDelete
        private void ShowPluginErrorDialog(Plugin plugin, Exception e)
        {
            PluginError errorDialog = new PluginError();
            errorDialog.Plugin = plugin;
            errorDialog.Exception = e;

            errorDialog.ShowDialog();
        }
コード例 #5
0
 public static StoreId CreateStoreId(Plugin plugin)
 {
     StoreId id = new StoreId();
     id.id = plugin.Id;
     id.name = plugin.Name;
     id.majorVersion = plugin.HasMajorVersion ? plugin.MajorVersion : int.MaxValue;
     id.minorVersion = plugin.HasMinorVersion ? plugin.MinorVersion : int.MaxValue;
     return id;
 }
コード例 #6
0
ファイル: PluginTool.cs プロジェクト: gratianlup/SecureDelete
 private void SavePluginSettings(Plugin p)
 {
     _plugin.PluginSettings.SavePluginSettings(p);
 }
コード例 #7
0
ファイル: PluginTool.cs プロジェクト: gratianlup/SecureDelete
        private void PluginList_SelectedIndexChanged(object sender, EventArgs e)
        {
            try {
                if(PluginList.SelectedIndices.Count == 0) {
                    return;
                }

                Plugin p = GetPlugin(PluginList.SelectedItems[0].Text, (Guid)PluginList.SelectedItems[0].Tag);
                activePlugin = p;

                if(p == null) {
                    return;
                }

                NameLabel.Text = p.Name;
                VersionLabel.Text = p.VersionString;
                AuthorLabel.Text = p.Author;
                DescriptionTextbox.Text = p.Description;
                OptionsButton.Enabled = p.PluginObject.HasOptionsDialog;
                activePlugin = p;

                // load icon
                if(p.PluginObject.HasIcon) {
                    object iconObject = p.PluginObject.GetIcon();

                    if(iconObject == null) {
                        Debug.ReportWarning("No icon object returned. Plugin :{0}", activePlugin);
                        return;
                    }

                    if(iconObject is Icon) {
                        PluginIcon.Image = ((Icon)iconObject).ToBitmap();
                    }
                    else if(iconObject is Image) {
                        PluginIcon.Image = (Image)iconObject;
                    }
                    else {
                        // invalid format
                        Debug.ReportWarning("Invalid icon format. Plugin: {0}", activePlugin);
                        return;
                    }
                }
                else {
                    PluginIcon.Image = PluginIcon.ErrorImage;
                }

                // show panel
                splitContainer1.Panel2Collapsed = !toolStripButton1.Checked;
            }
            catch(Exception ex) {
                Debug.ReportError("Exception {0} in plugin {1}", ex.Message, activePlugin);

                if(activePlugin != null) {
                    ShowPluginErrorDialog(activePlugin, ex);
                }
            }
        }
コード例 #8
0
ファイル: PluginTool.cs プロジェクト: gratianlup/SecureDelete
        public void DisposeTool()
        {
            if(manager != null) {
                manager.DestroyAllPlugins();
            }

            activePlugin = null;
        }
コード例 #9
0
        private void ReportPluginError(Plugin plugin, Exception e)
        {
            if(plugin == null) {
                return;
            }

            _beforeWipeErrors.Add(new WipeError(DateTime.Now, ErrorSeverity.High,
                                                string.Format("Critical error occured in plugin {0}", plugin)));
        }
コード例 #10
0
        /// <summary>
        /// Load and instantiate all plugins found in the given assembly
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        public static Plugin[] LoadPluginsFromAssembly(Assembly assembly)
        {
            Debug.AssertNotNull(assembly, "Assembly is null");
            List<Plugin> plugins = new List<Plugin>();

            try {
                foreach(Type type in assembly.GetTypes()) {
                    if(type.IsAbstract == true || typeof(IPlugin).IsAssignableFrom(type) == false) {
                        continue;
                    }

                    // check if it has a plugin _attribute
                    if(type.GetCustomAttributes(typeof(PluginAttribute), false) != null) {
                        Plugin plugin = new Plugin(type);

                        if(plugin.CreateInstance()) {
                            // add the _plugin
                            plugins.Add(plugin);
                        }
                        else {
                            Debug.ReportWarning("Couldn't create plugin instance");
                        }
                    }
                }
            }
            catch(Exception e) {
                Debug.ReportError("Failed to load plugin types from assembly {0}. Exception: {1}", assembly, e.Message);
            }

            return plugins.ToArray();
        }