/// <summary> /// Initialize VirtualBox COM. /// </summary> /// <param name="servers">Servers to initialize</param> public void Initialize(Dictionary <string, Server> servers) { this.servers = servers; try { vbox = new VirtualBoxClass(); } catch { throw new VirtualBoxServerException("Error while connecting to VirtualBox."); } eventListener = new VirtualBoxEventListener(this); vbox.EventSource.RegisterListener(eventListener, new VBoxEventType[] { VBoxEventType.VBoxEventType_OnMachineStateChanged }, 1); foreach (Server server in servers.Values) { try { machines.Add(server, vbox.FindMachine(server.GetMachine())); } catch { throw new VirtualBoxServerException("Machine '" + server.GetMachine() + "' not found."); } UpdateServerState(server, true); } }
/// <summary> /// Release VirtualBox sever. /// </summary> public void Release() { if (eventListener != null) { try { vbox.EventSource.UnregisterListener(eventListener); } catch (System.Runtime.InteropServices.COMException) { eventListener = null; // Better system shutdown handle... } } }
/// <summary> /// Initialize VirtualBox COM. /// </summary> /// <param name="servers">Servers to initialize</param> public void Initialize(Dictionary<string, Server> servers) { this.servers = servers; try { vbox = new VirtualBoxClass(); } catch { throw new VirtualBoxServerException("Error while connecting to VirtualBox."); } eventListener = new VirtualBoxEventListener(this); vbox.EventSource.RegisterListener(eventListener, new VBoxEventType[] { VBoxEventType.VBoxEventType_OnMachineStateChanged }, 1); foreach (Server server in servers.Values) { try { machines.Add(server, vbox.FindMachine(server.GetMachine())); } catch { throw new VirtualBoxServerException("Machine '" + server.GetMachine() + "' not found."); } UpdateServerState(server, true); } }
/// <summary> /// Initialize VirtualBox COM. /// </summary> /// <param name="runServer">Run server after initialize.</param> public void Initialize(bool runServer) { ClearConsoleHWnd(); try { vbox = new VirtualBoxClass(); } catch { throw new Exception("Error while connecting to VirtualBox."); } try { vboxMachine = vbox.FindMachine(machine); } catch { throw new Exception("Machine '" + machine + "' not found."); } SetState(vboxMachine.State); eventListener = new VirtualBoxEventListener(this); vbox.EventSource.RegisterListener(eventListener, new VBoxEventType[] { VBoxEventType.VBoxEventType_OnMachineStateChanged }, 1); if (runServer && (status == Status.POWEREDOFF)) { StartServer(); } }