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);
            }
        }
Exemplo n.º 2
0
        private void btnRunData_Click(object sender, EventArgs e)
        {
            PCRunResponse pcRunResponse = pcRestProxy.GetRunData(int.Parse(txtRunID.Text));

            if (pcRunResponse != null)
            {
                List <PCRunResponse> pcRunResponseList = new List <PCRunResponse>();
                pcRunResponseList.Add(pcRunResponse);
                dgvForAll.DataSource = pcRunResponseList;
                btnRunData.Text      = "RunData received";
                btnRunData.BackColor = Color.Green;
            }
            else
            {
                btnRunData.Text      = "RunData not received";
                btnRunData.BackColor = Color.Red;
            }
        }