public void GetWorkItem() { var wi = WIStore.GetWorkItem(WorkItemsAdded.First()); Console.WriteLine($"Opened a work item with id: '{wi.Id}' and title: '{wi.Title}'"); Console.WriteLine(); }
public void LinkExistingWorkItem() { // Get the first item var firstWorkItem = WIStore.GetWorkItem(WorkItemsAdded.First()); // Create a new work item var secondWorkItem = new WorkItem(DefaultWorkItemType) { Title = "Second work item created" }; secondWorkItem.Save(); // Need to know the type of link type ends available to the project var linkTypeEnds = WIStore.WorkItemLinkTypes.LinkTypeEnds; // Create a new work item type link with the specified type and the work item to point to // Access WorkItemLinkTypeEnd by specifying ImmutableName as index var relatedLinkTypeEnd = linkTypeEnds["System.LinkTypes.Related-Forward"]; var workItemLink = new WorkItemLink(relatedLinkTypeEnd, secondWorkItem.Id); // Add the work item link to the desired work item and save firstWorkItem.WorkItemLinks.Add(workItemLink); firstWorkItem.Save(); Console.WriteLine($"Added a link from existing work item '{secondWorkItem.Id}' to '{firstWorkItem.Id}.' Work Item: '{firstWorkItem.Id}' contains a link to '{secondWorkItem.Id}': {firstWorkItem.Links.Contains(workItemLink)}"); firstWorkItem.Links.Contains(workItemLink); Console.WriteLine(); }
public void AddHyperLink() { var wi = WIStore.GetWorkItem(WorkItemsAdded.First()); Hyperlink hlink = new Hyperlink("https://www.microsoft.com") { Comment = "This is a hyperlink to microsoft.com" }; wi.Links.Add(hlink); wi.Save(); Console.WriteLine($"Updated Existing Work Item: '{wi.Id}'. Added hyperlink: '{hlink.Location}'"); Console.WriteLine(); }
public void UpdateExistingWorkItem() { var wi = WIStore.GetWorkItem(WorkItemsAdded.First()); var originalTitle = wi.Title; var originalDescription = wi["System.Description"]; var changedTitle = "Changed Work Item Title"; var changedDescription = "Changed Description"; wi.Title = changedTitle; wi["System.Description"] = changedDescription; wi.Save(); Console.WriteLine($"Updated Existing Work Item: '{wi.Id}'. Work Item title was: '{originalTitle}', but is now '{wi.Title}'"); Console.WriteLine($"Updated Existing Work Item: '{wi.Id}'. Work Item description was: '{originalDescription}', but is now '{wi["System.Description"] }'"); Console.WriteLine(); }
public void AddComment() { var wi = WIStore.GetWorkItem(WorkItemsAdded.First()); // The value for field 'System.History' at the current revision is always an empty string. var currentHistoryValue = wi.History; Console.WriteLine($"WorkItem History is empty at the current revision: '{String.IsNullOrEmpty(currentHistoryValue)}'"); var commentToAdd = "Added a new comment"; wi.History = commentToAdd; wi.Save(); // In the WIT model, when the history field is saved, the recent change is persisted in the previous revision and current revision becomes empty. Console.WriteLine($"Updated Existing Work Item: '{wi.Id}'. Added comment: '{wi.Revisions[wi.Revisions.Count - 1].Fields[CoreField.History].Value}' to last revision"); Console.WriteLine(); }
public void AddAttachment() { var filePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); using (FileStream fstream = File.Create(filePath)) { using (StreamWriter swriter = new StreamWriter(fstream)) { swriter.Write("Sample attachment text"); } } var wi = WIStore.GetWorkItem(WorkItemsAdded.First()); Attachment newAttachment = new Attachment(filePath); wi.Attachments.Add(newAttachment); wi.Save(); Console.WriteLine($"Updated Existing Work Item: '{wi.Id}'. Added attachment: '{newAttachment.Name}'"); Console.WriteLine(); }