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;
34
private VMState NewState;
37
//complicated constructor if you want to supply everything
38
public VMThread(string o1, string o2, VMState ns, ref VMItem v)
46
//empty constructor, only for complex actions
47
public VMThread(ref VMItem v)
52
//simple constructor, to make things easy
53
public VMThread(VMState ns, ref VMItem v)
58
op2 = "controlvm " + v.Uuid + " ";
59
switch (NewState) //do some action, depending on what the desired NewState is
68
if (v.Status == VMState.paused)
70
else if ((v.Status == VMState.off) || (v.Status == VMState.saved))
71
op2 = "startvm " + v.Uuid + " -type gui";
76
case VMState.headless:
77
if (v.Status == VMState.paused)
79
else if ((v.Status == VMState.off) || (v.Status == VMState.saved))
80
op2 = "startvm " + v.Uuid + " -type vrdp";
85
public void DoAction()
91
Log.Error("State mismatch for {0}.", vm.Name);
94
vm.Status = VMState.limbo;
95
ProcessStartInfo ps = new ProcessStartInfo (op1, op2);
96
ps.UseShellExecute = false;
97
ps.RedirectStandardOutput = true;
98
using (Process p = Process.Start (ps)) {
99
Log.Info("Execution thread for {0} started.", vm.Name);
103
vm.Status = NewState;
104
Log.Info("Execution thread for {0} finished.", vm.Name);
110
Log.Fatal("Something horrible happened to {0}.", vm.Name);
114
public void DoShutdownRestoreAction()
120
Log.Error("State mismatch for {0}", vm.Name);
123
vm.Status = VMState.limbo;
124
List<ProcessStartInfo> Processes = new List<ProcessStartInfo>();
125
Processes.Add( new ProcessStartInfo ("VBoxManage", "controlvm " + vm.Uuid + " poweroff") );
126
Processes.Add( new ProcessStartInfo ("sleep", "2") );
127
Processes.Add( new ProcessStartInfo ("VBoxManage", "snapshot " + vm.Uuid + " discardcurrent -state") );
129
Log.Info("Execution thread for {0} started.", vm.Name);
130
foreach (ProcessStartInfo ps in Processes)
132
ps.UseShellExecute = false;
133
ps.RedirectStandardOutput = true;
134
using (Process p = Process.Start (ps))
137
Log.Info("Execution thread for {0} finished.", vm.Name);
138
vm.Status = VMState.off;
142
Log.Fatal("Something horrible happened to {0}.", vm.Name);
146
public bool CheckState()
148
return (vm.Status == vm.CurrentState) ? true : false;