/// <summary> /// Returns a Wox.Plugin.Result object corresponding to this machine. /// </summary> /// <param name="machine">The machine to resultify</param> public static Result ToResult(this VirtualBoxApi.IMachine machine) { return(new Result() { Title = machine.Name, SubTitle = machine.State.ToDisplayString(), IcoPath = Main.IconPath, Action = context => { // the machine cannot be launched if it's already online if (machine.Online()) { return false; } var session = new VirtualBoxApi.Session(); var progress = machine.LaunchVMProcess(session, "gui", string.Empty); /* * Although everything appears to work fine if we don't unlock the machine after launching, * the VirtualBox SDK reference (http://download.virtualbox.org/virtualbox/SDKRef.pdf) says * that we must unlock it (see the documentation of IMachine::launchVMProcess()). We do this * asynchronously to keep the Wox UI responsive. */ Task.Run(() => { progress.WaitForCompletion(10000); // 10s if (progress.ResultCode == 0) { session.UnlockMachine(); } }); return true; } }); }
public void Rename(string _old, string _new) { OnEvent("Finalizowanie instalacji", 1); if(Session != null && Session.State == SessionState.SessionState_Locked) Session.UnlockMachine(); Session tmps = new VirtualBox.Session(); try { IMachine mach = vb.FindMachine(_old); Thread.Sleep(1000); mach.LockMachine(tmps, LockType.LockType_Write); tmps.Machine.SaveSettings(); tmps.UnlockMachine(); mach.LockMachine(tmps, LockType.LockType_Write); tmps.Machine.Name = _new; tmps.Machine.SaveSettings(); tmps.UnlockMachine(); } catch (Exception) { //TODO: Remove Devel directory return; } finally { if(tmps.State==SessionState.SessionState_Locked) tmps.UnlockMachine(); } OnEvent("Zakończono instalację", 1); }
private void button3_Click(object sender, EventArgs e) { session.UnlockMachine(); }