示例#1
0
 private bool CanStartHost()
 {
     bool canStartHost = false;
     Program.Invoke(Program.MainWindow, delegate
        {
            var powerOnCommand = new PowerOnHostCommand(Program.MainWindow.CommandInterface, Server);
            canStartHost = powerOnCommand.CanExecute();
        });
     return canStartHost;
 }
示例#2
0
        private void treeView_NodeMouseDoubleClick(object sender, VirtualTreeNodeMouseClickEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
                return;
            if (e.Node == null)
                return;

            IXenConnection conn = e.Node.Tag as IXenConnection;
            if (conn == null)
            {
                var obj = e.Node.Tag as IXenObject;
                if (obj != null)
                    conn = obj.Connection;
            }
            if (conn != null && !conn.IsConnected)
            {
                new ReconnectHostCommand(Program.MainWindow, conn).Execute();
                return;
            }

            VM vm = e.Node.Tag as VM;
            if (vm != null)
            {
                Command cmd = null;

                if (vm.is_a_template)
                {
                    cmd = new NewVMCommand(Program.MainWindow, Program.MainWindow.SelectionManager.Selection);
                }
                else if (vm.power_state == vm_power_state.Halted && vm.allowed_operations.Contains(vm_operations.start))
                {
                    cmd = new StartVMCommand(Program.MainWindow, Program.MainWindow.SelectionManager.Selection);
                }
                else if (vm.power_state == vm_power_state.Suspended && vm.allowed_operations.Contains(vm_operations.resume))
                {
                    cmd = new ResumeVMCommand(Program.MainWindow, Program.MainWindow.SelectionManager.Selection);
                }

                if (cmd != null && cmd.CanExecute())
                {
                    treeView.SelectedNode = e.Node;
                    cmd.Execute();
                }
                return;
            }

            Host host = e.Node.Tag as Host;
            if (host != null)
            {
                Command cmd = new PowerOnHostCommand(Program.MainWindow, host);
                if (cmd.CanExecute())
                {
                    treeView.SelectedNode = e.Node;
                    cmd.Execute();
                }
            }
        }