Exemple #1
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);
        }