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 int StartRun()
        {
            PCErrorResponse pcErrorResponse = new PCErrorResponse("", 0);

            try
            {
                int testID       = int.Parse(_pcModel.TestId);
                int testInstance = GetCorrectTestInstanceID(testID);
                if (testInstance == 0)
                {
                    return(0);
                }
                SetCorrectTrendReportID();

                string msg = string.Format("Executing Load Test:\n====================\nTest ID: {0} \nTest Instance ID: {1} \nTimeslot Duration: {2} \nPost Run Action: {3} \nUse VUDS: {4}\n====================\n",
                                           int.Parse(_pcModel.TestId), testInstance, _pcModel.PCTimeslotDuration, _pcModel.PCPostRunActionsRequest.PostRunAction, _pcModel.isVudsMode());
                _fileLog.Write(LogMessageType.Info, msg);

                PCRunResponse response = _pcRestProxy.StartRun(testID,
                                                               testInstance,
                                                               _pcModel.PCTimeslotDuration,
                                                               ref pcErrorResponse,
                                                               _pcModel.PCPostRunActionsRequest.PostRunAction,
                                                               _pcModel.isVudsMode());
                if (response == null && pcErrorResponse != null)
                {
                    _fileLog.Write(LogMessageType.Info, string.Format("{0}, Error Code: {1}",
                                                                      pcErrorResponse.ExceptionMessage, pcErrorResponse.ErrorCode));
                    return(0);
                }
                _fileLog.Write(LogMessageType.Info, string.Format("Run started (TestID: {0}, RunID: {1}, TimeslotID: {2})\n",
                                                                  response.TestID, response.ID, response.TimeslotID));
                if (response.ID > 0)
                {
                    return(response.ID);
                }
            }
            catch (Exception ex)
            {
                if (!_loggedIn && pcErrorResponse.ErrorCode > 0)
                {
                    _fileLog.Write(LogMessageType.Error, "\n ExceptionMessage: " + pcErrorResponse.ExceptionMessage + "\n ErrorCode: " + pcErrorResponse.ErrorCode.ToString());
                }
                _fileLog.Write(LogMessageType.Error, ex.Message);
            }
            return(0);
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
0
        private void btnStartRun_Click_1(object sender, EventArgs e)
        {
            int testInstanceId = int.Parse(txtTestInstanceID.Text);
            PCTimeslotDuration timeslotDuration = new PCTimeslotDuration(30);
            string             postRunAction    = "Collate And Analyze";
            bool          vudsMode      = false;
            PCRunResponse pcRunResponse = pcRestProxy.StartRun(int.Parse(txtTestID.Text), testInstanceId, timeslotDuration, postRunAction, vudsMode);

            if (pcRunResponse != null)
            {
                List <PCRunResponse> pcRunResponseList = new List <PCRunResponse>();
                pcRunResponseList.Add(pcRunResponse);
                dgvForAll.DataSource  = pcRunResponseList;
                btnStartRun.Text      = "RunID " + pcRunResponse.ID + " created";
                btnStartRun.BackColor = Color.Green;
            }
            else
            {
                btnStartRun.Text      = "no run started";
                btnStartRun.BackColor = Color.Red;
            }
        }
Esempio n. 5
0
        public void Perform()
        {
            IPCClient pcClient = new PCClient(_pcModel, _fileLog);

            try
            {
                bool authenticated = pcClient.Login();
                int  runID;
                if (authenticated)
                {
                    runID = pcClient.StartRun();
                    if (runID == 0)
                    {
                        pcClient.Logout();
                        return;
                    }
                }
                else
                {
                    return;
                }

                string        testName      = pcClient.GetTestName();
                PCRunResponse pcRunResponse = null;
                if (runID > 0)
                {
                    pcRunResponse = pcClient.WaitForRunCompletion(runID);
                }

                if (pcRunResponse != null)
                {
                    //analysis report
                    string pcReportFile = (pcRunResponse.RunState == EnumerationHelper.GetEnumDescription(PCConstants.RunStates.Finished)) ? pcClient.PublishRunReport(runID, _workDirectory) : "";

                    // Adding the trend report section if ID has been set
                    if (_pcModel.GetAddRunToTrendReport.Equals("UseTrendReportID") && !string.IsNullOrWhiteSpace(_pcModel.TrendReportId) && pcRunResponse.RunState != EnumerationHelper.GetEnumDescription(PCConstants.RunStates.RunFailure))
                    {
                        bool addRunToTrendReportSuccess = pcClient.AddRunToTrendReport(runID, _pcModel.TrendReportId);
                        if (addRunToTrendReportSuccess)
                        {
                            pcClient.WaitForRunToPublishOnTrendReport(runID, _pcModel.TrendReportId);
                            pcClient.DownloadTrendReportAsPdf(_pcModel.TrendReportId, _workDirectory);
                        }
                    }

                    // Adding the trend report if the Associated Trend report is selected.
                    if (_pcModel.GetAddRunToTrendReport.Equals("AssociatedTrend") && pcRunResponse.RunState != EnumerationHelper.GetEnumDescription(PCConstants.RunStates.RunFailure))
                    {
                        bool addRunToTrendReportSuccess = pcClient.AddRunToTrendReport(runID, _pcModel.TrendReportId);
                        if (addRunToTrendReportSuccess)
                        {
                            pcClient.WaitForRunToPublishOnTrendReport(runID, _pcModel.TrendReportId);
                            pcClient.DownloadTrendReportAsPdf(_pcModel.TrendReportId, _workDirectory);
                        }
                    }
                    if (_statusBySLA && pcRunResponse.RunState == EnumerationHelper.GetEnumDescription(PCConstants.RunStates.Finished))
                    {
                        pcClient.verifySlaStatus(pcRunResponse.RunSLAStatus);
                    }
                }
                pcClient.Logout();
            }
            catch { }
            finally
            {
                //important ending to mark the end of the task for log report parsing!!
                pcClient.PCClientEnd();
            }
        }
Esempio n. 6
0
        public int StartRun()
        {
            PCErrorResponse pcErrorResponse = new PCErrorResponse("", 0);

            try
            {
                int testID       = int.Parse(_pcModel.TestId);
                int testInstance = GetCorrectTestInstanceID(testID);
                if (testInstance == 0)
                {
                    return(0);
                }
                SetCorrectTrendReportID();
                //if(_pcModel)
                string msg = string.Format("Executing Load Test:\n====================\nTest ID: {0} \nTest Instance ID: {1} \nTimeslot Duration: {2} \nPost Run Action: {3} \nUse VUDS: {4}\n====================\n",
                                           int.Parse(_pcModel.TestId), testInstance, _pcModel.PCTimeslotDuration, _pcModel.PCPostRunActionsRequest.PostRunAction, _pcModel.isVudsMode());
                _fileLog.Write(LogMessageType.Info, msg);


                PCRunResponse response = _pcRestProxy.StartRun(testID,
                                                               testInstance,
                                                               _pcModel.PCTimeslotDuration,
                                                               ref pcErrorResponse,
                                                               _pcModel.PCPostRunActionsRequest.PostRunAction,
                                                               _pcModel.isVudsMode());
                if (response == null && pcErrorResponse != null)
                {
                    _fileLog.Write(LogMessageType.Info, string.Format("{0}. {1}Code: {2}",
                                                                      pcErrorResponse.ExceptionMessage, !"RepeatWithParameters".Equals(_pcModel.TimeslotRepeat) ? "Error " : "", pcErrorResponse.ErrorCode));
                    if ("RepeatWithParameters".Equals(_pcModel.TimeslotRepeat))
                    {
                        int count = 1;
                        while (count < Int32.Parse(_pcModel.TimeslotRepeatAttempts) && response == null)
                        {
                            count++;
                            _fileLog.Write(LogMessageType.Info, string.Format("Repeating timeslot - Attempt # {0}. Waiting {1} minute(s) before trying once again to execute the test.", count, _pcModel.TimeslotRepeatDelay));
                            System.Threading.Thread.Sleep(Int32.Parse(_pcModel.TimeslotRepeatDelay) * 1000 * 60);
                            _fileLog.Write(LogMessageType.Info, string.Format("Repeating timeslot - Attempt # {0}. Executing the test:", count));
                            response = _pcRestProxy.StartRun(testID,
                                                             testInstance,
                                                             _pcModel.PCTimeslotDuration,
                                                             ref pcErrorResponse,
                                                             _pcModel.PCPostRunActionsRequest.PostRunAction,
                                                             _pcModel.isVudsMode());
                            if (response == null && pcErrorResponse != null)
                            {
                                _fileLog.Write(LogMessageType.Info, string.Format("Repeating timeslot - Attempt # {0}. Exception - {1}, Code: {2}.", count, pcErrorResponse.ExceptionMessage, pcErrorResponse.ErrorCode));
                                _fileLog.Write(LogMessageType.Info, string.Format("Repeating timeslot - Attempt # {0}. {1} remaining attempt(s).", count, Int32.Parse(_pcModel.TimeslotRepeatAttempts) - count));
                            }
                            if (count == Int32.Parse(_pcModel.TimeslotRepeatAttempts) && response == null)
                            {
                                _fileLog.Write(LogMessageType.Info, string.Format("All attempts to create a timeslot failed. Exception - {0}, Error Code: {1}.", pcErrorResponse.ExceptionMessage, pcErrorResponse.ErrorCode));
                            }
                        }
                    }
                    return(0);
                }
                _fileLog.Write(LogMessageType.Info, string.Format("Run started (TestID: {0}, RunID: {1}, TimeslotID: {2})\n",
                                                                  response.TestID, response.ID, response.TimeslotID));
                if (response.ID > 0)
                {
                    return(response.ID);
                }
            }
            catch (Exception ex)
            {
                if (!_loggedIn && pcErrorResponse.ErrorCode > 0)
                {
                    _fileLog.Write(LogMessageType.Error, "\n ExceptionMessage: " + pcErrorResponse.ExceptionMessage + "\n ErrorCode: " + pcErrorResponse.ErrorCode.ToString());
                }
                _fileLog.Write(LogMessageType.Error, ex.Message);
            }
            return(0);
        }