From f4ed1ff981f3afb03d59161e1cbfeee9b6677d44 Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Sun, 31 May 2020 14:26:31 +0300 Subject: [PATCH] # Update the RDP active - improove work of the RDP cmd sent + feedback --- .../Orchestrator/RobotRDPActive/Connector.py | 135 ++++++++++++------ .../RobotRDPActive/RobotRDPActive.py | 5 +- 2 files changed, 91 insertions(+), 49 deletions(-) diff --git a/Sources/pyOpenRPA/Orchestrator/RobotRDPActive/Connector.py b/Sources/pyOpenRPA/Orchestrator/RobotRDPActive/Connector.py index f49d2adb..a3526b13 100644 --- a/Sources/pyOpenRPA/Orchestrator/RobotRDPActive/Connector.py +++ b/Sources/pyOpenRPA/Orchestrator/RobotRDPActive/Connector.py @@ -15,10 +15,10 @@ gRecoveryWindowRDPRetryCountInt = 3 # Retry iteration count is RDP window is not gRecoveryWindowRDPRetryIntervalSecInt = 3 # Retry interval for reconnect gRecoveryWindowRUNRetryCountInt = 3 # Retry iteration count is RUN window is not responsible -gRecoveryWindowRUNRetryIntervalSecInt = 3 # Retry interval for reconnect +gRecoveryWindowRUNRetryIntervalSecInt = 3 # Retry interval for retry gRecoveryCMDResponsibleRetryCountInt = 3 # Retry iteration count is CMD is not responsible -gRecoveryCMDResponsibleRetryIntervalSecInt = 3 # Retry interval for reconnect +gRecoveryCMDResponsibleRetryIntervalSecInt = 3 # Retry interval for retry #Connect to RDP session """ @@ -159,23 +159,26 @@ def SessionScreenFull(inSessionHex, inGSettings = None): lRDPConfigurationItem = None lL = None if inGSettings: # Get the values from gSettings - lRDPConfigurationItem = inGSettings["RobotRDPActive"]["RDPList"][inRDPSessionKeyStr] # Get the RDP configuration item + lRDPConfigurationItem = inGSettings["RobotRDPActive"]["RDPList"][inSessionHex] # Get the RDP configuration item lL = inGSettings["Logger"] # Get the logger instance while lWindowRDPRetryIterator= gRecoveryWindowRDPRetryCountInt: # Raise the error if retry count is over + if lL: lL.warning(f"RDP::SessionScreenFull: Retry count is over. Raise the error. SessionHex: {inSessionHex}.") # Log the info + raise ConnectorExceptions.SessionWindowNotExistError() # raise the error else: - if inLogger: inLogger.warning(f"RDP::SessionScreenFull: Has no RDP configuration item - don't reconnect. Raise the error. SessionHex: {inSessionHex}") # Log the info - raise ConnectorExceptions.SessionWindowNotExistError() # raise the errors + if lL: lL.warning(f"RDP::SessionScreenFull: Has no RDP configuration item - don't reconnect. Raise the error. SessionHex: {inSessionHex}") # Log the info + raise ConnectorExceptions.SessionWindowNotExistError() # raise the error # RDP window has been detected - go to set focus and maximize lRDPWindow.set_focus() lRDPWindow.maximize() @@ -231,13 +234,15 @@ def SessionClose(inSessionHexStr): # } # example Connector.SessionCMDRun("4d1e48f3ff6c45cc810ea25d8adbeb50","start notepad", "RUN") def SessionCMDRun(inSessionHex,inCMDCommandStr = "echo 1", inModeStr="CROSSCHECK", inClipboardTimeoutSec = 5, inGSettings = None): + lL = None # Init the logger + if inGSettings: # If gSettings is exist + lL = inGSettings["Logger"] # get the logger # Init the result dict lResult = {"OutStr": None,"IsResponsibleBool":True} - # Enter full screen mode - SessionScreenFull(inSessionHex, inGSettings = inGSettings) + SessionScreenFull(inSessionHex, inGSettings = inGSettings) # Enter full screen mode with recovery scenario time.sleep(2) # Run CMD operations - lResult = SystemCMDRun(inCMDCommandStr = inCMDCommandStr, inModeStr = inModeStr, inClipboardTimeoutSec = inClipboardTimeoutSec) + lResult = SystemCMDRun(inCMDCommandStr = inCMDCommandStr, inModeStr = inModeStr, inClipboardTimeoutSec = inClipboardTimeoutSec, inLogger=lL) # Exit fullscreen mode SessionScreenSize_X_Y_W_H(inSessionHex=inSessionHex, inXInt=10, inYInt=10, inWInt=550, inHInt=350) # Prepare little window @@ -289,43 +294,81 @@ def SessionIsMinimizedScreen(inSessionHexStr): # "IsResponsibleBool": True|False # Flag is RDP is responsible - works only when inModeStr = CROSSCHECK # } # example Connector.SessionCMDRun("4d1e48f3ff6c45cc810ea25d8adbeb50","start notepad", "RUN") -def SystemCMDRun(inCMDCommandStr = "echo 1", inModeStr="CROSSCHECK", inClipboardTimeoutSec = 5): - # Set random text to clipboard (for check purposes that clipboard text has been changed) - lClipboardTextOld = str(random.randrange(999,9999999)) +def SystemCMDRun(inCMDCommandStr = "echo 1", inModeStr="CROSSCHECK", inClipboardTimeoutSec = 5, inLogger = None): + lL = inLogger # Alias for logger + lResult = {"OutStr": None,"IsResponsibleBool":True} # Init the result dict + lClipboardTextOld = str(random.randrange(999,9999999)) # Set random text to clipboard (for check purposes that clipboard text has been changed) Clipboard.TextSet(lClipboardTextOld) - # Init the result dict - lResult = {"OutStr": None,"IsResponsibleBool":True} lCrosscheckKeyStr = str(random.randrange(999,9999999)) - lCMDPostFixStr = "" # Case default "RUN" - if inModeStr == "CROSSCHECK": - lCMDPostFixStr = f"| echo {lCrosscheckKeyStr} | clip" - elif inModeStr == "LISTEN": - lCMDPostFixStr = f"| clip" - keyboard.press_and_release('win+r') - time.sleep(1) - # Remove old text - keyboard.press_and_release("ctrl+a") - keyboard.press_and_release("backspace") - # Write new text - keyboard.write(f"cmd /c {inCMDCommandStr} {lCMDPostFixStr}") - time.sleep(1) - # TODo cross check from clipboard - keyboard.press_and_release('enter') - # Get OutStr (Case CROSSCHECK and LISTEN) - if inModeStr == "CROSSCHECK" or inModeStr == "LISTEN": - lClipboardWaitTimeStartSec = time.time() - lResult["OutStr"] = Clipboard.TextGet() # Get text from clipboard - while lResult["OutStr"] == lClipboardTextOld and (time.time() - lClipboardWaitTimeStartSec) <= inClipboardTimeoutSec: + lRecoveryCMDResponsibleRetryIteratorInt = 0 # Init the retry iterator + while lRecoveryCMDResponsibleRetryIteratorInt= gRecoveryCMDResponsibleRetryCountInt: # raise the error if retry count is exceeded + if lL: lL.warning(f"RDP::SystemCMDRun: Retry count is over. Raise the error.") # Log the error + raise ConnectorExceptions.CMDResponsibleError() # Raise the error + time.sleep(gRecoveryCMDResponsibleRetryIntervalSecInt) # wait for some seconds before new iteration + else: # Data was recieved - do crosscheck + if inModeStr == "CROSSCHECK": + if lResult["OutStr"] == f"{lCrosscheckKeyStr} \r\n\x00\x00\x00\x00\x00": # it is ok - do futher check + lResult["IsResponsibleBool"] = True + lRecoveryCMDResponsibleRetryIteratorInt = gRecoveryCMDResponsibleRetryCountInt # turn off the iterator + else: + lResult["IsResponsibleBool"] = False + lRecoveryCMDResponsibleRetryIteratorInt = lRecoveryCMDResponsibleRetryIteratorInt + 1 # increment the iterator + if lL: lL.warning(f"RDP::SystemCMDRun: CMD command doesn't been executed (wrong clipboard data). Wait for {gRecoveryCMDResponsibleRetryIntervalSecInt}[s.] and retry from start window RUN. Current retry iterator is {lRecoveryCMDResponsibleRetryIteratorInt}. CMD Str: {lInputStr}, Clipboard data: {lResult['OutStr']}") # Log the error + if lRecoveryCMDResponsibleRetryIteratorInt >= gRecoveryCMDResponsibleRetryCountInt: # raise the error if retry count is exceeded + if lL: lL.warning(f"RDP::SystemCMDRun: Retry count is over. Raise the error.") # Log the error + raise ConnectorExceptions.CMDResponsibleError() # Raise the error + time.sleep(gRecoveryCMDResponsibleRetryIntervalSecInt) # wait for some seconds before new iteration + else: # clipboard data has been changed but mode is not crosscheck - return success from function + lRecoveryCMDResponsibleRetryIteratorInt = gRecoveryCMDResponsibleRetryCountInt # turn off the iterator + else: # Success - no cross validation is aaplicable + lRecoveryCMDResponsibleRetryIteratorInt = gRecoveryCMDResponsibleRetryCountInt # turn off the iterator + # # # # # # # # # # # # # # # # # # # # # # # # # # # # + return lResult # return the result # Check if current RDP is responsible def SystemRDPIsResponsible(): return SystemCMDRun(inCMDCommandStr = "echo 1", inModeStr="CROSSCHECK")["IsResponsibleBool"] diff --git a/Sources/pyOpenRPA/Orchestrator/RobotRDPActive/RobotRDPActive.py b/Sources/pyOpenRPA/Orchestrator/RobotRDPActive/RobotRDPActive.py index e24db40c..5f463a23 100644 --- a/Sources/pyOpenRPA/Orchestrator/RobotRDPActive/RobotRDPActive.py +++ b/Sources/pyOpenRPA/Orchestrator/RobotRDPActive/RobotRDPActive.py @@ -9,7 +9,7 @@ def RobotRDPActive(inGSettings): # inGSettings = { # ... "RobotRDPActive": {} ... # } - lL = gSettingsDict["Logger"] #Logger alias + lL = inGSettings["Logger"] #Logger alias Processor.gSettings = inGSettings # Set gSettings in processor module mGSettingsRDPActiveDict = inGSettings["RobotRDPActive"] # Get configuration from global dict settings # Global error handler @@ -95,8 +95,7 @@ def RobotRDPActive(inGSettings): # Check all RDP window and minimize it for lRDPSessionKeyStrItem in inGlobalDict["RDPList"]: lRDPConfigurationDictItem = inGlobalDict["RDPList"][lRDPSessionKeyStrItem] - if Connector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]) or # if window in full screen - resize - Connector.SessionIsMinimizedScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]): # If window is minimized - restore + if Connector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]) or Connector.SessionIsMinimizedScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]): # If window is minimized - restore # if window in full screen - resize Connector.SessionScreenSize_X_Y_W_H(inSessionHex=lRDPConfigurationDictItem["SessionHex"], inXInt=10, inYInt=10, inWInt=550,