From b02acc1a142c1011c5ba218b7546e6bf442123a5 Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Wed, 11 Mar 2020 07:18:03 +0300 Subject: [PATCH] # Beta - dont use as release Tool RobotRDPActive --- .../Tools/RobotRDPActive/Clipboard.py | 39 +++++++++++++++++++ .../Tools/RobotRDPActive/Connector.py | 17 ++++++-- .../pyOpenRPA/Tools/RobotRDPActive/Monitor.py | 11 ++++++ .../Tools/RobotRDPActive/__main__.py | 1 + .../SettingsRobotRDPActiveExample.py | 6 ++- 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 Sources/pyOpenRPA/Tools/RobotRDPActive/Clipboard.py diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Clipboard.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Clipboard.py new file mode 100644 index 00000000..1af5ea76 --- /dev/null +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Clipboard.py @@ -0,0 +1,39 @@ +import win32clipboard +import keyboard # keyboard functions +import time # Some operations need wait +import random # random number for test +# set clipboard data +def TextSet(inTextStr): + win32clipboard.OpenClipboard() + win32clipboard.EmptyClipboard() + win32clipboard.SetClipboardText(inTextStr) + win32clipboard.CloseClipboard() + +# get clipboard data +def TextGet(): + win32clipboard.OpenClipboard() + data = win32clipboard.GetClipboardData() + win32clipboard.CloseClipboard() + return data +# Test in has text cursor and ready to apply +def InputIsFocused(): + keyboard.press_and_release("ctrl+a") + keyboard.press_and_release("backspace") # remove old text + lTextForTest = str(random.randrange(100,99999)) + keyboard.write(lTextForTest) + keyboard.press_and_release("ctrl+a") + keyboard.press_and_release("ctrl+c") + time.sleep(2) + keyboard.press_and_release("backspace") # remove old text + lClipboardText = TextGet() + lResult = lClipboardText == lTextForTest + return lResult +# Check if cmd is opened +def CMDIsOpen(): + lTextForTest = str(random.randrange(100,99999)) + keyboard.write(lTextForTest+" |clip") + keyboard.press_and_release("enter") + time.sleep(2) + lClipboardText = TextGet() + lResult = lClipboardText == lTextForTest + return lResult \ No newline at end of file diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py index 5910bc9f..7f0d4853 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py @@ -5,6 +5,7 @@ import uuid #temp id for Template.rdp import tempfile #Temporary location import time import subprocess +from . import Clipboard # Clipboard functions get/set #Connect to RDP session """ { @@ -123,7 +124,7 @@ def SessionRDPStart(inRDPFilePath): #Set fullscreen for app def SessionScreenFull(inSessionHex): #Prepare little window - lRDPWindow = UIDesktop.UIOSelector_Get_UIO([{"title_re": f"{inSessionHex}.*", "backend": "win32"}]) + lRDPWindow = UIDesktop.UIOSelector_Get_UIO([{"title_re": f"{inSessionHex}.*", "backend": "uia"}]) #Hotfix uia is needed to set focus in RDP lRDPWindow.maximize() lRDPWindow.set_focus() return None @@ -131,7 +132,10 @@ def SessionScreenFull(inSessionHex): def SessionScreen100x550(inSessionHex): #Prepare little window lRDPWindow = UIDesktop.UIOSelector_Get_UIO([{"title_re": f"{inSessionHex}.*", "backend": "win32"}]) - lRDPWindow.restore() + #lRDPWindow.minimize() + #lRDPWindow.restore() + lRDPWindow.maximize() + lRDPWindow.type_keys("^%{BREAK}") # Ctrl + alt + creak to return window from full screen correctly lRDPWindow.move_window(10,10,550,100) return None import keyboard @@ -139,8 +143,15 @@ import time #Type command in CMD def SessionCMDRun(inSessionHex,inCMDCommandStr): SessionScreenFull(inSessionHex) + time.sleep(2) # High priority keyboard.press_and_release('win+r') time.sleep(2) - keyboard.write(f"cmd {inCMDCommandStr}") + print(Clipboard.InputIsFocused()) + keyboard.write(f"cmd") keyboard.press_and_release('enter') + time.sleep(2) # Only time wait we can set here :( + print(Clipboard.CMDIsOpen()) + keyboard.write(f"{inCMDCommandStr} && exit") # Run CMD command and close CMD console + keyboard.press_and_release('enter') + time.sleep(2) SessionScreen100x550(inSessionHex) \ No newline at end of file diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py index c65ac8a6..935e5a0a 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py @@ -1,6 +1,7 @@ from pyOpenRPA.Robot import UIDesktop from . import Connector import os +import time # Time wait operations import pdb #Check for session is closed. Reopen if detected. Always keep session is active def Monitor(inGlobalDict, inListUpdateTimeout): @@ -51,5 +52,15 @@ def Monitor(inGlobalDict, inListUpdateTimeout): Connector.SessionScreenFull(inGlobalDict["RDPList"][inGlobalDict["OrchestratorToRobotStorage"]["FullScreenSessionIndex"]]["SessionHex"]) #Set one to other equal inGlobalDict["FullScreenSessionIndex"] = inGlobalDict["OrchestratorToRobotStorage"]["FullScreenSessionIndex"] + ########################################### + # Check ActivityList from orchestrator + for lActivityItem in inGlobalDict["OrchestratorToRobotResetStorage"]["ActivityList"]: + # Check case CMDCommand + if lActivityItem["Type"] == "CMDCommand": + pass + # CMD command passed + #Connector.SessionCMDRun(inSessionHex=lActivityItem["SessionHex"], inCMDCommandStr= lActivityItem["CMDValue"]) + # loop interval + time.sleep(2) return None #TODO Def garbage window cleaner (if connection was lost) \ No newline at end of file diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py index 7217dbed..4b7dd76f 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py @@ -41,6 +41,7 @@ for lConfigurationItem in mGlobalDict["RDPList"]: except Exception: pass #Run monitor +print(mGlobalDict) Monitor.Monitor(mGlobalDict, 1) #Enable certificate warning lCMDString = 'reg add "HKEY_CURRENT_USER\\Software\\Microsoft\\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 2 /f' diff --git a/Utils/RobotRDPActive/SettingsRobotRDPActiveExample.py b/Utils/RobotRDPActive/SettingsRobotRDPActiveExample.py index 0903c515..457fa2be 100644 --- a/Utils/RobotRDPActive/SettingsRobotRDPActiveExample.py +++ b/Utils/RobotRDPActive/SettingsRobotRDPActiveExample.py @@ -36,6 +36,10 @@ def Settings(): }, "OrchestratorToRobotResetStorage": { "SafeTurnOff":False #Control from orchestrator to safety turn off robot + "ActivityList":[ + {"Type":"CMDCommand", "CMDValue"}, + {"Type":"CreateFile","FileFullPath": "" ,"FileBytes": None} + ] }, "OrchestratorConnector": { #Fill below @@ -73,7 +77,7 @@ def Settings(): "Interval": 3.3, "RobotStorage": mDict, "RobotStorageKey": "OrchestratorToRobotResetStorage", - "RobotResetValue": {"SafeTurnOff":False}, + "RobotResetValue": mDict["OrchestratorToRobotResetStorage"], "OrchestratorKeyList": ["Storage", "RobotRDPActive","OrchestratorToRobotResetStorage"], "OrchestratorProtocol": lOrchestratorProtocol, "OrchestratorHost": lOrchestratorHost,