private bool runScenario(string scenario, ref string errorReason, RunCancelledDelegate runCancelled)
        {
            cleanENV();

            ConsoleWriter.WriteLine(string.Format(Resources.LrInitScenario, scenario));

            //start controller
            _engine = new LrEngine();
            if (_engine == null)
            {
                errorReason = string.Format(Resources.LrFailToOpenController, scenario);
                return(false);
            }

            //try to register the end scenario event:
            _scenarioEndedEvent = false;
            try
            {
                _engine.Events.ScenarioEvents.OnScenarioEnded += ScenarioEvents_OnScenarioEnded;
                _scenarioEndedEvent = true;
            }
            catch (Exception e)
            {
                ConsoleWriter.WriteException(Resources.LrFailToRegisterEndScenarioEvent, e);
                _scenarioEndedEvent = false;
            }

            _engine.ShowMainWindow(0);
#if DEBUG
            _engine.ShowMainWindow(1);
#endif
            //pointer to the scenario object:
            LrScenario currentScenario = _engine.Scenario;

            //try to open the scenario and validate the scenario and connect to load generators
            if (openScenario(scenario, ref errorReason) && validateScenario(currentScenario, ref errorReason))
            {
                //set the result dir:
                ConsoleWriter.WriteLine("setting scenario result folder to " + Path.Combine(_resultsFolder, LRR_FOLDER));
                currentScenario.ResultDir = Path.Combine(_resultsFolder, LRR_FOLDER);
                ConsoleWriter.WriteLine("scenario result folder: " + currentScenario.ResultDir);

                //check if canceled or timedOut:
                if (_runCancelled())
                {
                    errorReason = Resources.GeneralTimedOut;
                    return(false);
                }

                _scenarioEnded = false;

                ConsoleWriter.WriteLine(Resources.LrStartScenario);

                int ret = currentScenario.Start();

                if (!currentScenario.ResultDir.Equals(Path.Combine(_resultsFolder, LRR_FOLDER)))
                {
                    ConsoleWriter.WriteLine("controller failed to write to " + Path.Combine(_resultsFolder, LRR_FOLDER) + " setting result folder to " + currentScenario.ResultDir);
                    _controller_result_dir = new DirectoryInfo(currentScenario.ResultDir).Name;
                    ConsoleWriter.WriteLine("controller reult dir: " + _controller_result_dir);
                }


                if (ret != 0)
                {
                    errorReason = string.Format(Resources.LrStartScenarioFail, scenario, ret);
                    return(false);
                }
                //per scenario timeout stopwatch
                _stopWatch = Stopwatch.StartNew();
                //wait for scenario to end:
                if (!waitForScenario(ref errorReason))
                {
                    //something went wrong during scenario execution, error reason set in errorReason string
                    return(false);
                }
                else
                {//scenario has ended
                    Console.WriteLine(string.Format(Resources.LrScenarioEnded, scenario, _stopWatch.Elapsed.Hours, _stopWatch.Elapsed.Minutes, _stopWatch.Elapsed.Seconds));

                    //collate results
                    collateResults();
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool runScenario(string scenario, ref string errorReason, RunCancelledDelegate runCancelled)
        {
            cleanENV();

            ConsoleWriter.WriteLine(string.Format(Resources.LrInitScenario, scenario));

            //start controller
            _engine = new LrEngine();
            if (_engine == null)
            {
                errorReason = string.Format(Resources.LrFailToOpenController, scenario);
                return(false);
            }

            //try to register the end scenario event:
            _scenarioEndedEvent = false;
            try
            {
                _engine.Events.ScenarioEvents.OnScenarioEnded += ScenarioEvents_OnScenarioEnded;
                _scenarioEndedEvent = true;
            }
            catch (Exception e)
            {
                ConsoleWriter.WriteException(Resources.LrFailToRegisterEndScenarioEvent, e);
                _scenarioEndedEvent = false;
            }


            if (_displayController == true)
            {
                _engine.ShowMainWindow(1);
            }
            else
            {
                _engine.ShowMainWindow(0);
            }

            //pointer to the scenario object:
            LrScenario currentScenario = _engine.Scenario;

            //try to open the scenario and validate the scenario and connect to load generators
            if (openScenario(scenario, ref errorReason) && validateScenario(currentScenario, ref errorReason))
            {
                //apply rts to scripts
                foreach (ScriptRTSModel scriptRTS in _scriptRTSSet)
                {
                    try
                    {
                        LrScripts currentScripts  = currentScenario.Scripts;
                        LrScript  currentScript   = currentScripts.Item[scriptRTS.GetScriptName()];
                        string    runtimeSettings = "",
                                  actionLogic     = "";
                        currentScript.GetScriptRunTimeSettings(ref runtimeSettings, ref actionLogic);
                        RTSHelper rtsHelper = new RTSHelper(runtimeSettings, RTSHelper.COMMAND_ARGUMENTS, scriptRTS.GetKeyValuePairs());
                        string    updatedRuntimeSettings = rtsHelper.GetUpdatedIniFileText();
                        currentScript.SetScriptRunTimeSettings(updatedRuntimeSettings, actionLogic);
                    }
                    catch (Exception e)
                    {
                        errorReason = string.Format(Resources.LrRTSError, scriptRTS.GetScriptName(), e.Message);
                        return(false);
                    }
                }

                //set the result dir:
                ConsoleWriter.WriteLine("setting scenario result folder to " + Path.Combine(_resultsFolder, LRR_FOLDER));
                currentScenario.ResultDir = Path.Combine(_resultsFolder, LRR_FOLDER);
                ConsoleWriter.WriteLine("scenario result folder: " + currentScenario.ResultDir);

                //check if canceled or timedOut:
                if (_runCancelled())
                {
                    errorReason = Resources.GeneralTimedOut;
                    return(false);
                }

                _scenarioEnded = false;

                ConsoleWriter.WriteLine(Resources.LrStartScenario);

                int ret = currentScenario.Start();

                if (!currentScenario.ResultDir.Equals(Path.Combine(_resultsFolder, LRR_FOLDER)))
                {
                    ConsoleWriter.WriteLine("controller failed to write to " + Path.Combine(_resultsFolder, LRR_FOLDER) + " setting result folder to " + currentScenario.ResultDir);
                    _controller_result_dir = new DirectoryInfo(currentScenario.ResultDir).Name;
                    ConsoleWriter.WriteLine("controller reult dir: " + _controller_result_dir);
                }


                if (ret != 0)
                {
                    errorReason = string.Format(Resources.LrStartScenarioFail, scenario, ret);
                    return(false);
                }
                //per scenario timeout stopwatch
                _stopWatch = Stopwatch.StartNew();
                //wait for scenario to end:
                if (!waitForScenario(ref errorReason))
                {
                    //something went wrong during scenario execution, error reason set in errorReason string
                    return(false);
                }
                else
                {//scenario has ended
                    Console.WriteLine(string.Format(Resources.LrScenarioEnded, scenario, _stopWatch.Elapsed.Hours, _stopWatch.Elapsed.Minutes, _stopWatch.Elapsed.Seconds));

                    //collate results
                    collateResults();
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
        private bool runScenario(string scenario, ref string errorReason, RunCancelledDelegate runCancelled)
        {
            cleanENV();

            ConsoleWriter.WriteLine(string.Format(Resources.LrInitScenario, scenario));

            //start controller
            _engine = new LrEngine();
            if (_engine == null)
            {
                errorReason = string.Format(Resources.LrFailToOpenController, scenario);
                return false;
            }

            //try to register the end scenario event:
            _scenarioEndedEvent = false;
            try
            {
                _engine.Events.ScenarioEvents.OnScenarioEnded += ScenarioEvents_OnScenarioEnded;
                _scenarioEndedEvent = true;
            }
            catch (Exception e)
            {
                ConsoleWriter.WriteException(Resources.LrFailToRegisterEndScenarioEvent, e);
                _scenarioEndedEvent = false;
            }

            _engine.ShowMainWindow(0);
#if DEBUG
            _engine.ShowMainWindow(1);
#endif
            //pointer to the scenario object:
            LrScenario currentScenario = _engine.Scenario;

            //try to open the scenario and validate the scenario and connect to load generators
            if (openScenario(scenario, ref errorReason) && validateScenario(currentScenario, ref errorReason))
            {
                //set the result dir:
                ConsoleWriter.WriteLine("setting scenario result folder to " + Path.Combine(_resultsFolder, LRR_FOLDER));
                currentScenario.ResultDir = Path.Combine(_resultsFolder, LRR_FOLDER);
                ConsoleWriter.WriteLine("scenario result folder: " + currentScenario.ResultDir);

                //check if canceled or timedOut:
                if (_runCancelled())
                {
                    errorReason = Resources.GeneralTimedOut;
                    return false;
                }

                _scenarioEnded = false;

                ConsoleWriter.WriteLine(Resources.LrStartScenario);

                int ret = currentScenario.Start();

                if (!currentScenario.ResultDir.Equals(Path.Combine(_resultsFolder, LRR_FOLDER)))
                {
                    ConsoleWriter.WriteLine("controller failed to write to " + Path.Combine(_resultsFolder, LRR_FOLDER) + " setting result folder to " + currentScenario.ResultDir);
                    _controller_result_dir = new DirectoryInfo(currentScenario.ResultDir).Name;
                    ConsoleWriter.WriteLine("controller reult dir: " + _controller_result_dir);
                }
                

                if (ret != 0)
                {
                    errorReason = string.Format(Resources.LrStartScenarioFail, scenario, ret);
                    return false;
                }
                //per scenario timeout stopwatch
                _stopWatch = Stopwatch.StartNew();

                //wait for scenario to end:
                if (!waitForScenario(ref errorReason))
                {
                    //something went wrong during scenario execution, error reason set in errorReason string
                    return false;
                }
                else
                {//scenario has ended
                    Console.WriteLine(string.Format(Resources.LrScenarioEnded, scenario,_stopWatch.Elapsed.Hours,_stopWatch.Elapsed.Minutes, _stopWatch.Elapsed.Seconds));

                    //collate results
                    collateResults();
                }
            }
            else
            {
                return false;
            }

            return true;
        }