protected static List <PosInfo> reorderLocation(List <PosInfo> locations, IVDController controller) { var results = new List <PosInfo>(); var processed = new Dictionary <string, bool>(); foreach (var l in locations) { if (string.IsNullOrEmpty(l.Name())) { continue; } if (processed.ContainsKey(l.Name())) { continue; } processed.Add(l.Name(), true); var allNames = locations.FindAll(me => me.Name() == l.Name()).OrderBy(me => me.Level()).ToList(); controller.Log("debug", $"before dup {l.Name()} has {allNames.Count} items"); var allDist = new List <PosInfo>(); allNames.ForEach(me => { if (allDist.FirstOrDefault(x => x.point.x == me.point.x && x.point.y == me.point.y) == null) { allDist.Add(me); } }); results.AddRange(allDist); } return(results); }
public static void SetWaitForWakeUpTime(IVDController controller, long timeMs, bool setToSleep) { SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS); IntPtr handle; //long duetime = -300000000; // negative value, so a RELATIVE due time long duetime = -10000 * timeMs; // negative value, so a RELATIVE due time handle = CreateWaitableTimer(IntPtr.Zero, true, "MyWaitabletimer"); SetWaitableTimer(handle, ref duetime, 0, IntPtr.Zero, IntPtr.Zero, true); if (setToSleep) { new Thread(() => { controller.Log("info", "puting computer to sleep"); PutComputerToSleep(); }).Start(); } uint INFINITE = 0xFFFFFFFF; int ret = WaitForSingleObject(handle, INFINITE); CloseHandle(handle); SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS); controller.Log("info", "computer woke from sleep"); }
public ProcessingContext(IMouse m, IKeyboard k, IVDController c) { mouse = m; keyboard = k; vdcontroller = c; stdClk = new StandardClicks(this); }
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); }