From cd8f6bb64c690eaa2e203a4676051d98eeb1e40d Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Tue, 31 Mar 2020 17:21:30 +0300 Subject: [PATCH] RobotRDPActive: # Minor fixes/ ActivityListFromOrchestrator/ StartFullscreen fix/ AddFunctions without GDict send --- .../Tools/RobotRDPActive/Connector.py | 4 +- .../Tools/RobotRDPActive/Defs_SessionIndex.py | 76 +++++++++++++++++++ .../GlobalDictSessionIndex_Defs.py | 4 +- .../pyOpenRPA/Tools/RobotRDPActive/Monitor.py | 2 + .../Tools/RobotRDPActive/Scheduler.py | 12 ++- Utils/RobotRDPActive/CheckAutoLogon.txt | 2 + .../SettingsRobotRDPActiveExample.py | 5 +- 7 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 Sources/pyOpenRPA/Tools/RobotRDPActive/Defs_SessionIndex.py create mode 100644 Utils/RobotRDPActive/CheckAutoLogon.txt diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py index a024d535..facc60c0 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py @@ -140,6 +140,8 @@ def SessionRDPStart(inRDPFilePath): raise ConnectorExceptions.SessionWindowNotExistError("Error when initialize the RDP session - No RDP windows has appreared!") # Wait for init time.sleep(3) + # set the fullscreen + SessionScreenFull(inSessionHex=lRDPFileName) # Check RDP responsibility lDoCheckResponsibilityBool = True lDoCheckResponsibilityCountMax = 20 @@ -264,7 +266,7 @@ def SystemCMDRun(inCMDCommandStr = "echo 1", inModeStr="CROSSCHECK", inClipboard 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 + while lResult["OutStr"] == lClipboardTextOld and (time.time() - lClipboardWaitTimeStartSec) <= inClipboardTimeoutSec: lResult["OutStr"] = Clipboard.TextGet() # Get text from clipboard time.sleep(0.5) # wait some time for the next operation # Do crosscheck diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Defs_SessionIndex.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Defs_SessionIndex.py new file mode 100644 index 00000000..4332dc3a --- /dev/null +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Defs_SessionIndex.py @@ -0,0 +1,76 @@ +# ATTENTION! HERE IS NO Relative import because it will be imported dynamically +# All function check the flag SessionIsWindowResponsibleBool == True else no cammand is processed +# All functions can return None, Bool or Dict { "IsSuccessful": True } +from pyOpenRPA.Tools.RobotRDPActive import CMDStr # Create CMD Strings +from pyOpenRPA.Tools.RobotRDPActive import Connector # RDP API +#ATTENTION +gSettings = None # Gsettings will be initialized after the import module +def ProcessStartIfNotRunning(inSessionIndex, inProcessName, inFilePath, inFlagGetAbsPath=True): + global gSettings + inGlobalDict = gSettings + lResult = True + lCMDStr = CMDStr.ProcessStartIfNotRunning(inProcessName,inFilePath, inFlagGetAbsPath= inFlagGetAbsPath) + # Calculate the session Hex + lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] + # Check is Session is responsible + if inGlobalDict["RDPList"][inSessionIndex]["SessionIsWindowResponsibleBool"]: + # Run CMD + Connector.SessionCMDRun(inSessionHex=lSessionHex, inCMDCommandStr=lCMDStr, inModeStr="RUN") + else: + # Write in logger - warning + inGlobalDict["Logger"].warning(f"Defs_SessionIndex.ProcessStartIfNotRunning: SessionIndex: {str(inSessionIndex)}, ProcessName: {inProcessName}:: Session is not responsible!") + lResult = False # Set false result - function has not been done + return lResult +# Create CMD str to stop process +def ProcessStop(inSessionIndex, inProcessName, inFlagForceClose): + global gSettings + inGlobalDict = gSettings + lResult = True + lCMDStr = f'taskkill /im "{inProcessName}" /fi "username eq %USERNAME%"' + if inFlagForceClose: + lCMDStr+= " /F" + # Calculate the session Hex + lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] + # Check is Session is responsible + if inGlobalDict["RDPList"][inSessionIndex]["SessionIsWindowResponsibleBool"]: + # Run CMD + Connector.SessionCMDRun(inSessionHex=lSessionHex, inCMDCommandStr=lCMDStr, inModeStr="RUN") + else: + # TODO Write in logger - warning + inGlobalDict["Logger"].warning(f"Defs_SessionIndex.ProcessStop: SessionIndex: {str(inSessionIndex)}, ProcessName: {inProcessName}:: Session is not responsible!") + lResult = False # Set false result - function has not been done + return lResult +# Send file from Host to Session RDP using shared drive in RDP +def FileStoredSend(inSessionIndex, inHostFilePath, inRDPFilePath): + global gSettings + inGlobalDict = gSettings + lResult = True + lCMDStr = CMDStr.FileStoredSend(inHostFilePath = inHostFilePath, inRDPFilePath = inRDPFilePath) + # Calculate the session Hex + lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] + # Check is Session is responsible + if inGlobalDict["RDPList"][inSessionIndex]["SessionIsWindowResponsibleBool"]: + # Run CMD + Connector.SessionCMDRun(inSessionHex=lSessionHex, inCMDCommandStr=lCMDStr, inModeStr="LISTEN", inClipboardTimeoutSec = 120) + else: + # Write in logger - warning + inGlobalDict["Logger"].warning(f"Defs_SessionIndex.FileStoredSend: SessionIndex: {str(inSessionIndex)}, HostFilePath: {inHostFilePath}:: Session is not responsible!") + lResult = False # Set false result - function has not been done + return lResult +# Recieve file from Session RDP to Host using shared drive in RDP +def FileStoredRecieve(inSessionIndex, inRDPFilePath, inHostFilePath): + global gSettings + inGlobalDict = gSettings + lResult = True + lCMDStr = CMDStr.FileStoredRecieve(inRDPFilePath = inRDPFilePath, inHostFilePath = inHostFilePath) + # Calculate the session Hex + lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] + # Check is Session is responsible + if inGlobalDict["RDPList"][inSessionIndex]["SessionIsWindowResponsibleBool"]: + # Run CMD + Connector.SessionCMDRun(inSessionHex=lSessionHex, inCMDCommandStr=lCMDStr, inModeStr="LISTEN", inClipboardTimeoutSec = 120) + else: + # Write in logger - warning + inGlobalDict["Logger"].warning(f"Defs_SessionIndex.FileStoredRecieve: SessionIndex: {str(inSessionIndex)}, HostFilePath: {inHostFilePath}:: Session is not responsible!") + lResult = False # Set false result - function has not been done + return lResult \ No newline at end of file diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/GlobalDictSessionIndex_Defs.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/GlobalDictSessionIndex_Defs.py index bc7d5e8f..d4c7c82f 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/GlobalDictSessionIndex_Defs.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/GlobalDictSessionIndex_Defs.py @@ -37,7 +37,7 @@ def ProcessStop(inGlobalDict, inSessionIndex, inProcessName, inFlagForceClose): # Send file from Host to Session RDP using shared drive in RDP def FileStoredSend(inGlobalDict, inSessionIndex, inHostFilePath, inRDPFilePath): lResult = True - lCMDStr = CMDStr.FileStoredSend(inHostFilePath = inHostFilePath, inRDPFilePath = inRDPFilePath): + lCMDStr = CMDStr.FileStoredSend(inHostFilePath = inHostFilePath, inRDPFilePath = inRDPFilePath) # Calculate the session Hex lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] # Check is Session is responsible @@ -52,7 +52,7 @@ def FileStoredSend(inGlobalDict, inSessionIndex, inHostFilePath, inRDPFilePath): # Recieve file from Session RDP to Host using shared drive in RDP def FileStoredRecieve(inGlobalDict, inSessionIndex, inRDPFilePath, inHostFilePath): lResult = True - lCMDStr = CMDStr.FileStoredRecieve(inRDPFilePath = inRDPFilePath, inHostFilePath = inHostFilePath): + lCMDStr = CMDStr.FileStoredRecieve(inRDPFilePath = inRDPFilePath, inHostFilePath = inHostFilePath) # Calculate the session Hex lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] # Check is Session is responsible diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py index c1eb11b9..d35a52d2 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py @@ -130,6 +130,8 @@ def Monitor(inGlobalDict, inListUpdateTimeout): lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath) lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification) lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec) + # Set gSettings in module + lTechModuleFromSpec.gSettings = inGlobalDict if lSubmoduleFunctionName in dir(lTechModuleFromSpec): # Run SettingUpdate function in submodule #mGlobalDict = getattr(lTechModuleFromSpec, lSubmoduleFunctionName)() diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Scheduler.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Scheduler.py index 2f48aa9f..bf67287b 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/Scheduler.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Scheduler.py @@ -9,12 +9,14 @@ import importlib # import lib functions class Scheduler: # Class properties mSchedulerDict = None + mGSettings = None ######################### # Init class - def __init__(self,inSchedulerDict): - self.Init(inSchedulerDict = inSchedulerDict) + def __init__(self,inSchedulerDict, inGSettings = None): + self.Init(inSchedulerDict = inSchedulerDict, inGSettings = inGSettings) # Init the class instance - def Init(self,inSchedulerDict): + def Init(self,inSchedulerDict, inGSettings): + self.mGSettings = inGSettings self.mSchedulerDict = inSchedulerDict # Init the threads lTimerMainThread = threading.Thread(target = self.TimerMainThreadRun) @@ -63,6 +65,8 @@ class Scheduler: lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath) lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification) lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec) + # Set gSettings in module + lTechModuleFromSpec.gSettings = self.mGSettings if lSubmoduleFunctionName in dir(lTechModuleFromSpec): # Run SettingUpdate function in submodule #mGlobalDict = getattr(lTechModuleFromSpec, lSubmoduleFunctionName)() @@ -93,6 +97,8 @@ class Scheduler: lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath) lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification) lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec) + # Set gSettings in module + lTechModuleFromSpec.gSettings = self.mGSettings if lSubmoduleFunctionName in dir(lTechModuleFromSpec): # Run SettingUpdate function in submodule #mGlobalDict = getattr(lTechModuleFromSpec, lSubmoduleFunctionName)() diff --git a/Utils/RobotRDPActive/CheckAutoLogon.txt b/Utils/RobotRDPActive/CheckAutoLogon.txt new file mode 100644 index 00000000..a338486f --- /dev/null +++ b/Utils/RobotRDPActive/CheckAutoLogon.txt @@ -0,0 +1,2 @@ +https://www.intowindows.com/how-to-automatically-login-in-windows-10/ +Netplwiz \ No newline at end of file diff --git a/Utils/RobotRDPActive/SettingsRobotRDPActiveExample.py b/Utils/RobotRDPActive/SettingsRobotRDPActiveExample.py index 30827e68..42a62bdf 100644 --- a/Utils/RobotRDPActive/SettingsRobotRDPActiveExample.py +++ b/Utils/RobotRDPActive/SettingsRobotRDPActiveExample.py @@ -39,6 +39,9 @@ def Settings(): "ResponsibilityCheckIntervalSec": None, # Seconds interval when Robot check the RDP responsibility. if None - dont check "FullScreenSessionIndex": None, #Index of the current session which is full screened, None is no session in fullscreen "Logger": logging.getLogger("RobotRDPActive"), + "Logs": { + "FlagShowInConsole":True + }, "OrchestratorToRobotStorage": { "FullScreenSessionIndex":None, #Index of the session which is full screen in GUI. None if no session in full screen "IgnoreIndexList":[] @@ -165,7 +168,7 @@ def Settings(): ####################Add console output if mDict["Logs"]["FlagShowInConsole"]: handler = logging.StreamHandler(sys.stdout) - handler.setFormatter(lRobotLoggerFormatter) + handler.setFormatter(mRobotLoggerFormatter) mRobotLogger.addHandler(handler) ############################################ return mDict \ No newline at end of file