/// <summary> /// Evaluates whether this condition is valid. /// </summary> /// <param name="context">The context.</param> /// <returns> /// <c>true</c> if this instance is valid; <c>false</c> otherwise. /// </returns> public abstract bool Evaluate(TaskExecutionContext context);
/// <summary> /// Starts a new child context. /// </summary> /// <param name="task">The task.</param> /// <returns> /// The new child <see cref="TaskExecutionContext"/>. /// </returns> public virtual TaskExecutionContext StartChild(Task task) { logger.Debug("Starting new task execution context for '{0}'", task.NameOrType); var parameters = new TaskExecutionParameters { XmlWriter = this.writer, FileSystem = this.fileSystem, Clock = this.clock, IntegrationRequest = this.request, Project = this.project, BuildName = this.buildName }; var child = new TaskExecutionContext(parameters) { Parent = this, modificationsSets = this.modificationsSets, modificationsLock = this.modificationsLock }; this.writer.WriteStartElement("task"); if (!string.IsNullOrEmpty(task.Name)) { this.writer.WriteAttributeString("name", task.Name); } this.writer.WriteAttributeString("type", task.GetType().Name); writer.WriteElementString("start", this.clock.Now.ToString("s")); return child; }
/// <summary> /// Executes this task. /// </summary> /// <param name="context">The context.</param> /// <returns> /// The child tasks to execute. /// </returns> protected abstract IEnumerable<Task> OnRun(TaskExecutionContext context);
/// <summary> /// Called when this task has been skipped. /// </summary> /// <param name="context">The context.</param> protected virtual void OnSkip(TaskExecutionContext context) { }
/// <summary> /// Called when the task is being checked whether it can run. /// </summary> /// <param name="context">The context.</param> /// <returns> /// <c>true</c> if the task can run; <c>false</c> otherwise. /// </returns> protected virtual bool OnCanRun(TaskExecutionContext context) { var canExecute = true; foreach (var condition in this.Conditions ?? new TaskCondition[0]) { canExecute = condition.Evaluate(context); if (!canExecute) { break; } } return canExecute; }
/// <summary> /// Skips this instance. /// </summary> /// <param name="context">The context.</param> public virtual void Skip(TaskExecutionContext context) { var message = "Task '" + this.NameOrType + "' has been skipped"; context.AddEntryToBuildLog(message); logger.Debug(message); this.State = TaskState.Skipped; this.OnSkip(context); }
/// <summary> /// Runs this task. /// </summary> /// <param name="context">The context.</param> /// <returns>The child tasks to run.</returns> public virtual IEnumerable<Task> Run(TaskExecutionContext context) { var stopwatch = new Stopwatch(); stopwatch.Start(); logger.Debug("Running task '{0}'", this.NameOrType); this.State = TaskState.Executing; foreach (var task in this.OnRun(context) ?? new Task[0]) { yield return task; } stopwatch.Stop(); logger.Debug("Task '{0}' has completed in {1:#,##0.000}s", this.NameOrType, (double)stopwatch.ElapsedMilliseconds / 1000); this.State = TaskState.Completed; }
/// <summary> /// Determines whether this instance can run. /// </summary> /// <param name="context">The context.</param> /// <returns> /// <c>true</c> if this instance can run; otherwise, <c>false</c>. /// </returns> public bool CanRun(TaskExecutionContext context) { logger.Debug("Checking conditions for task '{0}'", this.NameOrType); this.State = TaskState.CheckingConditions; var canExecute = this.OnCanRun(context); return canExecute; }