private void EnableAppropriateHostsNoWlb(Session session)
        {
            SelectedItemCollection selection  = Command.GetSelection();
            IXenConnection         connection = selection[0].Connection;

            VMOperationCommand cmdHome = new VMOperationHomeServerCommand(Command.MainWindowCommandInterface, selection, _operation, session);

            Host affinityHost             = connection.Resolve(((VM)Command.GetSelection()[0].XenObject).affinity);
            VMOperationCommand cpmCmdHome = new CrossPoolMigrateToHomeCommand(Command.MainWindowCommandInterface, selection, affinityHost);

            Program.Invoke(Program.MainWindow, delegate
            {
                var firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0];

                bool oldMigrateToHomeCmdCanRun = cmdHome.CanExecute();
                if (affinityHost == null || _operation == vm_operations.start_on || !oldMigrateToHomeCmdCanRun && !cpmCmdHome.CanExecute())
                {
                    firstItem.Command = cmdHome;
                }
                else
                {
                    firstItem.Command = oldMigrateToHomeCmdCanRun ? cmdHome : cpmCmdHome;
                }
            });

            List <VMOperationToolStripMenuSubItem> dropDownItems = DropDownItems.Cast <VMOperationToolStripMenuSubItem>().ToList();

            // Adds the migrate wizard button, do this before the enable checks on the other items
            Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection));

            foreach (VMOperationToolStripMenuSubItem item in dropDownItems)
            {
                if (_isDropDownClosed)
                {
                    // Stop making requests to assert can start on each host after dropdown is closed
                    break;
                }

                Host host = item.Tag as Host;
                if (host != null)
                {
                    VMOperationCommand      cmd    = new VMOperationHostCommand(Command.MainWindowCommandInterface, selection, delegate { return(host); }, host.Name().EscapeAmpersands(), _operation, session);
                    CrossPoolMigrateCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host, _resumeAfter);

                    VMOperationToolStripMenuSubItem tempItem = item;
                    Program.Invoke(Program.MainWindow, delegate
                    {
                        bool oldMigrateCmdCanRun = cmd.CanExecute();
                        if (_operation == vm_operations.start_on || (!oldMigrateCmdCanRun && !cpmCmd.CanExecute() && string.IsNullOrEmpty(cpmCmd.CantExecuteReason)))
                        {
                            tempItem.Command = cmd;
                        }
                        else
                        {
                            tempItem.Command = oldMigrateCmdCanRun ? cmd : cpmCmd;
                        }
                    });
                }
            }
        }
        private void EnableAppropriateHostsNoWlb(Session session)
        {
            SelectedItemCollection selection  = Command.GetSelection();
            IXenConnection         connection = selection[0].Connection;

            VMOperationCommand cmdHome = new VMOperationHomeServerCommand(Command.MainWindowCommandInterface, selection, _operation, session);

            Host affinityHost             = connection.Resolve(((VM)Command.GetSelection()[0].XenObject).affinity);
            VMOperationCommand cpmCmdHome = new CrossPoolMigrateToHomeCommand(Command.MainWindowCommandInterface, selection, affinityHost);

            Program.Invoke(Program.MainWindow, delegate
            {
                var firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0];

                bool oldMigrateToHomeCmdCanRun = cmdHome.CanExecute();
                if (affinityHost == null || _operation == vm_operations.start_on || !oldMigrateToHomeCmdCanRun && !cpmCmdHome.CanExecute())
                {
                    firstItem.Command = cmdHome;
                }
                else
                {
                    firstItem.Command = oldMigrateToHomeCmdCanRun ? cmdHome : cpmCmdHome;
                }
            });

            List <VMOperationToolStripMenuSubItem> dropDownItems = DropDownItems.Cast <VMOperationToolStripMenuSubItem>().ToList();

            foreach (VMOperationToolStripMenuSubItem item in dropDownItems)
            {
                if (item.Tag is Host)
                {
                    Host host = (Host)item.Tag;

                    string hostNameText = host.Name.EscapeAmpersands();

                    VMOperationCommand cmd    = new VMOperationHostCommand(Command.MainWindowCommandInterface, selection, delegate { return(host); }, hostNameText, _operation, session);
                    VMOperationCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host)
                    {
                        MenuText = hostNameText
                    };

                    VMOperationToolStripMenuSubItem tempItem = item;
                    Program.Invoke(Program.MainWindow, delegate
                    {
                        bool oldMigrateCmdCanRun = cmd.CanExecute();
                        if (_operation == vm_operations.start_on || !oldMigrateCmdCanRun && !cpmCmd.CanExecute())
                        {
                            tempItem.Command = cmd;
                        }
                        else
                        {
                            tempItem.Command = oldMigrateCmdCanRun ? cmd : cpmCmd;
                        }
                    });
                }
            }

            Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection));
        }
        protected override void OnDropDownOpening(EventArgs e)
        {
            base.DropDownItems.Clear();
            _isDropDownClosed = false;

            // Work around bug in tool kit where disabled menu items show their dropdown menus
            if (!Enabled)
            {
                ToolStripMenuItem emptyMenuItem = new ToolStripMenuItem(Messages.HOST_MENU_EMPTY);
                emptyMenuItem.Font    = Program.DefaultFont;
                emptyMenuItem.Enabled = false;
                base.DropDownItems.Add(emptyMenuItem);
                return;
            }

            VisualMenuItemAlignData.ParentStrip = this;
            IXenConnection connection = Command.GetSelection()[0].Connection;
            bool           wlb        = Helpers.WlbEnabled(connection);

            if (wlb)
            {
                base.DropDownItems.Add(new VMOperationToolStripMenuSubItem(Messages.WLB_OPT_MENU_OPTIMAL_SERVER, Images.StaticImages._000_ServerWlb_h32bit_16));
            }
            else
            {
                base.DropDownItems.Add(new VMOperationToolStripMenuSubItem(Messages.HOME_SERVER_MENU_ITEM, Images.StaticImages._000_ServerHome_h32bit_16));
            }

            List <Host> hosts = new List <Host>(connection.Cache.Hosts);

            hosts.Sort();
            foreach (Host host in hosts)
            {
                VMOperationToolStripMenuSubItem item = new VMOperationToolStripMenuSubItem(String.Format(Messages.MAINWINDOW_CONTEXT_UPDATING, host.name_label.EscapeAmpersands()), Images.StaticImages._000_ServerDisconnected_h32bit_16);
                item.Tag = host;
                base.DropDownItems.Add(item);
            }

            // start a new thread to evaluate which hosts can be used.
            ThreadPool.QueueUserWorkItem(delegate
            {
                SelectedItemCollection selection = Command.GetSelection();
                Session session = selection[0].Connection.DuplicateSession();
                WlbRecommendations recommendations = new WlbRecommendations(selection.AsXenObjects <VM>(), session);
                recommendations.Initialize();

                if (recommendations.IsError)
                {
                    EnableAppropriateHostsNoWlb(session);
                }
                else
                {
                    EnableAppropriateHostsWlb(session, recommendations);
                }
            });
        }
Ejemplo n.º 4
0
 protected override void AddAdditionalMenuItems(SelectedItemCollection selection)
 {
     if (selection.ToList().All(item => !Helpers.CrossPoolMigrationRestrictedWithWlb(item.Connection)))
     {
         VMOperationCommand cmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection);
         DropDownItems.Add(new ToolStripSeparator());
         VMOperationToolStripMenuSubItem lastItem = new VMOperationToolStripMenuSubItem(cmd);
         DropDownItems.Add(lastItem);
     }
 }
Ejemplo n.º 5
0
 protected override void AddAdditionalMenuItems(SelectedItemCollection selection)
 {
     if (selection.ToList().All(item => Helpers.TampaOrGreater(item.Connection) && !Helpers.CrossPoolMigrationRestrictedWithWlb(item.Connection)))
     {
         VMOperationCommand cmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection);
         DropDownItems.Add(new ToolStripSeparator());
         VMOperationToolStripMenuSubItem lastItem = new VMOperationToolStripMenuSubItem(cmd);
         DropDownItems.Add(lastItem); 
     }            
 }
        private void EnableAppropriateHostsWlb(Session session, WlbRecommendations recommendations)
        {
            SelectedItemCollection selection = Command.GetSelection();
            // set the first menu item to be the WLB optimal server menu item
            VMOperationToolStripMenuSubItem firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0];
            var firstItemCmd           = new VMOperationWlbOptimalServerCommand(Command.MainWindowCommandInterface, selection, _operation, recommendations);
            var firstItemCmdCanExecute = firstItemCmd.CanExecute();

            Program.Invoke(Program.MainWindow, delegate
            {
                firstItem.Command = firstItemCmd;
                firstItem.Enabled = firstItemCmdCanExecute;
            });

            List <VMOperationToolStripMenuSubItem> hostMenuItems = new List <VMOperationToolStripMenuSubItem>();

            foreach (VMOperationToolStripMenuSubItem item in base.DropDownItems)
            {
                Host host = item.Tag as Host;
                if (host != null)
                {
                    var cmd        = new VMOperationWlbHostCommand(Command.MainWindowCommandInterface, selection, host, _operation, recommendations.GetStarRating(host));
                    var canExecute = cmd.CanExecute();

                    Program.Invoke(Program.MainWindow, delegate
                    {
                        item.Command = cmd;
                        item.Enabled = canExecute;
                    });
                    hostMenuItems.Add(item);
                }
            }

            // Shuffle the list to make it look cool
            // Helpers.ShuffleList(hostMenuItems);

            // sort the hostMenuItems by star rating
            hostMenuItems.Sort(new WlbHostStarCompare());

            // refresh the drop-down-items from the menuItems.
            foreach (VMOperationToolStripMenuSubItem menuItem in hostMenuItems)
            {
                Program.Invoke(Program.MainWindow, delegate()
                {
                    base.DropDownItems.Insert(hostMenuItems.IndexOf(menuItem) + 1, menuItem);
                });
            }

            Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection));
        }
        private void EnableAppropriateHostsNoWlb(Session session)
        {
            SelectedItemCollection selection  = Command.GetSelection();
            IXenConnection         connection = selection[0].Connection;
            VMOperationCommand     commandForFirstMenuItem = new VMOperationHomeServerCommand(Command.MainWindowCommandInterface, selection, _operation, session);

            Program.Invoke(Program.MainWindow, delegate
            {
                VMOperationToolStripMenuSubItem firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0];
                firstItem.Command = commandForFirstMenuItem;
            });

            List <VMOperationToolStripMenuSubItem> dropDownItems = DropDownItems.Cast <VMOperationToolStripMenuSubItem>().ToList();

            foreach (VMOperationToolStripMenuSubItem item in dropDownItems)
            {
                if (item.Tag is Host)
                {
                    Host host = (Host)item.Tag;

                    VMOperationCommand cmd    = new VMOperationHostCommand(Command.MainWindowCommandInterface, selection, delegate { return(host); }, host.Name.EscapeAmpersands(), _operation, session);
                    VMOperationCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host)
                    {
                        MenuText = host.Name.EscapeAmpersands()
                    };

                    VMOperationToolStripMenuSubItem tempItem = item;
                    Program.Invoke(Program.MainWindow, delegate
                    {
                        bool oldMigrateCmdCanRun = cmd.CanExecute();
                        if (!oldMigrateCmdCanRun && !cpmCmd.CanExecute())
                        {
                            tempItem.Command = cmd;
                        }
                        else
                        {
                            tempItem.Command = oldMigrateCmdCanRun ? cmd : cpmCmd;
                        }
                    });
                }
            }

            Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection));
        }
        protected override void OnDropDownOpening(EventArgs e)
        {
            base.DropDownItems.Clear();

            // Work around bug in tool kit where disabled menu items show their dropdown menus
            if (!Enabled)
            {
                ToolStripMenuItem emptyMenuItem = new ToolStripMenuItem(Messages.HOST_MENU_EMPTY);
                emptyMenuItem.Font    = Program.DefaultFont;
                emptyMenuItem.Enabled = false;
                base.DropDownItems.Add(emptyMenuItem);
                return;
            }

            VisualMenuItemAlignData.ParentStrip = this;
            var            selection  = Command.GetSelection();
            IXenConnection connection = selection[0].Connection;
            bool           wlb        = Helpers.WlbEnabled(connection);

            if (wlb)
            {
                base.DropDownItems.Add(new VMOperationToolStripMenuSubItem(Messages.WLB_OPT_MENU_OPTIMAL_SERVER, Images.StaticImages._000_ServerWlb_h32bit_16));
            }
            else
            {
                base.DropDownItems.Add(new VMOperationToolStripMenuSubItem(Messages.HOME_SERVER_MENU_ITEM, Images.StaticImages._000_ServerHome_h32bit_16));
            }

            List <Host> hosts = new List <Host>(connection.Cache.Hosts);

            hosts.Sort();
            foreach (Host host in hosts)
            {
                VMOperationToolStripMenuSubItem item = new VMOperationToolStripMenuSubItem(String.Format(Messages.MAINWINDOW_CONTEXT_UPDATING, host.name_label.EscapeAmpersands()), Images.StaticImages._000_ServerDisconnected_h32bit_16);
                item.Tag = host;
                base.DropDownItems.Add(item);
            }

            // Adds the migrate wizard button, do this before the enable checks on the other items
            AddAdditionalMenuItems(selection);

            UpdateHostList();
        }
Ejemplo n.º 9
0
        private void EnableAppropriateHostsWlb(Session session, WlbRecommendations recommendations)
        {
            SelectedItemCollection selection = Command.GetSelection();

            // set the first menu item to be the WLB optimal server menu item
            Program.Invoke(Program.MainWindow, delegate
            {
                VMOperationToolStripMenuSubItem firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0];
                firstItem.Command = new VMOperationWlbOptimalServerCommand(Command.MainWindowCommandInterface, selection, _operation, recommendations);
            });

            List <VMOperationToolStripMenuSubItem> hostMenuItems = new List <VMOperationToolStripMenuSubItem>();

            Program.Invoke(Program.MainWindow, delegate
            {
                foreach (VMOperationToolStripMenuSubItem item in base.DropDownItems)
                {
                    if (item.Tag is Host)
                    {
                        Host host    = (Host)item.Tag;
                        item.Command = new VMOperationWlbHostCommand(Command.MainWindowCommandInterface, selection, host, _operation, recommendations.GetStarRating(host));
                        hostMenuItems.Add(item);
                    }
                }
            });

            // Shuffle the list to make it look cool
            Helpers.ShuffleList(hostMenuItems);

            // sort the hostMenuItems by star rating
            hostMenuItems.Sort(new WlbHostStarCompare());

            // refresh the drop-down-items from the menuItems.
            Program.Invoke(Program.MainWindow, delegate()
            {
                foreach (VMOperationToolStripMenuSubItem menuItem in hostMenuItems)
                {
                    base.DropDownItems.Insert(hostMenuItems.IndexOf(menuItem) + 1, menuItem);
                }
            });
        }
Ejemplo n.º 10
0
        private void EnqueueHostMenuItem(VMOperationToolStripMenuItem menu, Session session, Host host, VMOperationToolStripMenuSubItem hostMenuItem, bool isHomeServer)
        {
            workerQueueWithoutWlb.EnqueueItem(() =>
            {
                var selection = menu.Command.GetSelection();
                var cmd       = isHomeServer
                    ? new VMOperationHomeServerCommand(menu.Command.MainWindowCommandInterface, selection, menu._operation, session)
                    : new VMOperationHostCommand(menu.Command.MainWindowCommandInterface, selection, delegate { return(host); }, host.Name().EscapeAmpersands(), menu._operation, session);

                var oldMigrateCmdCanRun = cmd.CanExecute();
                if (Stopped)
                {
                    return;
                }

                if (host == null || menu._operation == vm_operations.start_on || oldMigrateCmdCanRun)
                {
                    Program.Invoke(Program.MainWindow, delegate
                    {
                        hostMenuItem.Command = cmd;
                        hostMenuItem.Enabled = oldMigrateCmdCanRun;
                    });
                }
                else
                {
                    var cpmCmd = isHomeServer
                        ? new CrossPoolMigrateToHomeCommand(menu.Command.MainWindowCommandInterface, selection, host)
                        : new CrossPoolMigrateCommand(menu.Command.MainWindowCommandInterface, selection, host, menu._resumeAfter);

                    var crossPoolMigrateCmdCanRun = cpmCmd.CanExecute();
                    if (Stopped)
                    {
                        return;
                    }

                    Program.Invoke(Program.MainWindow, delegate
                    {
                        if (crossPoolMigrateCmdCanRun || !string.IsNullOrEmpty(cpmCmd.CantExecuteReason))
                        {
                            hostMenuItem.Command = cpmCmd;
                            hostMenuItem.Enabled = crossPoolMigrateCmdCanRun;
                        }
                        else
                        {
                            hostMenuItem.Command = cmd;
                            hostMenuItem.Enabled = false;
                        }
                    });
                }
            });
        }
        private void EnableAppropriateHostsNoWlb(Session session)
        {
            SelectedItemCollection selection  = Command.GetSelection();
            IXenConnection         connection = selection[0].Connection;

            VMOperationCommand cmdHome = new VMOperationHomeServerCommand(Command.MainWindowCommandInterface, selection, _operation, session);
            Host affinityHost          = connection.Resolve(((VM)Command.GetSelection()[0].XenObject).affinity);

            Program.Invoke(Program.MainWindow, delegate
            {
                var firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0];

                bool oldMigrateToHomeCmdCanRun = cmdHome.CanExecute();
                if (affinityHost == null || _operation == vm_operations.start_on || oldMigrateToHomeCmdCanRun)
                {
                    firstItem.Command = cmdHome;
                    firstItem.Enabled = oldMigrateToHomeCmdCanRun;
                }
                else
                {
                    VMOperationCommand cpmCmdHome = new CrossPoolMigrateToHomeCommand(Command.MainWindowCommandInterface, selection, affinityHost);

                    if (cpmCmdHome.CanExecute())
                    {
                        firstItem.Command = cpmCmdHome;
                        firstItem.Enabled = true;
                    }
                    else
                    {
                        firstItem.Command = cmdHome;
                        firstItem.Enabled = false;
                    }
                }
            });

            List <VMOperationToolStripMenuSubItem> dropDownItems = DropDownItems.Cast <VMOperationToolStripMenuSubItem>().ToList();

            // Adds the migrate wizard button, do this before the enable checks on the other items
            Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection));

            foreach (VMOperationToolStripMenuSubItem item in dropDownItems)
            {
                if (_isDropDownClosed)
                {
                    // Stop making requests to assert can start on each host after dropdown is closed
                    break;
                }

                Host host = item.Tag as Host;
                if (host != null)
                {
                    // API calls could happen in CanExecute(), which take time to wait.
                    // So a Producer-Consumer-Queue with size 25 is used here to :
                    //   1. Make API calls for different menu items happen in parallel;
                    //   2. Limit the count of concurrent threads (now it's 25).
                    workerQueueWithouWlb.EnqueueItem(() =>
                    {
                        if (_isDropDownClosed)
                        {
                            return;
                        }
                        VMOperationCommand cmd         = new VMOperationHostCommand(Command.MainWindowCommandInterface, selection, delegate { return(host); }, host.Name().EscapeAmpersands(), _operation, session);
                        CrossPoolMigrateCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host, _resumeAfter);

                        VMOperationToolStripMenuSubItem tempItem = item;
                        bool oldMigrateCmdCanRun = cmd.CanExecute();
                        if ((_operation == vm_operations.start_on) || oldMigrateCmdCanRun)
                        {
                            Program.Invoke(Program.MainWindow, delegate
                            {
                                tempItem.Command = cmd;
                                tempItem.Enabled = oldMigrateCmdCanRun;
                            });
                        }
                        else
                        {
                            bool crossPoolMigrateCmdCanRun = cpmCmd.CanExecute();
                            if (crossPoolMigrateCmdCanRun || !string.IsNullOrEmpty(cpmCmd.CantExecuteReason))
                            {
                                Program.Invoke(Program.MainWindow, delegate
                                {
                                    tempItem.Command = cpmCmd;
                                    tempItem.Enabled = crossPoolMigrateCmdCanRun;
                                });
                            }
                            else
                            {
                                Program.Invoke(Program.MainWindow, delegate
                                {
                                    tempItem.Command = cmd;
                                    tempItem.Enabled = oldMigrateCmdCanRun;
                                });
                            }
                        }
                    });
                }
            }
        }