3
// GNOME Do is the legal property of its developers.
4
// Please refer to the COPYRIGHT file distributed with this
5
// source distribution.
7
// This program is free software: you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation, either version 3 of the License, or
10
// (at your option) any later version.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with this program. If not, see <http://www.gnu.org/licenses/>.
22
using System.Collections.Generic;
23
using System.Diagnostics;
31
private VMState NewState;
34
//complicated constructor if you want to supply everything
35
public VMThread(string o1, string o2, VMState ns, ref VMItem v)
43
//empty constructor, only for complex actions
44
public VMThread(ref VMItem v)
49
//simple constructor, to make things easy
50
public VMThread(VMState ns, ref VMItem v)
55
op2 = "controlvm " + v.Uuid + " ";
56
switch (NewState) //do some action, depending on what the desired NewState is
65
if (v.Status == VMState.paused)
67
else if ((v.Status == VMState.off) || (v.Status == VMState.saved))
68
op2 = "startvm " + v.Uuid + " -type gui";
73
case VMState.headless:
74
if (v.Status == VMState.paused)
76
else if ((v.Status == VMState.off) || (v.Status == VMState.saved))
77
op2 = "startvm " + v.Uuid + " -type vrdp";
82
public void DoAction()
84
vm.Status = VMState.limbo;
85
ProcessStartInfo ps = new ProcessStartInfo (op1, op2);
86
ps.UseShellExecute = false;
87
ps.RedirectStandardOutput = true;
88
using (Process p = Process.Start (ps)) {
95
public void DoShutdownRestoreAction()
97
vm.Status = VMState.limbo;
98
List<ProcessStartInfo> Processes = new List<ProcessStartInfo>();
99
Processes.Add( new ProcessStartInfo ("VBoxManage", "controlvm " + vm.Uuid + " poweroff") );
100
Processes.Add( new ProcessStartInfo ("sleep", "2") );
101
Processes.Add( new ProcessStartInfo ("VBoxManage", "snapshot " + vm.Uuid + " discardcurrent -state") );
103
foreach (ProcessStartInfo ps in Processes)
105
ps.UseShellExecute = false;
106
ps.RedirectStandardOutput = true;
107
using (Process p = Process.Start (ps))
110
vm.Status = VMState.off;