示例#1
0
 private void LoadCorePlugin(IProjectPlugin plugin)
 {
     try {
         plugin.Launch(project);
     }
     catch (Exception ex) {
         MessageBox.Show(ex.Message, Strings.GetString("unknown_error"),
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#2
0
        private void LoadPlugins()
        {
            try {
                string pluginsPath = Path.Combine(Application.StartupPath, "plugins");
                if (!Directory.Exists(pluginsPath))
                {
                    return;
                }

                DirectoryInfo directory = new DirectoryInfo(pluginsPath);

                foreach (FileInfo file in directory.GetFiles("*.dll"))
                {
                    Assembly assembly = Assembly.LoadFile(file.FullName);
                    LoadPlugin(assembly);
                }
            }
            catch (Exception ex) {
                MessageBox.Show(Strings.GetString("error_could_not_load_plugins", ex.Message));
            }

            if (projectPlugins.Count > 0 || diagramPlugins.Count > 0)
            {
                mnuPlugins.Visible = true;

                foreach (IProjectPlugin plugin in projectPlugins)
                {
                    ToolStripMenuItem menu = new ToolStripMenuItem();
                    menu.Text   = plugin.MenuText;
                    menu.Tag    = plugin;
                    menu.Click += new EventHandler(delegate {
                        try {
                            IProjectPlugin taggedPlugin = menu.Tag as IProjectPlugin;
                            if (taggedPlugin != null)
                            {
                                taggedPlugin.Launch(project);
                            }
                        }
                        catch (Exception ex) {
                            MessageBox.Show(ex.Message, Strings.GetString("unknown_error"),
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    });
                    mnuPlugins.DropDownItems.Add(menu);
                }
                foreach (IDiagramPlugin plugin in diagramPlugins)
                {
                    ToolStripMenuItem menu = new ToolStripMenuItem();
                    menu.Text   = plugin.MenuText;
                    menu.Tag    = plugin;
                    menu.Click += new EventHandler(delegate {
                        try {
                            IDiagramPlugin taggedPlugin = menu.Tag as IDiagramPlugin;
                            if (taggedPlugin != null)
                            {
                                taggedPlugin.Launch(diagram);
                            }
                        }
                        catch (Exception ex) {
                            MessageBox.Show(ex.Message, Strings.GetString("unknown_error"),
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    });
                    mnuPlugins.DropDownItems.Add(menu);
                }
            }
        }