Ejemplo n.º 1
0
        public void AddPluginItems(PluginContextMenu contextMenu, SelectedItemCollection selection)
        {
            if (_pluginManager == null)
            {
                throw new InvalidOperationException("No plugin manager was specified.");
            }

            bool addedSeparatorBefore = false;

            foreach (PluginDescriptor plugin in _pluginManager.Plugins)
            {
                if (plugin.Enabled)
                {
                    foreach (Feature feature in plugin.Features)
                    {
                        MenuItemFeature menuItemFeature = feature as MenuItemFeature;

                        if (menuItemFeature != null && menuItemFeature.ContextMenu == contextMenu)
                        {
                            if (!addedSeparatorBefore)
                            {
                                AddSeparator();
                                addedSeparatorBefore = true;
                            }

                            Add(menuItemFeature.GetCommand(_mainWindow, selection));
                        }

                        ParentMenuItemFeature parentMenuItemFeature = feature as ParentMenuItemFeature;

                        if (parentMenuItemFeature != null && parentMenuItemFeature.ContextMenu == contextMenu)
                        {
                            CommandToolStripMenuItem parentItem = new CommandToolStripMenuItem(parentMenuItemFeature.GetCommand(_mainWindow, selection));

                            foreach (MenuItemFeature f in parentMenuItemFeature.Features)
                            {
                                parentItem.DropDownItems.Add(new CommandToolStripMenuItem(f.GetCommand(_mainWindow, selection)));
                            }

                            if (!addedSeparatorBefore)
                            {
                                AddSeparator();
                                addedSeparatorBefore = true;
                            }

                            Add(parentItem);
                        }
                    }
                }
            }

            if (addedSeparatorBefore)
            {
                AddSeparator();
            }
        }
Ejemplo n.º 2
0
 public ExternalPluginAction(MenuItemFeature menuItemFeature, IEnumerable <IXenObject> targets, bool XenCenterNodeSelected)
     : base(null,
            string.Format(Messages.EXTERNAL_PLUGIN_TITLE, menuItemFeature.ToString(), menuItemFeature.PluginName),
            string.Format(Messages.EXTERNAL_PLUGIN_RUNNING, menuItemFeature.ToString()), false)
 {
     if (targets != null)
     {
         _targets = new ReadOnlyCollection <IXenObject>(new List <IXenObject>(targets));
         if (_targets.Count == 1)
         {
             Connection = this._targets[0].Connection;
             SetAppliesTo(this._targets[0]);
         }
     }
     XenCenterNodeTarget = XenCenterNodeSelected;
     ShowProgress        = false;
     _menuItemFeature    = menuItemFeature;
 }
Ejemplo n.º 3
0
        public void TestLoadPlugin()
        {
            _batchFile = new ShellCmdTestBatchFile();

            _pluginLoader = new TestPluginLoader("ShellCmdTestPlugin", _pluginManager, _batchFile.Xml);
            _pluginLoader.Load();

            Assert.IsTrue(File.Exists(_batchFile.BatchFile), "test batch file wasn't written");
            Assert.IsFalse(File.Exists(_batchFile.FileThatBatchFileWillWrite), "test file shouldn't exist");

            Assert.AreEqual(1, _pluginManager.Plugins.Count, "No plugins loaded.");
            Assert.AreEqual("ShellCmdTestPlugin", _pluginManager.Plugins[0].Name, "Plugin Name incorrect");
            Assert.AreEqual("plugin-vendor", _pluginManager.Plugins[0].Organization, "Plugin Vendor incorrect");
            Assert.IsTrue(_pluginManager.Enabled, "Plugin manager isn't enabled");
            Assert.IsNull(_pluginManager.Plugins[0].Error, "Error when loading plugin manager");
            Assert.AreEqual(1, _pluginManager.Plugins[0].Features.Count, "MenuItem feature wasn't loaded");

            MenuItemFeature menuItemFeature = (MenuItemFeature)_pluginManager.Plugins[0].Features[0];

            Assert.IsNotNull(menuItemFeature.ShellCmd, "ShellCmd wasn't loaded");
            Assert.AreEqual(menuItemFeature.ShellCmd.Filename, _batchFile.BatchFile, "Batch file name wasn't read from plugin XML");

            // now execute the command and see if the test file is written by the batch file.
            menuItemFeature.GetCommand(new MockMainWindow(), new SelectedItem[] { new SelectedItem((IXenObject)null) }).Execute();

            int  i         = 0;
            bool completed = false;

            while (i < 300)
            {
                if (File.Exists(_batchFile.FileThatBatchFileWillWrite))
                {
                    completed = true;
                    break;
                }

                Thread.Sleep(100);
                i++;
            }

            Assert.IsTrue(completed, "test didn't complete");
        }
Ejemplo n.º 4
0
        public void TestFirstFeatureDetails()
        {
            _pluginManager.Plugins[0].Enabled = true;

            Assert.AreEqual(1, _pluginManager.Plugins.Count, "plugin wasn't loaded");
            Assert.AreEqual(10, _pluginManager.Plugins[0].Features.Count, "features weren't loaded");
            Assert.IsTrue(_pluginManager.Plugins[0].Enabled);

            MenuItemFeature menuItemFeature = (MenuItemFeature)_pluginManager.Plugins[0].Features[0];

            Assert.AreEqual(PluginMenu.file, menuItemFeature.Menu, "file_ShellTest1 plugin heading incorrect.");
            //Assert.IsTrue(menuItemFeature.Enabled, "file_ShellTest1 plugin not enabled.");
            Assert.AreEqual("file_ShellTest1", menuItemFeature.Name, "file_ShellTest1 plugin name incorrect.");
            Assert.AreEqual("the label", menuItemFeature.Label, "file_ShellTest1 plugin label incorrect.");
            Assert.AreEqual("the description", menuItemFeature.Description, "file_ShellTest1 plugin description incorrect.");
            Assert.AreEqual("the tooltip", menuItemFeature.Tooltip, "file_ShellTest1 plugin tooltip incorrect.");
            Assert.AreEqual(pluginName, menuItemFeature.PluginName, "file_ShellTest1 plugin name was incorrect.");
            Assert.IsNull(menuItemFeature.ParentFeature, "file_ShellTest1 shouldn't have parent feature");
            Assert.IsInstanceOf <ShellCmd>(menuItemFeature.ShellCmd, "file_ShellTest1 should have shell cmd.");
        }