public void AllPropertiesCanBeSetAndRetrieved() { var item = new ItemStatus(); var theName = "myItemName"; var theDesc = "A description"; var theError = "any error here"; var theStatus = ItemBuildStatus.CompletedFailed; var startTime = new DateTime(2010, 1, 1, 12, 12, 12); var completedTime = new DateTime(2010, 1, 1, 13, 12, 12); var estimatedTime = new DateTime(2010, 1, 1, 14, 12, 12); var theParent = new ItemStatus(); item.Name = theName; item.Description = theDesc; item.Error = theError; item.Status = theStatus; item.TimeStarted = startTime; item.TimeCompleted = completedTime; item.TimeOfEstimatedCompletion = estimatedTime; item.Parent = theParent; Assert.AreEqual(theName, item.Name); Assert.AreEqual(theDesc, item.Description); Assert.AreEqual(theError, item.Error); Assert.AreEqual(theStatus, item.Status); Assert.AreEqual(startTime, item.TimeStarted); Assert.AreEqual(completedTime, item.TimeCompleted); Assert.AreEqual(estimatedTime, item.TimeOfEstimatedCompletion); Assert.AreEqual(theParent, item.Parent); Assert.AreNotEqual(item.Identifier, item.Parent.Identifier); }
public void CloneGeneratesANewIdenticialInstance() { var item = new ItemStatus(); var theName = "myItemName"; var theDesc = "A description"; var theError = "any error here"; var theStatus = ItemBuildStatus.CompletedFailed; var startTime = new DateTime(2010, 1, 1, 12, 12, 12); var completedTime = new DateTime(2010, 1, 1, 13, 12, 12); var estimatedTime = new DateTime(2010, 1, 1, 14, 12, 12); var aChild = new ItemStatus("aChild"); item.Name = theName; item.Description = theDesc; item.Error = theError; item.Status = theStatus; item.TimeStarted = startTime; item.TimeCompleted = completedTime; item.TimeOfEstimatedCompletion = estimatedTime; item.ChildItems.Add(aChild); var clone = item.Clone(); Assert.AreEqual(theName, clone.Name); Assert.AreEqual(theDesc, clone.Description); Assert.AreEqual(theError, clone.Error); Assert.AreEqual(theStatus, clone.Status); Assert.AreEqual(startTime, clone.TimeStarted); Assert.AreEqual(completedTime, clone.TimeCompleted); Assert.AreEqual(estimatedTime, clone.TimeOfEstimatedCompletion); Assert.AreEqual(item.Identifier, clone.Identifier); Assert.AreEqual(1, clone.ChildItems.Count); Assert.AreEqual("aChild", clone.ChildItems[0].Name); Assert.AreEqual(aChild.Identifier, clone.ChildItems[0].Identifier); }
/// <summary> /// Generates a clone of this status. /// </summary> /// <returns></returns> public virtual ItemStatus Clone() { ItemStatus clone = new ItemStatus(); CopyTo(clone); return(clone); }
/// <summary> /// Simple method to convert am item status to JSON (since we're not using .NET 3.5). /// </summary> /// <param name="status">The status to convert.</param> /// <returns></returns> private string ConvertStatusToJson(ItemStatus status) { var jsonText = new StringBuilder(); jsonText.Append("{"); AppendStatusDetails(status, jsonText); jsonText.Append("}"); return jsonText.ToString(); }
/// <summary> /// Copies this item to another. /// </summary> /// <param name="value"></param> public virtual void CopyTo(ItemStatus value) { value.identifier = this.identifier; value.description = this.description; value.name = this.name; value.status = this.status; value.Error = this.Error; value.timeCompleted = this.timeCompleted; value.timeOfEstimatedCompletion = this.timeOfEstimatedCompletion; value.timeStarted = this.timeStarted; foreach (ItemStatus item in this.childItems) { value.AddChild(item.Clone()); } ; }
/// <summary> /// Initialise an <see cref="ItemStatus"/>. /// </summary> /// <param name="newStatus">The new status.</param> public override void InitialiseStatus(ItemBuildStatus newStatus) { // Do not re-initialise if the status is already set if ((this.CurrentStatus == null) || (this.CurrentStatus.Status != newStatus)) { // This needs to be called first, otherwise the status is not set up taskStatuses.Clear(); base.InitialiseStatus(newStatus); // Add each status if (Tasks != null) { foreach (ITask task in Tasks) { ItemStatus taskItem = null; if (task is TaskBase) { // Reset the status for the task (task as TaskBase).InitialiseStatus(newStatus); } if (task is IStatusSnapshotGenerator) { taskItem = (task as IStatusSnapshotGenerator).GenerateSnapshot(); } else { taskItem = new ItemStatus(task.GetType().Name); taskItem.Status = newStatus; } // Only add the item if it has been initialised if (taskItem != null) { CurrentStatus.AddChild(taskItem); taskStatuses.Add(task, taskItem); } } } } }
/// <summary> /// Simple method to append status information to a builder /// </summary> /// <param name="status">The status to append.</param> /// <param name="builder">The builder to append the details to.</param> private void AppendStatusDetails(ItemStatus status, StringBuilder builder) { builder.AppendFormat("id:'{0}'", status.Identifier); builder.AppendFormat(",name:'{0}'", ToJsonString(status.Name)); builder.AppendFormat(",status:'{0}'", status.Status); if (!string.IsNullOrEmpty(status.Description)) builder.AppendFormat(",description:'{0}'", ToJsonString(status.Description)); if (status.TimeStarted.HasValue) builder.AppendFormat(",started:{0}", ToJsonDate(status.TimeStarted.Value)); if (status.TimeCompleted.HasValue) builder.AppendFormat(",completed:{0}", ToJsonDate(status.TimeCompleted.Value)); if (status.TimeOfEstimatedCompletion.HasValue) builder.AppendFormat(",estimated:{0}", ToJsonDate(status.TimeOfEstimatedCompletion.Value)); if (status.ChildItems.Count > 0) { builder.Append(",children:["); int count = 0; foreach (ItemStatus child in status.ChildItems) { if (count++ > 0) builder.Append(","); builder.Append(ConvertStatusToJson(child)); } builder.Append("]"); } }
/// <summary> /// Converts the specified status. /// </summary> /// <param name="status">The status.</param> /// <returns> /// The summary. /// </returns> private static TaskSummary Convert(ItemStatus status) { var model = new TaskSummary { Description = status.Description, Name = status.Name, Tasks = status.ChildItems.Any() ? status.ToModel() : null, Status = Convert(status.Status), Error = status.Error }; if (status.TimeStarted.HasValue || status.TimeCompleted.HasValue) { model.Times = new TaskSummaryTimes { Started = status.TimeStarted, Completed = status.TimeCompleted }; } return model; }
/// <summary> /// Stores a snapshot of a project build. /// </summary> /// <param name="result">The result that the snapshot is for.</param> /// <param name="snapshot">The project snapshot.</param> public void StoreProjectSnapshot(IIntegrationResult result, ItemStatus snapshot) { var dirPath = this.RootFolder(result.ArtifactDirectory, this.SnapshotsFolder); Log.Info("Writing snapshot (XML) to [" + dirPath + "]"); var logFile = new LogFile(result); var filePath = Path.ChangeExtension( Path.Combine(dirPath, logFile.Filename), "snapshot"); this.FileSystem.EnsureFolderExists(filePath); Log.Debug("Creating new snapshot (XML) [" + filePath + "]"); using (var stream = this.FileSystem.OpenOutputStream(filePath)) { using (var writer = new StreamWriter(stream)) { Log.Debug("Writing snapshot (XML)"); writer.Write(snapshot.ToString()); Log.Debug("Snapshot (XML) written"); } } }
public void ToStringGeneratesXml() { var item = new ItemStatus(); var theName = "myItemName"; var theDesc = "A description"; var theError = "any error here"; var theStatus = ItemBuildStatus.CompletedFailed; var startTime = new DateTime(2010, 1, 1, 12, 12, 12); var completedTime = new DateTime(2010, 1, 1, 13, 12, 12); var estimatedTime = new DateTime(2010, 1, 1, 14, 12, 12); var aChild = new ItemStatus("aChild"); item.Name = theName; item.Description = theDesc; item.Error = theError; item.Status = theStatus; item.TimeStarted = startTime; item.TimeCompleted = completedTime; item.TimeOfEstimatedCompletion = estimatedTime; item.ChildItems.Add(aChild); var xml = item.ToString(); var expected = "<itemStatus xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" name=\"myItemName\" status=\"CompletedFailed\">" + "<description>A description</description>" + "<error>any error here</error>" + "<timeStarted>2010-01-01T12:12:12</timeStarted>" + "<timeCompleted>2010-01-01T13:12:12</timeCompleted>" + "<timeOfEstimatedCompletion>2010-01-01T14:12:12</timeOfEstimatedCompletion>" + "<childItems>" + "<childItem name=\"aChild\" status=\"Unknown\">" + "<timeStarted xsi:nil=\"true\" />" + "<timeCompleted xsi:nil=\"true\" />" + "<timeOfEstimatedCompletion xsi:nil=\"true\" />" + "<childItems />" + "</childItem>" + "</childItems>" + "</itemStatus>"; Assert.AreEqual(expected, xml); }
public void ConstructorSetsName() { var item = new ItemStatus("theName"); Assert.AreEqual("theName", item.Name); }
/// <summary> /// Adds a child and correctly links it. /// </summary> /// <param name="child"></param> public void AddChild(ItemStatus child) { child.parent = this; childItems.Add(child); }
/// <summary> /// Copies this item to another. /// </summary> /// <param name="value"></param> public virtual void CopyTo(ItemStatus value) { value.identifier = this.identifier; value.description = this.description; value.name = this.name; value.status = this.status; value.Error = this.Error; value.timeCompleted = this.timeCompleted; value.timeOfEstimatedCompletion = this.timeOfEstimatedCompletion; value.timeStarted = this.timeStarted; foreach (ItemStatus item in this.childItems) { value.AddChild(item.Clone()); }; }
/// <summary> /// Generates a clone of this status. /// </summary> /// <returns></returns> public virtual ItemStatus Clone() { ItemStatus clone = new ItemStatus(); CopyTo(clone); return clone; }
/// <summary> /// Adds a child and correctly links it. /// </summary> /// <param name="child"></param> public void AddChild(ItemStatus child) { child.parent = this; childItems.Add(child); }
public void GetHashCodeReturnsHashOfIdentifier() { var item = new ItemStatus(); var hash = item.GetHashCode(); Assert.AreEqual(item.Identifier.GetHashCode(), hash); }
public void EqualsReturnsFalseForNonItemStatus() { var item1 = new ItemStatus(); var item2 = "This is a test"; Assert.IsFalse(item1.Equals(item2)); }
public void PassThroughSerialisation() { TestHelpers.EnsureLanguageIsValid(); var item = new ItemStatus(); var theName = "myItemName"; var theDesc = "A description"; var theError = "any error here"; var theStatus = ItemBuildStatus.CompletedFailed; var startTime = new DateTime(2010, 1, 1, 12, 12, 12); var completedTime = new DateTime(2010, 1, 1, 13, 12, 12); var estimatedTime = new DateTime(2010, 1, 1, 14, 12, 12); var aChild = new ItemStatus("aChild"); item.Name = theName; item.Description = theDesc; item.Error = theError; item.Status = theStatus; item.TimeStarted = startTime; item.TimeCompleted = completedTime; item.TimeOfEstimatedCompletion = estimatedTime; item.ChildItems.Add(aChild); var result = TestHelpers.RunSerialisationTest(item); Assert.IsNotNull(result); Assert.IsInstanceOf<ItemStatus>(result); var actualStatus = result as ItemStatus; Assert.AreEqual(theName, actualStatus.Name); Assert.AreEqual(theDesc, actualStatus.Description); Assert.AreEqual(theError, actualStatus.Error); Assert.AreEqual(theStatus, actualStatus.Status); Assert.AreEqual(startTime, actualStatus.TimeStarted); Assert.AreEqual(completedTime, actualStatus.TimeCompleted); Assert.AreEqual(estimatedTime, actualStatus.TimeOfEstimatedCompletion); Assert.AreEqual(item.Identifier, actualStatus.Identifier); Assert.AreEqual(1, actualStatus.ChildItems.Count); Assert.AreEqual("aChild", actualStatus.ChildItems[0].Name); Assert.AreEqual(aChild.Identifier, actualStatus.ChildItems[0].Identifier); }
private void DisplayStatusItem(ItemStatus status) { statusDetails.SelectedObject = new StatusItemDisplay(status); int progress = 0; Color color = Color.Gray; // Calculate the progress bar switch (status.Status) { case ItemBuildStatus.CompletedSuccess: progress = 100; color = Color.Green; break; case ItemBuildStatus.CompletedFailed: progress = 100; color = Color.Red; break; case ItemBuildStatus.Cancelled: progress = 100; break; case ItemBuildStatus.Running: // TODO: Caculdate the progress percentage progress = 50; break; } // Update the progress bar statusProgress.Value = (progress > 100) ? 100 : progress; statusProgress.ForeColor = color; }
public StatusItemDisplay(ItemStatus value) { this.item = value; }
/// <summary> /// Initialises the task statuses. /// </summary> /// <param name="newStatus">The new status.</param> /// <param name="tasks">The tasks.</param> /// <param name="taskStatuses">The task statuses.</param> /// <param name="title">The title.</param> /// <returns></returns> private ItemStatus InitialiseTaskStatuses( ItemBuildStatus newStatus, ITask[] tasks, Dictionary<ITask, ItemStatus> taskStatuses, string title) { var groupStatus = new ItemStatus { Name = title, Status = newStatus, TimeCompleted = null, TimeOfEstimatedCompletion = null, TimeStarted = null }; this.CurrentStatus.AddChild(groupStatus); if (tasks != null) { foreach (var task in tasks) { ItemStatus taskItem; var tbase = task as TaskBase; if (tbase != null) { // Reset the status for the task tbase.InitialiseStatus(newStatus); } var dummy = task as IStatusSnapshotGenerator; if (dummy != null) { taskItem = dummy.GenerateSnapshot(); } else { taskItem = new ItemStatus(task.GetType().Name) { Status = newStatus }; } // Only add the item if it has been initialised if (taskItem != null) { groupStatus.AddChild(taskItem); taskStatuses.Add(task, taskItem); } } } return groupStatus; }
/// <summary> /// Initialise an <see cref="ItemStatus"/>. /// </summary> /// <param name="newStatus">The new status.</param> public override void InitialiseStatus(ItemBuildStatus newStatus) { // If the status is already set, do not change it if ((this.CurrentStatus == null) || (this.CurrentStatus.Status != newStatus)) { // This needs to be called first, otherwise the status is not set up this.taskStatuses.Clear(); this.elseTaskStatuses.Clear(); base.InitialiseStatus(newStatus); this.mainStatus = this.InitialiseTaskStatuses(newStatus, this.Tasks, this.taskStatuses, "Tasks (Main)"); this.elseStatus = this.InitialiseTaskStatuses(newStatus, this.ElseTasks, this.elseTaskStatuses, "Tasks (Else)"); } }
public void RetrieveBuildFinalStatusReturnsDataStoreResult() { var dataStoreMock = this.mocks.StrictMock<IDataStore>(); var project = new Project { DataStore = dataStoreMock }; var buildName = "testBuild"; var expected = new ItemStatus(); Expect.Call(dataStoreMock.LoadProjectSnapshot(project, buildName)).Return(expected); this.mocks.ReplayAll(); var actual = project.RetrieveBuildFinalStatus(buildName); this.mocks.VerifyAll(); Assert.AreSame(expected, actual); }
private void GenerateTaskStatuses(string name, IList tasks) { // Generate the group status ItemStatus groupItem = new ItemStatus(name); groupItem.Status = ItemBuildStatus.Pending; // Add each status foreach (ITask task in tasks) { ItemStatus taskItem = null; var tbase = task as TaskBase; if (tbase != null) { tbase.InitialiseStatus(); } var item = task as IStatusItem; if (item != null) { item.InitialiseStatus(); taskItem = item.GenerateSnapshot(); } var dummyStatusSnapshotGenerator = task as IStatusSnapshotGenerator; if (dummyStatusSnapshotGenerator != null) { taskItem = dummyStatusSnapshotGenerator.GenerateSnapshot(); } else { taskItem = new ItemStatus(task.GetType().Name); taskItem.Status = ItemBuildStatus.Pending; } // Only add the item if it has been initialised if (taskItem != null) { groupItem.AddChild(taskItem); currentProjectItems.Add(task, taskItem); } } // Only add the group item if it contains children if (groupItem.ChildItems.Count > 0) currentProjectStatus.AddChild(groupItem); }
private void FindFailedTasks(ItemStatus item, List<string> failedTasks) { if (item.ChildItems.Count > 0) { foreach (var childItem in item.ChildItems) { FindFailedTasks(childItem, failedTasks); } } else { if (item.Status == ItemBuildStatus.CompletedFailed) { if (string.IsNullOrEmpty(item.Description)) { failedTasks.Add(item.Name); } else { failedTasks.Add(item.Description); } } } }
public void EqualsReturnsTrueForSameIdentifier() { var item1 = new ItemStatus(); var item2 = item1.Clone(); Assert.IsTrue(item1.Equals(item2)); }
private void AddToExplorer(ItemStatus value, TreeNodeCollection nodes, int position) { TreeNode node = null; // First attempt to find a node with a matching name foreach (TreeNode nodeToCheck in nodes) { if (object.Equals((nodeToCheck.Tag as ItemStatus), value)) { node = nodeToCheck; break; } } string nodeKey = value.Identifier.ToString(); string nodeText = value.Name + (value.Description!=null? "[" + value.Description + "]" : ""); bool newNode = false; if (node == null) { // Need to add a whole new node node = nodes.Insert(position, nodeKey, nodeText); newNode = true; } newKeys.Add(nodeKey); // Update the node node.Tag = value; node.Text = nodeText; node.ImageKey = value.Status.ToString(); node.SelectedImageKey = node.ImageKey; // Update all the child items int childPosition = 0; foreach (ItemStatus childItem in value.ChildItems) { AddToExplorer(childItem, node.Nodes, childPosition++); } if (newNode) node.Expand(); }
/// <summary> /// Cancels all outstanding items on a status item. /// </summary> private void CancelAllOutstandingItems(ItemStatus value) { if ((value.Status == ItemBuildStatus.Running) || (value.Status == ItemBuildStatus.Pending)) { ItemBuildStatus status = ItemBuildStatus.Cancelled; foreach (ItemStatus item in value.ChildItems) { CancelAllOutstandingItems(item); if (item.Status == ItemBuildStatus.CompletedFailed) { status = ItemBuildStatus.CompletedFailed; } else if ((item.Status == ItemBuildStatus.CompletedSuccess) && (status == ItemBuildStatus.Cancelled)) { status = ItemBuildStatus.CompletedSuccess; } } value.Status = status; } }
/// <summary> /// Initialise an <see cref="ItemStatus"/>. /// </summary> /// <param name="newStatus">The new status.</param> public virtual void InitialiseStatus(ItemBuildStatus newStatus) { // Store the last elapsed time if (currentStatus != null) { var elapsedTime = currentStatus.TimeCompleted - currentStatus.TimeStarted; if (elapsedTime.HasValue) { if (elapsedTimes.Count >= 8) { elapsedTimes.RemoveAt(7); } elapsedTimes.Insert(0, elapsedTime.Value); } } // Initialise the status with the default value - do not re-initialise if the status is already set if ((currentStatus == null) || (currentStatus.Status != newStatus)) { currentStatus = new ItemStatus { Name = Name, Description = Description, Status = newStatus, TimeCompleted = null, TimeOfEstimatedCompletion = null, TimeStarted = null }; } }
private void GenerateSourceControlOperation(SourceControlOperation operation) { ItemStatus sourceControlStatus = null; if (this.sourceControl is IStatusItem) { var item = this.sourceControl as IStatusItem; item.InitialiseStatus(); sourceControlStatus = item.GenerateSnapshot(); } else if (SourceControl is IStatusSnapshotGenerator) { sourceControlStatus = (SourceControl as IStatusSnapshotGenerator).GenerateSnapshot(); } else { sourceControlStatus = new ItemStatus( string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}: {1}", SourceControl.GetType().Name, operation)); sourceControlStatus.Status = ItemBuildStatus.Pending; } // Only add the item if it has been initialised if (sourceControlStatus != null) { currentProjectStatus.AddChild(sourceControlStatus); sourceControlOperations.Add(operation, sourceControlStatus); } }
/// <summary> /// Simple method to append status information to a builder /// </summary> /// <param name="status">The status to append.</param> /// <param name="builder">The builder to append the details to.</param> private void AppendStatusDetails(ItemStatus status, StringBuilder builder) { builder.AppendFormat("id:'{0}'", status.Identifier); builder.AppendFormat(",name:'{0}'", ToJsonString(status.Name)); builder.AppendFormat(",status:'{0}'", status.Status); if (!string.IsNullOrEmpty(status.Description)) builder.AppendFormat(",description:'{0}'", ToJsonString(status.Description)); if (status.TimeStarted.HasValue) builder.AppendFormat(",started:{0}", ToJsonDate(status.TimeStarted.Value)); if (status.TimeCompleted.HasValue) builder.AppendFormat(",completed:{0}", ToJsonDate(status.TimeCompleted.Value)); if (status.TimeOfEstimatedCompletion.HasValue) builder.AppendFormat(",estimated:{0}", ToJsonDate(status.TimeOfEstimatedCompletion.Value)); if (status.ChildItems.Count > 0) { builder.Append(",children:["); var children = from child in status.ChildItems select this.ConvertStatusToJson(child); builder.Append(string.Join(",", children.ToArray())); builder.Append("]"); } }
public void EqualsReturnsFalseForDifferentIdentifier() { var item1 = new ItemStatus(); var item2 = new ItemStatus(); Assert.IsFalse(item1.Equals(item2)); }