Exemple #1
0
        public MyApplicationContext()
        {
            vbox = new VirtualBox.VirtualBox();

            components = new Container();
            InitializeComponent();
        }
Exemple #2
0
    private Virtualtray()
    {
        _virtualbox = (IVirtualBox) new VirtualBox.VirtualBox();

        /* the generated VirtualBox.dll COM library doesn't work with the C# event
         * system, so we handle events by registering callbacks
         */
        _virtualbox.RegisterCallback(this);

        _icon = GetIcon("icon/icon-16.ico");
        _idleIcon = GetIcon("icon/icon-gray-16.ico");

        _notifyIcon = new NotifyIcon();
        _notifyIcon.Icon = _idleIcon;
        _notifyIcon.Text = "Virtualtray";
        _notifyIcon.Visible = true;

        _vms = new Hashtable();

        ContextMenu menu = new ContextMenu();
        foreach (IMachine machine in _virtualbox.Machines) {
            MachineMenu mm = new MachineMenu(machine, menu);
            mm.StateChange += new EventHandler(MachineStateChangeEventHandler);
            _vms.Add(machine.Id, mm);
        }
        menu.MenuItems.Add(new MenuItem("-") {Name = "-"});
        menu.MenuItems.Add(new MenuItem("Open VirtualBox...", new EventHandler(
            MenuLaunchVirtualBoxEventHandler)));
        menu.MenuItems.Add(new MenuItem("Exit", new EventHandler(MenuExitEventHandler)));
        _notifyIcon.ContextMenu = menu;

        ToggleIcon();
        _notifyIcon.MouseClick += new MouseEventHandler(IconClickEventHandler);
        Application.ApplicationExit += new EventHandler(ApplicationExitEventHandler);
    }
Exemple #3
0
        /// <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);
            }
        }
Exemple #4
0
 public RegTester()
 {
     /* Create VBox instance */
     vBox         = new VirtualBox.VirtualBox();
     vmBaseFolder = Path.Combine(Environment.CurrentDirectory, "vm");
     logName      = defaultLogName;
 }
 public void DisConnect()
 {
     Logger.Info("{0}", (object)MethodBase.GetCurrentMethod().Name);
     Marshal.FinalReleaseComObject((object)this.mVirtualBoxClient);
     this.mSession          = (Session)null;
     this.mVirtualBox       = (IVirtualBox)null;
     this.mVirtualBoxClient = (IVirtualBoxClient)null;
 }
 public void Connect()
 {
     Logger.Info("{0}", (object)MethodBase.GetCurrentMethod().Name);
     this.mVirtualBoxClient = (IVirtualBoxClient) new VirtualBoxClientClass();
     this.mVirtualBox       = (IVirtualBox)this.mVirtualBoxClient.VirtualBox;
     Logger.Info("Version: " + this.mVirtualBox.Version);
     this.mSession = this.mVirtualBoxClient.Session;
 }
 public VBoxControl(string VMName, string Username, string Password, string Domain) : base(VMName, Username, Password, Domain)
 {
     try
     {
         vbox    = new VirtualBoxClass();
         machine = vbox.Machines.Single(p => p.Name == VMName);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemple #8
0
        public VboxTraySvc()
        {
            InitializeComponent();
            ServiceName = "VboxTraySvc";

            AutoLog = false;
            vbox    = new VirtualBox.VirtualBox();

            FieldInfo acceptedCommandsFieldInfo =
                typeof(ServiceBase).GetField("acceptedCommands", BindingFlags.Instance | BindingFlags.NonPublic);

            if (acceptedCommandsFieldInfo == null)
            {
                EventLog.WriteEntry(ServiceName, "acceptedCommands field not found", EventLogEntryType.Information);
            }
            else
            {
                int value = (int)acceptedCommandsFieldInfo.GetValue(this);
                acceptedCommandsFieldInfo.SetValue(this, value | SERVICE_ACCEPT_PRESHUTDOWN);
            }
        }
        /// <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();
            }
        }
Exemple #11
0
        public MachineMenu(IMachine machine, Menu parentMenu)
        {
            _virtualbox = machine.Parent;
            _virtualbox.RegisterCallback(this);
            _session = null;
            _id = machine.Id;
            _name = machine.Name;
            _parentMenu = parentMenu;
            _menu = new MenuItem(machine.Name);

            /* initially create MenuItems for all possible VM actions, then show/hide
             * them as needed
             */
            object[][] submenus = new object [][] {
                new object[] {Submenu.Start, "Start Machine", new EventHandler(MenuStartEventHandler)},
                new object[] {Submenu.StartHeadless, "Start Machine Headless", new EventHandler(MenuStartHeadlessEventHandler)},
                new object[] {Submenu.Save, "Save Machine", new EventHandler(MenuSaveEventHandler)},
                new object[] {Submenu.Stop, "Stop Machine", new EventHandler(MenuStopEventHandler)}
            };

            Array.ForEach<object[]>(submenus, delegate(object[] s) {
                MenuItem m = new MenuItem((string) s[1], (EventHandler) s[2]);
                m.Visible = false;
                _submenu[(int) s[0]] = m;
                _menu.MenuItems.Add(m);
            });

            State = machine.State;

            int last = _parentMenu.MenuItems.IndexOfKey("-");
            last = last < 0 ? _parentMenu.MenuItems.Count : last;
            _parentMenu.MenuItems.Add(last, _menu);
        }