From 23436daf1f1c74f455239c14a4c060e56a0e42d5 Mon Sep 17 00:00:00 2001 From: OBones Date: Mon, 9 Jan 2012 14:15:23 +0100 Subject: [PATCH 1/2] Issue 46: Allow modification of build status while the task is running so that it shows up in the web dashboard --- project/core/tasks/SequentialTask.cs | 40 +++++++++++++++++++ project/core/util/BuildProgressInformation.cs | 20 ++++++++++ 2 files changed, 60 insertions(+) diff --git a/project/core/tasks/SequentialTask.cs b/project/core/tasks/SequentialTask.cs index 65f526a6f..ac01d6540 100644 --- a/project/core/tasks/SequentialTask.cs +++ b/project/core/tasks/SequentialTask.cs @@ -68,6 +68,38 @@ public override ITask[] Tasks #endregion #endregion + private class _RunningSubTaskDetails + { + private int _Index; + private IIntegrationResult _ParentResult; + + public _RunningSubTaskDetails(int Index, IIntegrationResult ParentResult) + { + _Index = Index; + _ParentResult = ParentResult; + } + + public int Index { get { return _Index; } } + public IIntegrationResult ParentResult { get { return _ParentResult; } } + } + + private string _getStatusInformation(string runningSubTaskStartupInfo, _RunningSubTaskDetails Details) + { + string Value = !string.IsNullOrEmpty(Description) + ? Description + : string.Format("Running sequential tasks ({0} task(s))", Tasks.Length); + + if (Details != null) + Value += string.Format(": [{0}] {1}", + Details.Index, + !string.IsNullOrEmpty(runningSubTaskStartupInfo) + ? runningSubTaskStartupInfo + : "No information"); + + return Value; + } + + #region Protected methods #region Execute() /// @@ -95,6 +127,8 @@ protected override bool Execute(IIntegrationResult result) { // Start the actual task var taskResult = result.Clone(); + taskResult.BuildProgressInformation.OnStartupInformationUpdatedUserObject = new _RunningSubTaskDetails(loop, result); + taskResult.BuildProgressInformation.OnStartupInformationUpdated = SubTaskStartupInformationUpdated; var task = Tasks[loop]; RunTask(task, taskResult); result.Merge(taskResult); @@ -126,5 +160,11 @@ protected override bool Execute(IIntegrationResult result) } #endregion #endregion + + private void SubTaskStartupInformationUpdated(string information, object UserObject) + { + _RunningSubTaskDetails Details = (_RunningSubTaskDetails)UserObject; + Details.ParentResult.BuildProgressInformation.UpdateStartupInformation(_getStatusInformation(information, Details)); + } } } diff --git a/project/core/util/BuildProgressInformation.cs b/project/core/util/BuildProgressInformation.cs index 0719704b5..76482f63b 100644 --- a/project/core/util/BuildProgressInformation.cs +++ b/project/core/util/BuildProgressInformation.cs @@ -18,6 +18,15 @@ public class BuildProgressInformation private readonly object lockObject = new object(); private System.Collections.Generic.List Progress; private const Int32 MaxItemsInQueue = 10; + private OnStartupInformationUpdatedDelegate _OnStartupInformationUpdated = null; + + + private void DoStartupInformationUpdated(string information) + { + this._lastTimeQueried = DateTime.Now.AddYears(-10); + if (_OnStartupInformationUpdated != null) + OnStartupInformationUpdated(information, OnStartupInformationUpdatedUserObject); + } /// @@ -56,9 +65,13 @@ public virtual void SignalStartRunTask(string information) this._buildInformation = GetQueueDataAsXml(); this._lastTimeQueried = DateTime.Now.AddYears(-10); + DoStartupInformationUpdated(information); } } + public delegate void OnStartupInformationUpdatedDelegate(string information, object UserObject); + public OnStartupInformationUpdatedDelegate OnStartupInformationUpdated { get { return _OnStartupInformationUpdated; } set { _OnStartupInformationUpdated += value; } } + public object OnStartupInformationUpdatedUserObject { get; set; } /// /// Adds the task information. @@ -74,6 +87,13 @@ public virtual void AddTaskInformation(string information) } + public void UpdateStartupInformation(string information) + { + Progress[0] = new BuildProgressInformationData(information); + + DoStartupInformationUpdated(information); + } + /// /// Gets the build progress information. /// From fc30dedc51ca8496d89ac38817ccd745c4092a83 Mon Sep 17 00:00:00 2001 From: OBones Date: Mon, 9 Jan 2012 14:35:59 +0100 Subject: [PATCH 2/2] Better when using the same function everywhere --- project/core/tasks/SequentialTask.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/project/core/tasks/SequentialTask.cs b/project/core/tasks/SequentialTask.cs index ac01d6540..2ec79f1d7 100644 --- a/project/core/tasks/SequentialTask.cs +++ b/project/core/tasks/SequentialTask.cs @@ -111,9 +111,7 @@ protected override bool Execute(IIntegrationResult result) // Initialise the task var logger = Logger ?? new DefaultLogger(); var numberOfTasks = Tasks.Length; - result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) - ? Description - : string.Format(System.Globalization.CultureInfo.CurrentCulture,"Running sequential tasks ({0} task(s))", numberOfTasks)); + result.BuildProgressInformation.SignalStartRunTask(_getStatusInformation("", null)); logger.Info("Starting sequential task with {0} sub-task(s)", numberOfTasks); // Launch each task