private void internalExecution(IScriptRunner scriptRunner) { Step step = null; bool stepWithError = false; scriptWithErrors = false; try { if (!scriptRunner.ScriptStarting(this)) throw new Exception("Script runner decided NOT to start executing this script."); if (ScriptStarting != null) ScriptStarting(this); for (int stepIndex = 0; stepIndex < steps.Count; stepIndex++) { stepWithError = false; step = steps[stepIndex]; try { scriptRunner.BeforeStepRun(step); if (StepStarting != null) StepStarting(step); if (scriptRunner.StepRun(step)) { if (StepFinished != null) StepFinished(step); } else { if (StepSkipped != null) StepSkipped(step); if (step.Required) throw new RequiredStepNotExecutedException(step); } } catch (RequiredStepNotExecutedException) { // Can't continue with script execution if a required step was not executed. throw; } catch (Exception exception) { scriptWithErrors = true; stepWithError = true; scriptRunner.StepError(step, exception); if (StepError != null) StepError(step, exception); if (step.Required) throw new RequiredStepNotExecutedException(step); } finally { scriptRunner.AfterStepRun(step, stepWithError); } } } catch (Exception exception) { scriptWithErrors = true; scriptRunner.ScriptError(this, exception); if (ScriptError != null) ScriptError(this, exception); } finally { scriptRunner.ScriptFinished(this, scriptWithErrors); if (ScriptFinished != null) ScriptFinished(this, scriptWithErrors); } }