/// <summary>
        /// Returns a Wox.Plugin.Result object corresponding to this machine, containing the given score.
        /// </summary>
        /// <param name="machine">The machine to resultify</param>
        /// <param name="score">The score to assign to the result</param>
        public static Result ToScoredResult(this VirtualBoxApi.IMachine machine, int score)
        {
            var result = machine.ToResult();

            result.Score = score;
            return(result);
        }
        /// <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;
                }
            });
        }
Example #3
0
        public static void Start(IVDController controller)
        {
            //var rrr = Utils.GetAppInfo($"-input tstimgs\\upgradeelibad.png -name upgradegood -match data\\check\\upgradeeligood.png 10000 -name upgradebad -match data\\check\\upgradeelibad.png 10000");
            //SwitchAccount.CheckAccount();
            //TestAccounts(); //TODO DEBUG REMOVE THIS
            //return;
            controller.Log("info", "Starting vm");
            Utils.executeVBoxMngr($"startvm {Utils.vmname}");
            controller.Log("info", "VmStarted, allocate machine");
            var vbox = new VirtualBox.VirtualBox();

            VirtualBox.IMachine machine    = vbox.FindMachine(Utils.vmname);
            VirtualBoxClient    vboxclient = new VirtualBoxClient();
            var session = vboxclient.Session;

            try
            {
                controller.Log("info", "found machine, lock machine");
                machine.LockMachine(session, LockType.LockType_Shared);
                var          console     = session.Console;
                IEventSource es          = console.EventSource;
                var          listener    = es.CreateListener();
                Array        listenTYpes = new VBoxEventType[] { VBoxEventType.VBoxEventType_InputEvent };
                es.RegisterListener(listener, listenTYpes, 0);
                controller.Log("info", "locked machine, entry try");
                try
                {
                    //session.Console.Display.SetSeamlessMode(1);
                    var  display = console.Display;
                    uint sw, sh, bpp;
                    int  xorig, yorig;
                    GuestMonitorStatus gmstat;
                    display.GetScreenResolution(0, out sw, out sh, out bpp, out xorig, out yorig, out gmstat);
                    //Console.WriteLine($"sw={sw} {sh} bpp {bpp} xorig={xorig} yorig={yorig}");

                    byte[] buf = new byte[sw * sh * bpp / 8];
                    //display.TakeScreenShot(0, ref buf[0], sw, sh, BitmapFormat.BitmapFormat_PNG);

                    var mouse    = session.Console.Mouse;
                    var keyboard = session.Console.Keyboard;
                    //MouseMouseTo(mouse, 515, 660);
                    //MouseClick(mouse);
                    //MouseMouseTo(mouse, 360, 156);
                    //MouseClick(mouse);
                    controller.Log("info", "main loop");
                    while (true)
                    {
                        try
                        {
                            checkLoop(new ProcessingContext(mouse, keyboard, controller));
                        } catch (SwitchProcessingActionException)
                        {
                            continue;
                        }
                        break;
                    }
                }
                finally
                {
                    es.UnregisterListener(listener);
                }
            }
            catch (Exception e)
            {
                controller.Log("error", e.ToString());
            }
            finally
            {
                if (session.State == SessionState.SessionState_Locked)
                {
                    session.UnlockMachine();
                }
                controller.Log("info", "powering off");
                Utils.executeVBoxMngr($"controlvm {Utils.vmname} poweroff");
                controller.KillVBox();
                controller.Log("info", "sleeping 10s after kill vbox");
                controller.Sleep(10000);
                controller.Log("info", "vbox killed, poweroff");
            }
            //Console.WriteLine(machine.VideoCaptureWidth);
        }
 /// <summary>
 /// Returns true if this machine is online, false otherwise.
 ///
 /// At some point, C# will hopefully start supporting extension properties (see
 /// https://github.com/dotnet/csharplang/issues/192). At that point, it would probably
 /// make sense to turn this method into a property.
 /// </summary>
 /// <returns></returns>
 // ReSharper disable once MemberCanBePrivate.Global
 public static bool Online(this VirtualBoxApi.IMachine machine)
 {
     return(machine.State >= VirtualBoxApi.MachineState.MachineState_FirstOnline &&
            machine.State <= VirtualBoxApi.MachineState.MachineState_LastOnline);
 }
Example #5
0
 public ComMachineProxy(dynamic comMachine)
 {
     _comMachine = comMachine;
 }