Esempio n. 1
0
        private async Task InvokeAsync(TInput input, bool dryRun, Logger log)
        {
            await log.Starting(this.Name, input).ConfigureAwait(false);

            var stopWatch = Stopwatch.StartNew();

            if (!dryRun)
            {
                try
                {
                    if (this.action != default)
                    {
                        await this.action(input).ConfigureAwait(false);
                    }
                }
                catch (Exception ex)
                {
                    await log.Failed(this.Name, input, ex, stopWatch.Elapsed.TotalMilliseconds).ConfigureAwait(false);

                    throw;
                }
            }

            await log.Succeeded(this.Name, input, stopWatch.Elapsed.TotalMilliseconds).ConfigureAwait(false);
        }
Esempio n. 2
0
        private async Task InvokeAsync(TInput input, bool dryRun, Logger log, Func <Exception, bool> messageOnly)
        {
            await log.Starting(this.Name, input).Tax();

            var stopWatch = Stopwatch.StartNew();

            if (!dryRun && this.action != default)
            {
                try
                {
                    await this.action(input).Tax();
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex)
                {
                    if (!messageOnly(ex))
                    {
                        await log.Error(this.Name, input, ex).Tax();
                    }

                    await log.Failed(this.Name, input, ex, stopWatch.Elapsed.TotalMilliseconds).Tax();

                    throw new TargetFailedException(ex);
                }
#pragma warning restore CA1031 // Do not catch general exception types
            }

            await log.Succeeded(this.Name, input, stopWatch.Elapsed.TotalMilliseconds).Tax();
        }
Esempio n. 3
0
        private async Task InvokeAsync(TInput input, bool dryRun, Logger log, Func <Exception, bool> messageOnly)
        {
            await log.Starting(this.Name, input).ConfigureAwait(false);

            var stopWatch = Stopwatch.StartNew();

            if (!dryRun && this.action != default)
            {
                try
                {
                    await this.action(input).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    if (!messageOnly(ex))
                    {
                        await log.Error(this.Name, input, ex).ConfigureAwait(false);
                    }

                    await log.Failed(this.Name, input, ex, stopWatch.Elapsed.TotalMilliseconds).ConfigureAwait(false);

                    throw new TargetFailedException(ex);
                }
            }

            await log.Succeeded(this.Name, input, stopWatch.Elapsed.TotalMilliseconds).ConfigureAwait(false);
        }
Esempio n. 4
0
        public override async Task RunAsync(bool dryRun, bool parallel, Logger log, Func <Exception, bool> messageOnly)
        {
            var inputsList = this.inputs.ToList();

            if (inputsList.Count == 0)
            {
                await log.NoInputs(this.Name).Tax();

                return;
            }

            await log.Starting(this.Name).Tax();

            var stopWatch = Stopwatch.StartNew();

            try
            {
                if (parallel)
                {
                    var tasks = inputsList.Select(input => this.InvokeAsync(input, dryRun, log, messageOnly)).ToList();
                    await Task.WhenAll(tasks).Tax();
                }
                else
                {
                    foreach (var input in inputsList)
                    {
                        await this.InvokeAsync(input, dryRun, log, messageOnly).Tax();
                    }
                }
            }
            catch (Exception)
            {
                await log.Failed(this.Name, stopWatch.Elapsed.TotalMilliseconds).Tax();

                throw;
            }

            await log.Succeeded(this.Name, stopWatch.Elapsed.TotalMilliseconds).Tax();
        }
Esempio n. 5
0
        public async Task RunAsync(List <string> names, bool skipDependencies, bool dryRun, bool parallel, Logger log, Func <Exception, bool> messageOnly)
        {
            await log.Running(names).ConfigureAwait(false);

            var stopWatch = Stopwatch.StartNew();

            try
            {
                if (!skipDependencies)
                {
                    this.ValidateDependenciesAreAllDefined();
                }

                this.ValidateTargetGraphIsCycleFree();
                this.Validate(names);

                var targetsRan = new ConcurrentDictionary <string, Task>();
                if (parallel)
                {
                    var tasks = names.Select(name => this.RunAsync(name, names, skipDependencies, dryRun, true, targetsRan, log, messageOnly, new Stack <string>()));
                    await Task.WhenAll(tasks).ConfigureAwait(false);
                }
                else
                {
                    foreach (var name in names)
                    {
                        await this.RunAsync(name, names, skipDependencies, dryRun, false, targetsRan, log, messageOnly, new Stack <string>()).ConfigureAwait(false);
                    }
                }
            }
            catch (Exception)
            {
                await log.Failed(names, stopWatch.Elapsed.TotalMilliseconds).ConfigureAwait(false);

                throw;
            }

            await log.Succeeded(names, stopWatch.Elapsed.TotalMilliseconds).ConfigureAwait(false);
        }
        private async Task RunAsync(TInput input, bool dryRun, Logger log, Func <Exception, bool> messageOnly)
        {
            var id = Guid.NewGuid();
            await log.Starting(this.Name, input, id).Tax();

            TimeSpan?duration = null;

            if (!dryRun && this.action != null)
            {
                try
                {
                    var stopWatch = Stopwatch.StartNew();

                    try
                    {
                        await this.action(input).Tax();
                    }
                    finally
                    {
                        duration = stopWatch.Elapsed;
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    if (!messageOnly(ex))
                    {
                        await log.Error(this.Name, input, ex).Tax();
                    }

                    await log.Failed(this.Name, input, ex, duration, id).Tax();

                    throw new TargetFailedException($"Target '{this.Name}' failed with input '{input}'.", ex);
                }
            }

            await log.Succeeded(this.Name, input, duration, id).Tax();
        }
Esempio n. 7
0
        public async Task RunAsync(List <string> names, bool skipDependencies, bool dryRun, bool parallel, Logger log, Func <Exception, bool> messageOnly)
        {
            if (!skipDependencies)
            {
                this.CheckForMissingDependencies();
            }

            this.CheckForCircularDependencies();
            this.Check(names);

            await log.Starting(names).Tax();

            try
            {
                var runningTargets = new ConcurrentDictionary <string, Task>();
                if (parallel)
                {
                    var tasks = names.Select(name => this.RunAsync(name, names, skipDependencies, dryRun, true, log, messageOnly, runningTargets, new Stack <string>()));
                    await Task.WhenAll(tasks).Tax();
                }
                else
                {
                    foreach (var name in names)
                    {
                        await this.RunAsync(name, names, skipDependencies, dryRun, false, log, messageOnly, runningTargets, new Stack <string>()).Tax();
                    }
                }
            }
            catch (Exception)
            {
                await log.Failed(names).Tax();

                throw;
            }

            await log.Succeeded(names).Tax();
        }
Esempio n. 8
0
 public virtual Task RunAsync(bool dryRun, bool parallel, Logger log) => log.Succeeded(this.Name, null);
Esempio n. 9
0
 public virtual Task RunAsync(bool dryRun, bool parallel, Logger log, Func <Exception, bool> messageOnly) => log.Succeeded(this.Name, null);