Exemplo n.º 1
0
        public ITaskBuilder Intern <TTask>(string name = null) where TTask : class, IBauTask, new()
        {
            name = name ?? DefaultTask;
            if (string.IsNullOrWhiteSpace(name))
            {
                BauConsole.WriteInvalidTaskName(name);
                var message = string.Format(CultureInfo.InvariantCulture, "Invalid task name '{0}'.", name);
                throw new ArgumentException(message, "name");
            }

            IBauTask task;

            if (!this.tasks.TryGetValue(name, out task))
            {
                this.tasks.Add(name, task = new TTask());
            }

            var typedTask = task as TTask;

            if (typedTask == null)
            {
                BauConsole.WriteTasksAlreadyExists(name, task.GetType().Name);
                var message = string.Format(
                    CultureInfo.InvariantCulture,
                    "'{0}' task already exists with type '{1}'.",
                    name,
                    task.GetType().Name);

                throw new InvalidOperationException(message);
            }

            this.currentTask = typedTask;
            return(this);
        }
Exemplo n.º 2
0
        private static void Execute(string task, IBauTask taskRef)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            BauConsole.WriteTaskStarting(task);

            try
            {
                taskRef.Execute();
            }
            catch (Exception ex)
            {
                BauConsole.WriteTaskFailed(task, stopwatch.Elapsed.TotalMilliseconds, ex.Message);
                var message = string.Format(CultureInfo.InvariantCulture, "'{0}' task failed. {1}", task, ex.Message);
                throw new InvalidOperationException(message, ex);
            }

            BauConsole.WriteTaskFinished(task, stopwatch.Elapsed.TotalMilliseconds);
        }