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); }
public void Run() { BauConsole.WriteHeader(); foreach (var task in this.topLevelTasks) { this.Invoke(task); } }
private IBauTask GetTask(string task) { try { return(this.tasks[task]); } catch (KeyNotFoundException ex) { BauConsole.WriteTaskNotFound(task); var message = string.Format(CultureInfo.InvariantCulture, "'{0}' task not found.", task); throw new InvalidOperationException(message, ex); } }
public ITaskBuilder DependsOn(params string[] otherTasks) { this.EnsureCurrentTask(); foreach (var task in otherTasks.Where(t => !this.currentTask.Dependencies.Contains(t))) { if (string.IsNullOrWhiteSpace(task)) { BauConsole.WriteInvalidTaskName(task); var message = string.Format(CultureInfo.InvariantCulture, "Invalid task name '{0}'.", task); throw new ArgumentException(message, "otherTasks"); } this.currentTask.Dependencies.Add(task); } return(this); }
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); }
public void Execute() { BauConsole.WriteExecuteDeprecated(); this.Run(); }