from pyOpenRPA.Robot import UIDesktop from . import Connector import os import time # Time wait operations import pdb import importlib # from dynamic import module #Check for session is closed. Reopen if detected. Always keep session is active def Monitor(inGlobalDict, inListUpdateTimeout): lFlagWhile = True while lFlagWhile: # UIOSelector list init lUIOSelectorList = [] #Prepare selectors list for check for lIndex, lItem in enumerate(inGlobalDict["RDPList"]): lUIOSelectorList.append([{"title_re": f"{lItem['SessionHex']}.*", "backend": "win32"}]) #Run wait command lRDPDissappearList = UIDesktop.UIOSelectorsSecs_WaitDisappear_List(lUIOSelectorList, inListUpdateTimeout) ########################################### #Analyze if flag safeturn off is activated if inGlobalDict.get("OrchestratorToRobotResetStorage",{}).get("SafeTurnOff",False): lFlagWhile=False #Set status disconnected for all RDP List for lItem in inGlobalDict["RDPList"]: lItem["FlagSessionIsActive"]=False #Kill all RDP sessions os.system('taskkill /F /im mstsc.exe') #Return from function return ########################################### ########################################### for lItem in lRDPDissappearList: inGlobalDict["RDPList"][lItem]["FlagSessionIsActive"] = False # Set flag that session is disconnected #pdb.set_trace() #Session start if it is not in ignore list #add check for selector if it is not in ignoreIndexList if lItem not in inGlobalDict["OrchestratorToRobotStorage"]["IgnoreIndexList"]: try: Connector.Session(inGlobalDict["RDPList"][lItem]) inGlobalDict["RDPList"][lItem]["FlagSessionIsActive"] = True # Flag that session is started except Exception: pass ########################################### #Check if from Orchestrator full screen session is set if inGlobalDict["OrchestratorToRobotStorage"]["FullScreenSessionIndex"] != inGlobalDict["FullScreenSessionIndex"]: #Do some switches #If full screen mode we have now if inGlobalDict["FullScreenSessionIndex"] is not None: if inGlobalDict["RDPList"][inGlobalDict["FullScreenSessionIndex"]]["FlagSessionIsActive"]: Connector.SessionScreen100x550(inGlobalDict["RDPList"][inGlobalDict["FullScreenSessionIndex"]]["SessionHex"]) #If new session is setted if inGlobalDict["OrchestratorToRobotStorage"]["FullScreenSessionIndex"] is not None: if inGlobalDict["RDPList"][inGlobalDict["OrchestratorToRobotStorage"]["FullScreenSessionIndex"]]["FlagSessionIsActive"]: 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"]: ################# #Call function from Activity structure ################################################ lSubmoduleFunctionName = lActivityItem["DefName"] lFileFullPath = lActivityItem["ModulePath"] # "path\\to\\module.py" lModuleName = (lFileFullPath.split("\\")[-1])[0:-3] lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath) lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification) lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec) if lSubmoduleFunctionName in dir(lTechModuleFromSpec): # Run SettingUpdate function in submodule #mGlobalDict = getattr(lTechModuleFromSpec, lSubmoduleFunctionName)() getattr(lTechModuleFromSpec, lSubmoduleFunctionName)(*lActivityItem["ArgList"],**lActivityItem["ArgDict"]) ################################################# inGlobalDict["OrchestratorToRobotResetStorage"]["ActivityList"] = [] # Override the value time.sleep(2) return None #TODO Def garbage window cleaner (if connection was lost)