private void TryOnError(IExperimentError error) { if (error == null) { throw new ArgumentNullException("error"); } CurrentState.CurrentStep = Operations.OnError; TryOp(() => { OnError(new ErrorEventArgs { Publisher = Publisher, State = CurrentState.Snapshot(), ExperimentError = error }); return(0); }); }
public StepFailedException(IExperimentError error) : base(string.Format("Step {0} failed", error.LastStep), error.LastException) { ExperimentError = error; }
private T RunControl(IExperimentResult <TPublish> results, out Exception controlException) { controlException = null; CurrentState.Name = ControlName; CurrentState.CurrentStep = Operations.Control; if (Steps.Control == null) { // Can there be valid experiments with no Control?? Dunno but seems restrictive to enfore it // if so, return default(T) instead of Exception return(default(T)); // Throw exception if we want to enforce having a Control //throw new InvalidOperationException( // "The Control was never set for this Experiment! Can't run an Experiment without a Control!"); } IExperimentError stepError = null; object context = null; T result = default(T); TPublish value = default(TPublish); try { context = TrySetContext(); CurrentState.Context = context; } catch (StepFailedException sfe) { stepError = sfe.ExperimentError; TryOnError(stepError); } try { TrySetup(); } catch (StepFailedException sfe) { stepError = sfe.ExperimentError; TryOnError(stepError); } var timer = new Stopwatch(); CurrentState.CurrentStep = Operations.Control; try { timer.Start(); result = Steps.Control(); timer.Stop(); } catch (Exception e) { timer.Stop(); controlException = e; //need to throw this at the end var error = new ExperimentError { LastException = e, LastStep = Operations.Control, ErrorMessage = "An Exception was thrown running the Control! Exception message: " + e.Message, ExperimentName = ControlName }; TryOnError(error);//TODO: Should we run OnError on Control?? results.Control = new Observation <TPublish> { ExperimentError = error, ElapsedMilliseconds = timer.ElapsedMilliseconds, Context = context, Name = ControlName, IsMismatched = false, ExceptionThrown = true }; return(result); } try { value = TryPrepare(result); } catch (StepFailedException sfe) { stepError = sfe.ExperimentError; TryOnError(stepError); //We must continue on because we've already gotten a result } try { TryTeardown(); } catch (StepFailedException sfe) { stepError = sfe.ExperimentError; TryOnError(stepError); } results.Control = new Observation <TPublish> { ElapsedMilliseconds = timer.ElapsedMilliseconds, Context = context, Name = ControlName, IsMismatched = false, //Control can't be mismatched ExceptionThrown = stepError != null, ExperimentError = stepError, Value = value }; return(result); }
public StepFailedException(IExperimentError error) : base(string.Format("Step {0} failed", error.LastStep), error.LastException) { ExperimentError = error; }