private PCRunResponse WaitForRunState(int runId, PCRunState completionState, int interval) { PCErrorResponse pcErrorResponse = new PCErrorResponse("", 0); try { int counter = 0; PCRunState[] waitingStates = { PCRunState.BEFORE_COLLATING_RESULTS, PCRunState.BEFORE_CREATING_ANALYSIS_DATA }; PCRunState[] failingStates = { PCRunState.RUN_FAILURE, PCRunState.FAILED_CREATING_ANALYSIS_DATA }; PCRunResponse response = null; PCRunState lastState = PCRunState.UNDEFINED; do { response = _pcRestProxy.GetRunData(runId, ref pcErrorResponse); PCRunState currentState = PCRunState.get(response.RunState); if (lastState.ordinal() < currentState.ordinal()) { lastState = currentState; _fileLog.Write(LogMessageType.Info, string.Format("RunID: {0} - State = {1}\n", runId, currentState.Value)); } // In case we are in state before collate or before analyze, we will wait 1 minute for the state to change otherwise we exit // because the user probably stopped the run from PC or timeslot has reached the end. if (waitingStates.Contains(currentState)) { counter++; System.Threading.Thread.Sleep(1000); if (counter > 60) { _fileLog.Write(LogMessageType.Info, string.Format("RunID: {0} - Stopped from LoadRunner Enterprise side with state = {1}", runId, currentState.Value)); break; } } else if (failingStates.Contains(currentState)) { _fileLog.Write(LogMessageType.Info, string.Format("Error - RunID: {0} ended with state = {1}", runId, currentState.Value)); } else { counter = 0; System.Threading.Thread.Sleep(interval); } }while (lastState.ordinal() < completionState.ordinal()); return(response); } catch (Exception ex) { _fileLog.Write(LogMessageType.Error, string.Format("WaitForRunState failed, reason: {0}", ex.Message)); if (pcErrorResponse.ErrorCode > 0) { _fileLog.Write(LogMessageType.Error, string.Format("WaitForRunState failed, ExceptionMessage: {0}, ErrorCode: {1}", pcErrorResponse.ExceptionMessage, pcErrorResponse.ErrorCode)); } return(null); } }
public PCRunResponse WaitForRunCompletion(int runId, int interval) { PCRunState state = PCRunState.UNDEFINED; switch (_pcModel.PCPostRunActionsRequest.PostRunAction) { case PCConstants.DONOTCOLLATE: state = PCRunState.BEFORE_COLLATING_RESULTS; break; case PCConstants.COLLATERESULTS: state = PCRunState.BEFORE_CREATING_ANALYSIS_DATA; break; case PCConstants.COLLATEANDANALYZE: state = PCRunState.FINISHED; break; } return(WaitForRunState(runId, state, interval)); }