Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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)
                {
                    ReportErrors(strategy, task.ErrorReporter, exception);
                }

                // Got an error handler?
                if (task.ErrorHandler != null)
                {
                    HandleErrors(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)
                {
                    strategy.InvokeFinally(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);
            }
        }
Exemple #3
0
        private async Task ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, CancellationTokenSource cts, CakeTask task, CakeReport report)
        {
            _log.Verbose($"Starting task {task.Name}");
            var stopwatch = Stopwatch.StartNew();

            PerformTaskSetup(context, strategy, task, false);

            var execptionWasThrown = false;

            try
            {
                var taskExecutionContext = new TaskExecutionContext(context, task);

                await strategy.ExecuteAsync(task, taskExecutionContext).ConfigureAwait(false);
            }
            catch (TaskCanceledException)
            {
                execptionWasThrown = true;
                throw;
            }
            catch (Exception exception)
            {
                execptionWasThrown = true;
                _log.Error($"An error occurred when executing task '{task.Name}'.");

                if (task.ErrorReporter != null)
                {
                    ReportErrors(strategy, task.ErrorReporter, exception);
                }

                if (task.ErrorHandler != null)
                {
                    HandleErrors(strategy, task.ErrorHandler, exception);
                }
                else
                {
                    cts.Cancel();
                    throw;
                }
            }
            finally
            {
                strategy.InvokeFinally(task.FinallyHandler);

                PerformTaskTeardown(context, strategy, task, stopwatch.Elapsed, false, execptionWasThrown);
            }

            if (isDelegatedTask(task))
            {
                report.AddDelegated(task.Name, stopwatch.Elapsed);
            }
            else
            {
                report.Add(task.Name, stopwatch.Elapsed);
            }
        }
Exemple #4
0
        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);
        }
 /// <summary>
 /// Invokes the finally handler.
 /// </summary>
 /// <param name="action">The action.</param>
 public void InvokeFinally(Action action)
 {
     _default.InvokeFinally(action);
 }