private void PerformTeardown(IExecutionStrategy strategy, ICakeContext context, Stopwatch stopWatch, CakeReport report, bool exceptionWasThrown, Exception thrownException) { stopWatch.Restart(); var teardownContext = new TeardownContext(context, thrownException); PublishEvent(Teardown, new TeardownEventArgs(teardownContext)); if (_actions.Teardown != null) { try { strategy.PerformTeardown(_actions.Teardown, teardownContext); } catch (Exception ex) { _log.Error("An error occurred in the custom teardown action."); if (!exceptionWasThrown) { // If no other exception was thrown, we throw this one. throw; } _log.Error("Teardown error: {0}", ex.ToString()); } finally { report.Add("**Teardown**", stopWatch.Elapsed); } } }
private void PerformSetup(IExecutionStrategy strategy, ICakeContext context, CakeTask targetTask, CakeTask[] tasks, Stopwatch stopWatch, CakeReport report) { stopWatch.Restart(); PublishEvent(BeforeSetup, new BeforeSetupEventArgs(context)); #pragma warning disable 618 PublishEvent(Setup, new SetupEventArgs(context)); #pragma warning restore 618 try { if (_actions.Setups.Count > 0) { foreach (var setup in _actions.Setups) { strategy.PerformSetup(setup, new SetupContext(context, targetTask, tasks)); } report.Add("Setup", CakeReportEntryCategory.Setup, stopWatch.Elapsed); } } finally { PublishEvent(AfterSetup, new AfterSetupEventArgs(context)); } }
private void PerformTeardown(IExecutionStrategy strategy, ICakeContext context, Stopwatch stopWatch, CakeReport report, bool exceptionWasThrown, Exception thrownException) { stopWatch.Restart(); var teardownContext = new TeardownContext(context, thrownException); PublishEvent(BeforeTeardown, new BeforeTeardownEventArgs(teardownContext)); #pragma warning disable 618 PublishEvent(Teardown, new TeardownEventArgs(teardownContext)); #pragma warning restore 618 try { if (_actions.Teardowns.Count > 0) { var exceptions = new List <Exception>(); try { foreach (var teardown in _actions.Teardowns) { try { strategy.PerformTeardown(teardown, teardownContext); } catch (Exception ex) { // No other exceptions were thrown and this is the only teardown? if (!exceptionWasThrown && _actions.Teardowns.Count == 1) { // If no other exception was thrown, we throw this one. // By doing this we preserve the original stack trace which is always nice. _log.Error("An error occurred in a custom teardown action."); throw; } // Add this exception to the list. exceptions.Add(ex); } } } finally { report.Add("Teardown", CakeReportEntryCategory.Teardown, stopWatch.Elapsed); } // If, any exceptions occurred, process them now. if (exceptions.Count > 0) { ProcessTeardownExceptions(exceptions, exceptionWasThrown); } } } finally { PublishEvent(AfterTeardown, new AfterTeardownEventArgs(teardownContext)); } }
private void ExecuteTask(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) { // Reset the stop watch. stopWatch.Reset(); stopWatch.Start(); PerformTaskSetup(context, strategy, task, false); bool exceptionWasThrown = false; try { // Execute the task. strategy.Execute(task, context); } catch (Exception exception) { _log.Error("An error occurred when executing task '{0}'.", task.Name); exceptionWasThrown = true; // Got an error reporter? if (task.ErrorReporter != null) { ReportErrors(strategy, task.ErrorReporter, exception); } // Got an error handler? if (task.ErrorHandler != null) { HandleErrors(strategy, task.ErrorHandler, exception); } else { // No error handler defined for this task. // Rethrow the exception and let it propagate. throw; } } finally { if (task.FinallyHandler != null) { strategy.InvokeFinally(task.FinallyHandler); } PerformTaskTeardown(context, strategy, task, stopWatch.Elapsed, false, exceptionWasThrown); } // Add the task results to the report if (IsDelegatedTask(task)) { report.AddDelegated(task.Name, stopWatch.Elapsed); } else { report.Add(task.Name, stopWatch.Elapsed); } }
private async Task ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) { stopWatch.Restart(); PerformTaskSetup(context, strategy, task, false); Exception taskException = null; try { // Execute the task. await strategy.ExecuteAsync(task, context).ConfigureAwait(false); } catch (Exception exception) { _log.Error("An error occurred when executing task '{0}'.", task.Name); taskException = exception; // Got an error reporter? if (task.ErrorReporter != null) { await ReportErrorsAsync(strategy, task.ErrorReporter, exception); } // Got an error handler? if (task.ErrorHandler != null) { await HandleErrorsAsync(strategy, task.ErrorHandler, exception, context); } else { // No error handler defined for this task. // Rethrow the exception and let it propagate. throw; } } finally { if (task.FinallyHandler != null) { await strategy.InvokeFinallyAsync(task.FinallyHandler); } PerformTaskTeardown(context, strategy, task, stopWatch.Elapsed, false, taskException); } // Add the task results to the report if (IsDelegatedTask(task)) { report.AddDelegated(task.Name, stopWatch.Elapsed); } else { report.Add(task.Name, CakeReportEntryCategory.Task, stopWatch.Elapsed); } }
private void PerformSetup(IExecutionStrategy strategy, ICakeContext context, CakeTask targetTask, IEnumerable <CakeTask> tasks, Stopwatch stopWatch, CakeReport report) { stopWatch.Restart(); PublishEvent(Setup, new SetupEventArgs(context)); if (_actions.Setup != null) { strategy.PerformSetup(_actions.Setup, new SetupContext(context, targetTask, tasks)); report.Add("**Setup**", stopWatch.Elapsed); } }
private void PerformSetup(IExecutionStrategy strategy, ICakeContext context, Stopwatch stopWatch, CakeReport report) { stopWatch.Restart(); PublishEvent(Setup, new SetupEventArgs(context)); if (_setupAction != null) { strategy.PerformSetup(_setupAction, context); report.Add("**Setup**", stopWatch.Elapsed); } }
private void PerformSetup(IExecutionStrategy strategy, ICakeContext context, CakeTask targetTask, CakeTask[] tasks, Stopwatch stopWatch, CakeReport report) { stopWatch.Restart(); PublishEvent(Setup, new SetupEventArgs(context)); if (_actions.Setups.Count > 0) { foreach (var setup in _actions.Setups) { strategy.PerformSetup(setup, new SetupContext(context, targetTask, tasks)); } report.Add("Setup", CakeReportEntryCategory.Setup, stopWatch.Elapsed); } }
private void ExecuteTask(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) { // Reset the stop watch. stopWatch.Reset(); stopWatch.Start(); try { // Execute the task. strategy.Execute(task, context); } catch (Exception exception) { _log.Error("An error occured when executing task.", task.Name); // Got an error reporter? if (task.ErrorReporter != null) { ReportErrors(strategy, task.ErrorReporter, exception); } // Got an error handler? if (task.ErrorHandler != null) { HandleErrors(strategy, task.ErrorHandler, exception); } else { // No error handler defined for this task. // Rethrow the exception and let it propagate. throw; } } finally { if (task.FinallyHandler != null) { strategy.InvokeFinally(task.FinallyHandler); } } // Add the task results to the report. report.Add(task.Name, stopWatch.Elapsed); }
private void ExecuteTask(Stopwatch stopWatch, CakeTask task, CakeReport report) { // Reset the stop watch. stopWatch.Reset(); stopWatch.Start(); try { // Execute the task. task.Execute(this); } catch (Exception ex) { _log.Error("An error occured in task {0}.", ex.Message); if (!task.ContinueOnError) { throw; } } // Add the task results to the report. report.Add(task.Name, stopWatch.Elapsed); }