Esempio n. 1
0
        /// <summary>
        /// Executes the task using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void Execute(ICakeContext context)
        {
            while (DelayedActions.Count > 0)
            {
                var delayedDelegate = DelayedActions.Dequeue();
                delayedDelegate();
            }

            var exceptions = new List <Exception>();

            foreach (var action in Actions)
            {
                try
                {
                    action(context);
                }
                catch (Exception e) when(DeferExceptions)
                {
                    exceptions.Add(e);
                }
            }

            if (exceptions.Any())
            {
                if (exceptions.Count == 1)
                {
                    throw exceptions.Single();
                }
                throw new AggregateException("Task failed with following exceptions", exceptions);
            }
        }