コード例 #1
0
        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);
            }
        }
コード例 #2
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)
                {
                    Host host = item.Tag as Host;
                    if (host != null)
                    {
                        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);
                }
            });

            Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection));
        }