lWindowRDPRetryIterator=gRecoveryWindowRDPRetryCountInt# Set last iterator to turn off the loop
lWindowRDPRetryIterator=gRecoveryWindowRDPRetryCountInt# Set last iterator to turn off the loop
exceptExceptionase:# RDP window is not exist - try to reconnect
exceptExceptionase:# RDP window is not exist - try to reconnect
ifinLogger:inLogger.warning(f"RDP::SessionScreenFull: RDP window is not exist - try sleep {gRecoveryWindowRDPRetryIntervalSecInt}[s.] and then to reconnect. SessionHex: {inSessionHex}")
iflL:lL.warning(f"RDP::SessionScreenFull: RDP window is not exist - try sleep {gRecoveryWindowRDPRetryIntervalSecInt}[s.] and then to reconnect. SessionHex: {inSessionHex}. Current retry iterator is {lWindowRDPRetryIterator}")
time.sleep(gRecoveryWindowRDPRetryIntervalSecInt)# Before try to reconnect sleep
iflRDPConfigurationItem:
iflRDPConfigurationItem:
time.sleep(gRecoveryWindowRDPRetryIntervalSecInt)# Before try to reconnect sleep
# Try to reconnect the RDP
# Try to reconnect the RDP
Connector.SessionClose(inSessionHexStr=lSessionHex)# Close the
SessionClose(inSessionHexStr=inSessionHex)# Close the
lWindowRDPRetryIterator=lWindowRDPRetryIterator+1# increase the iterator
lWindowRDPRetryIterator=lWindowRDPRetryIterator+1# increase the iterator
iflWindowRDPRetryIterator>=gRecoveryWindowRDPRetryCountInt:# Raise the error if retry count is over
iflL:lL.warning(f"RDP::SessionScreenFull: Retry count is over. Raise the error. SessionHex: {inSessionHex}.")# Log the info
raiseConnectorExceptions.SessionWindowNotExistError()# raise the error
else:
else:
ifinLogger:inLogger.warning(f"RDP::SessionScreenFull: Has no RDP configuration item - don't reconnect. Raise the error. SessionHex: {inSessionHex}")# Log the info
iflL:lL.warning(f"RDP::SessionScreenFull: Has no RDP configuration item - don't reconnect. Raise the error. SessionHex: {inSessionHex}")# Log the info
raiseConnectorExceptions.SessionWindowNotExistError()# raise the errors
raiseConnectorExceptions.SessionWindowNotExistError()# raise the error
# RDP window has been detected - go to set focus and maximize
# RDP window has been detected - go to set focus and maximize
lClipboardStr=Clipboard.TextGet()# Get text from clipboard
time.sleep(0.5)# wait some time for the next operation
iflClipboardStr==lInputStr:# Cross check the clipboard data and input string
lRecoveryWindowRUNRetryIteratorInt=gRecoveryWindowRUNRetryCountInt# Set final count to block the loop
else:# Failed - wait and retry
iflL:lL.warning(f"RDP::SystemCMDRun: Window run doesn't appear. Wait for {gRecoveryWindowRUNRetryIntervalSecInt}[s.] and retry. Current retry iterator is {lRecoveryWindowRUNRetryIteratorInt}. CMD Str: {lInputStr}")# Log the error
lRecoveryWindowRUNRetryIteratorInt=lRecoveryWindowRUNRetryIteratorInt+1# Increment the iterator
lResult["OutStr"]=Clipboard.TextGet()# Get text from clipboard
lResult["OutStr"]=Clipboard.TextGet()# Get text from clipboard
time.sleep(0.5)# wait some time for the next operation
time.sleep(0.5)# wait some time for the next operation
# Do crosscheck
iflResult["OutStr"]==lClipboardTextOld:# If value hasn't been changed - retry send
lRecoveryCMDResponsibleRetryIteratorInt=lRecoveryCMDResponsibleRetryIteratorInt+1# increment the iterator
iflL:lL.warning(f"RDP::SystemCMDRun: CMD command doesn't been executed (no changes in 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
iflRecoveryCMDResponsibleRetryIteratorInt>=gRecoveryCMDResponsibleRetryCountInt:# raise the error if retry count is exceeded
iflL:lL.warning(f"RDP::SystemCMDRun: Retry count is over. Raise the error.")# Log the error
raiseConnectorExceptions.CMDResponsibleError()# Raise the error
time.sleep(gRecoveryCMDResponsibleRetryIntervalSecInt)# wait for some seconds before new iteration
iflResult["OutStr"]==f"{lCrosscheckKeyStr}\r\n\x00\x00\x00\x00\x00":# it is ok - do futher check
lResult["IsResponsibleBool"]=True
lResult["IsResponsibleBool"]=True
lRecoveryCMDResponsibleRetryIteratorInt=gRecoveryCMDResponsibleRetryCountInt# turn off the iterator
else:
else:
lResult["IsResponsibleBool"]=False
lResult["IsResponsibleBool"]=False
# return the result
lRecoveryCMDResponsibleRetryIteratorInt=lRecoveryCMDResponsibleRetryIteratorInt+1# increment the iterator
returnlResult
iflL: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
iflRecoveryCMDResponsibleRetryIteratorInt>=gRecoveryCMDResponsibleRetryCountInt:# raise the error if retry count is exceeded
iflL:lL.warning(f"RDP::SystemCMDRun: Retry count is over. Raise the error.")# Log the error
raiseConnectorExceptions.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
ifConnector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"])or# if window in full screen - resize
ifConnector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"])orConnector.SessionIsMinimizedScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]):# If window is minimized - restore # if window in full screen - resize
Connector.SessionIsMinimizedScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]):# If window is minimized - restore