Beispiel #1
0
        private void pluginsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            PluginInstance plugInfo = (PluginInstance)plugins[pluginToCombo[pluginsComboBox.SelectedIndex]];

            authorLabel.Text  = plugInfo.Instance.PlugAuthor;
            versionLabel.Text = plugInfo.Instance.PlugVersion;
            descLabel.Text    = plugInfo.Instance.PlugDescription;

            pluginOptionsButton.Enabled = plugInfo.Instance.IsOptionsFormPresent;

            if (plugInfo.Instance.HasIcon)
            {
                pluginImagePictureBox.Image = plugInfo.Instance.PlugImage;
            }
            else
            {
                pluginImagePictureBox.Image = null;
            }

            if (plugInfo.Instance.PlugOptions["EnabledPlugin"] != null)
            {
                enabledPluginCheckBox.Checked = bool.Parse(plugInfo.Instance.PlugOptions["EnabledPlugin"]);
            }
            else
            {
                enabledPluginCheckBox.Checked = true;
            }
        }
Beispiel #2
0
        private void pluginOptionsButton_Click(object sender, EventArgs e)
        {
            PluginInstance pluginOptForm = (PluginInstance)plugins[pluginToCombo[pluginsComboBox.SelectedIndex]];

            Form optionForm = pluginOptForm.Instance.OptionsForm;

            optionForm.Show();
        }
Beispiel #3
0
        public void RemovePlugins()
        {
            foreach (int pluginID in colPlugins.Keys)
            {
                PluginInstance plugin = (PluginInstance)colPlugins[pluginID];

                plugin.Instance.Unload();
                WritePluginOptions(plugin.Instance);
                plugin.Instance = null;
            }

            colPlugins.Clear();
            formatRegistered.Clear();
        }
Beispiel #4
0
        public void RemovePlugin(int pluginID)
        {
            PluginInstance plugin = (PluginInstance)colPlugins[pluginID];

            if (plugin != null)
            {
                UnloadPluginFormats(plugin.Instance);

                plugin.Instance.Unload();
                WritePluginOptions(plugin.Instance);
                plugin.Instance = null;

                colPlugins.Remove(pluginID);
            }
        }
Beispiel #5
0
        private void pluginAboutButton_Click(object sender, EventArgs e)
        {
            PluginInstance plugAboutForm = (PluginInstance)plugins[pluginToCombo[pluginsComboBox.SelectedIndex]];

            if (plugAboutForm.Instance.IsAboutFormPresent)
            {
                Form aboutForm = plugAboutForm.Instance.AboutForm;
                aboutForm.Show();
            }
            else
            {
                MessageBox.Show("Author: " + plugAboutForm.Instance.PlugAuthor + "\nVersion: " + plugAboutForm.Instance.PlugVersion +
                                "\nDescription: " + plugAboutForm.Instance.PlugDescription, plugAboutForm.Instance.PlugName,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Beispiel #6
0
        private void SendToPluginsAsFormat(object iData, string DataFormat)
        {
            ArrayList registeredPlugins = (ArrayList)plugins.FormatRegisteredPlugins[DataFormat];

            if (registeredPlugins != null)
            {
                foreach (int pluginID in registeredPlugins)
                {
                    PluginInstance selectedPlugin = (PluginInstance)plugins.LoadedPlugins[pluginID];

                    if ((selectedPlugin != null) && (selectedPlugin.Enabled))
                    {
                        new Thread(new ParameterizedThreadStart(selectedPlugin.Instance.Execute)).Start(iData);
                    }
                }
            }
        }
Beispiel #7
0
        public void LoadPlugin(string fileName)
        {
            Assembly pluginAssembly = Assembly.LoadFrom(fileName);

            foreach (Type pluginType in pluginAssembly.GetTypes())
            {
                if (pluginType.IsPublic)
                {
                    if (!pluginType.IsAbstract)
                    {
                        Type typeInterface = pluginType.GetInterface("PluginInterface.IPlugin", true);

                        if (typeInterface != null)
                        {
                            PluginInstance newPlugin = new PluginInstance();

                            int newPluginID = fileName.GetHashCode();

                            if (newPluginID < 0)
                            {
                                newPluginID *= -1;
                            }

                            newPlugin.Instance        = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                            newPlugin.Instance.Host   = this;
                            newPlugin.Instance.PlugID = newPluginID;

                            NameValueCollection pluginOption = (NameValueCollection)nvPluginConfig[newPluginID];

                            if ((pluginOption != null) && (pluginOption.Count != 0))
                            {
                                newPlugin.Instance.PlugOptions = pluginOption;
                            }

                            if ((pluginOption != null) && (pluginOption["EnabledPlugin"] != null))
                            {
                                try {
                                    newPlugin.Enabled = bool.Parse(pluginOption["EnabledPlugin"]);
                                }
                                catch (FormatException fe) {
                                    MessageBox.Show("Error parsing the configuration file.\n" + fe.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    newPlugin.Enabled = true;
                                }
                            }
                            else
                            {
                                newPlugin.Enabled = true;
                            }

                            newPlugin.Instance.Init();

                            if (colPlugins[newPluginID] == null)
                            {
                                LoadPluginFormats(newPlugin.Instance);
                                WritePluginOptions(newPlugin.Instance);
                                colPlugins.Add(newPluginID, newPlugin);
                            }
                        }
                    }
                }
            }
        }