private void EnableAppropriateHostsWlb(WlbRecommendations recommendations)
        {
            if (Stopped || DropDownItems.Count == 0)
            {
                return;
            }

            // set the first menu item to be the WLB optimal server menu item
            var firstItem = DropDownItems[0] as VMOperationToolStripMenuSubItem;

            if (firstItem == null)
            {
                return;
            }

            var selection = Command.GetSelection();

            var firstItemCmd = new VMOperationWlbOptimalServerCommand(Command.MainWindowCommandInterface,
                                                                      selection, _operation, recommendations);

            firstItem.Command = firstItemCmd;
            firstItem.Enabled = firstItemCmd.CanExecute();

            var hostMenuItems = new List <VMOperationToolStripMenuSubItem>();

            foreach (var item in DropDownItems)
            {
                var hostMenuItem = item as VMOperationToolStripMenuSubItem;
                if (hostMenuItem == null)
                {
                    continue;
                }

                var host = hostMenuItem.Tag as Host;
                if (host != null)
                {
                    var cmd = new VMOperationWlbHostCommand(Command.MainWindowCommandInterface, selection, host,
                                                            _operation, recommendations.GetStarRating(host));

                    hostMenuItem.Command = cmd;
                    hostMenuItem.Enabled = cmd.CanExecute();

                    hostMenuItems.Add(hostMenuItem);
                }
            }

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

            // refresh the drop-down-items from the menuItems.
            foreach (VMOperationToolStripMenuSubItem menuItem in hostMenuItems)
            {
                DropDownItems.Insert(hostMenuItems.IndexOf(menuItem) + 1, menuItem);
            }
        }
        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));
        }