예제 #1
0
        /// <summary>
        /// Stop server.
        /// </summary>
        /// <param name="server">Server</param>
        public void StopServer(Server server)
        {
            if (!machines.ContainsKey(server))
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not registered.");
            }

            if (server.GetStatus() == Status.POWEREDOFF)
            {
                return;
            }
            else if (server.GetStatus() != Status.RUNNING)
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not running.");
            }

            IMachine machine       = machines[server];
            Session  serverSession = getSession(server);

            server.SetStoping();

            if (serverSession.State == SessionState.SessionState_Locked)
            {
                serverSession.UnlockMachine();
            }
            machine.LockMachine(serverSession, LockType.LockType_Shared);
            serverSession.Console.PowerButton();
            serverSession.UnlockMachine();
        }
예제 #2
0
        /// <summary>
        /// Start server.
        /// </summary>
        /// <param name="server">Server</param>
        public void StartServer(Server server)
        {
            if (!machines.ContainsKey(server))
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not registered.");
            }

            if (server.GetStatus() == Status.RUNNING)
            {
                return;
            }
            else if (server.GetStatus() != Status.POWEREDOFF)
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not powered off.");
            }

            try
            {
                IMachine machine       = machines[server];
                Session  serverSession = getSession(server);
                DateTime startTime     = DateTime.Now;

                while (machine.SessionState != SessionState.SessionState_Unlocked)
                {
                    long ticks = DateTime.Now.Ticks - startTime.Ticks;

                    if (ticks >= (WAIT_FOR_RESTART_SERVER_SECONDS * 10000000))
                    {
                        break;
                    }
                }

                if (machine.SessionState == SessionState.SessionState_Unlocked)
                {
                    server.SetStarting();

                    IProgress progress = machine.LaunchVMProcess(serverSession, "headless", new string[0]);
                }
            }
            catch
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " can't be run.");
            }
        }
예제 #3
0
        /// <summary>
        /// Update or set server state.
        /// </summary>
        /// <param name="server">Server</param>
        /// <param name="initializing">True if is called while initializing application, false otherwise</param>
        private void UpdateServerState(Server server, bool initializing)
        {
            if (!machines.ContainsKey(server))
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not registered.");
            }

            IMachine machine = machines[server];

            Status newStatus;
            Status oldStatus = server.GetStatus();

            switch (machine.State)
            {
            case MachineState.MachineState_Running:
                newStatus = Status.RUNNING;
                break;

            case MachineState.MachineState_Starting:
            case MachineState.MachineState_Restoring:
                newStatus = Status.STARTING;
                break;

            case MachineState.MachineState_Stopping:
            case MachineState.MachineState_Saving:
                newStatus = Status.STOPING;
                break;

            default:
                newStatus = Status.POWEREDOFF;
                break;
            }

            if (newStatus == oldStatus)
            {
                return;
            }

            server.SetStatus(newStatus, initializing);
        }
예제 #4
0
        /// <summary>
        /// Update or set server state.
        /// </summary>
        /// <param name="server">Server</param>
        /// <param name="initializing">True if is called while initializing application, false otherwise</param>
        private void UpdateServerState(Server server, bool initializing)
        {
            if (!machines.ContainsKey(server))
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not registered.");
            }

            IMachine machine = machines[server];

            Status newStatus;
            Status oldStatus = server.GetStatus();

            switch (machine.State)
            {
                case MachineState.MachineState_Running:
                    newStatus = Status.RUNNING;
                    break;
                case MachineState.MachineState_Starting:
                case MachineState.MachineState_Restoring:
                    newStatus = Status.STARTING;
                    break;
                case MachineState.MachineState_Stopping:
                case MachineState.MachineState_Saving:
                    newStatus = Status.STOPING;
                    break;
                default :
                    newStatus = Status.POWEREDOFF;
                    break;
            }

            if (newStatus == oldStatus)
            {
                return;
            }

            server.SetStatus(newStatus, initializing);
        }
예제 #5
0
        /// <summary>
        /// Stop server.
        /// </summary>
        /// <param name="server">Server</param>
        public void StopServer(Server server)
        {
            if (!machines.ContainsKey(server))
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not registered.");
            }

            if (server.GetStatus() == Status.POWEREDOFF)
            {
                return;
            }
            else if (server.GetStatus() != Status.RUNNING)
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not running.");
            }

            IMachine machine = machines[server];
            Session serverSession = getSession(server);

            server.SetStoping();

            if (serverSession.State == SessionState.SessionState_Locked)
            {
                serverSession.UnlockMachine();
            }
            machine.LockMachine(serverSession, LockType.LockType_Shared);
            serverSession.Console.PowerButton();
            serverSession.UnlockMachine();
        }
예제 #6
0
        /// <summary>
        /// Start server.
        /// </summary>
        /// <param name="server">Server</param>
        public void StartServer(Server server)
        {
            if (!machines.ContainsKey(server))
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not registered.");
            }

            if (server.GetStatus() == Status.RUNNING)
            {
                return;
            }
            else if (server.GetStatus() != Status.POWEREDOFF)
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " is not powered off.");
            }

            try
            {
                IMachine machine = machines[server];
                Session serverSession = getSession(server);
                DateTime startTime = DateTime.Now;

                while (machine.SessionState != SessionState.SessionState_Unlocked)
                {
                    long ticks = DateTime.Now.Ticks - startTime.Ticks;

                    if (ticks >= (WAIT_FOR_RESTART_SERVER_SECONDS * 10000000))
                    {
                        break;
                    }
                }

                if (machine.SessionState == SessionState.SessionState_Unlocked)
                {
                    server.SetStarting();

                    IProgress progress = machine.LaunchVMProcess(serverSession, "headless", "");
                }
            }
            catch
            {
                throw new VirtualBoxServerException("Server " + server.GetName() + " can't be run.");
            }
        }