public void AddWorkItemLink(IWorkItemExposed destination, string linkTypeName) { var destLinkType = this.workItem.Store.WorkItemLinkTypes .FirstOrDefault(t => t.ForwardEnd.Name == linkTypeName) .ForwardEnd; var relationship = new WorkItemLink(destLinkType, this.Id, destination.Id); // check it does not exist already if (!this.workItem.WorkItemLinks.Contains(relationship)) { this.Logger.AddingWorkItemLink(this.Id, destLinkType, destination.Id); this.workItem.WorkItemLinks.Add(relationship); } else { this.Logger.WorkItemLinkAlreadyExists(this.Id, destLinkType, destination.Id); } }
public void DeleteScenarioExperienceLink(int scenarioId, int experienceId) { string condition = String.Format("[System.Id] = {0}", scenarioId); WITUtil util = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty); WorkItem wi = util.WorkItems[0]; wi.Open(); WorkItemLink link = null; foreach (WorkItemLink candidate in wi.WorkItemLinks) { if ((candidate.TargetId == experienceId) && (candidate.LinkTypeEnd.Name == "Scenario-Experience")) { link = candidate; break; } } if (link != null) { wi.WorkItemLinks.Remove(link); wi.Save(); } wi.Close(); }
public void DeleteParentChildLink(int parentId, int childId) { string condition = String.Format("[System.Id] = {0}", parentId); WITUtil util = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty); WorkItem wi = util.WorkItems[0]; wi.Open(); WorkItemLink link = null; foreach (WorkItemLink candidate in wi.WorkItemLinks) { if ((candidate.TargetId == childId) && (candidate.LinkTypeEnd.Name == "Child")) { link = candidate; break; } } if (link != null) { wi.WorkItemLinks.Remove(link); wi.Save(); } wi.Close(); }
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(); }
private IEnumerable <IWorkItemLinkInfo> RunkLinkQueryImplLazy() { // Eager loading for the link type ID (which is not returned by the REST API) causes ~250ms delay // REVIEW: Closure variable "ends" allocates, preventing local cache // REVIEW: Delegate for ctor of Lazy also allocates var ends = new Lazy <WorkItemLinkTypeEndCollection>(WorkItemLinkTypeEndValueFactory); var result = _workItemStore.NativeWorkItemStore.Value.QueryByWiqlAsync(_query, _timePrecision).GetAwaiter().GetResult(); // To avoid an enumerator allocation we are forcing the cast var result2 = (List <WorkItemLink>)result.WorkItemRelations; for (var i = 0; i < result2.Count; i++) { WorkItemLink t = result2[i]; // REVIEW: Closure allocation: workItemLink + ends outer closure IWorkItemLinkTypeEnd EndValueFactory() { return(ends.Value.TryGetByName(t.Rel, out IWorkItemLinkTypeEnd end) ? end : null); } var ltEnd = new Lazy <IWorkItemLinkTypeEnd>(EndValueFactory); yield return(new WorkItemLinkInfo(t.Source?.Id ?? 0, t.Target?.Id ?? 0, ltEnd)); } }
/// <summary> /// Gets the children of a work item /// </summary> public static IEnumerable <WorkItem> GetChildrenFromListOrStore(this WorkItem parent, IEnumerable <WorkItem> workItemList, Store store) { List <WorkItem> decendants = new List <WorkItem>(); // Go through all the links for the work item passed in (parent) foreach (WorkItemLink link in parent.WorkItemLinks) { WorkItem childWorkItem; // Find all the child links if (link.LinkTypeEnd.Name == "Child") { // If this child link is in the list of items then add it to the result set if (workItemList.Select(x => x.Id).Contains(link.TargetId)) { WorkItemLink linkClosure = link; childWorkItem = workItemList.Where(x => x.Id == linkClosure.TargetId).FirstOrDefault(); } // if the item was not in our list then get it from the store else { childWorkItem = store.Access.GetWorkItem(link.TargetId); } decendants.Add(childWorkItem); } } return(decendants); }
private void CreateLinks(WorkItem workItem, IList <ILink> links) { workItem.Reset(); foreach (Link link in links) { try { WorkItemLinkTypeEnd workItemLinkTypeEnd = m_workItemLinkTypeEndCollection[link.LinkTypeName]; WorkItemLink workItemLink = new WorkItemLink(workItemLinkTypeEnd, link.EndWorkItemTfsId); workItem.WorkItemLinks.Add(workItemLink); workItem.Save(); link.IsExistInTfs = true; } catch (ValidationException valEx) { link.Message = valEx.Message; workItem.Reset(); } catch (TeamFoundationServerException tfsEx) { link.Message = tfsEx.Message; workItem.Reset(); } } }
private void RecreateLink(WorkItemLink wlink, Dictionary <int, int> ReplacedIds) { int num1; if (!ReplacedIds.TryGetValue(wlink.TargetId, out num1)) { return; } int num2; if (!ReplacedIds.TryGetValue(wlink.SourceId, out num2)) { return; } try { WorkItem workItem1 = this.store.GetWorkItem(num2); WorkItem workItem2 = this.store.GetWorkItem(num1); workItem1.WorkItemLinks.Add(new WorkItemLink(wlink.LinkTypeEnd, num2, num1)); string str = "Copied Link according to historical ancestor."; workItem1.History = str; workItem2.History = str; workItem2.Save(); workItem1.Save(); } catch (Exception ex) { } }
public void UpdateLinkLockOption(int parentId, int childId, bool isLocked) { string condition = String.Format("[System.Id] = {0}", parentId); WITUtil util = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty); WorkItem wi = util.WorkItems[0]; wi.Open(); WorkItemLink link = null; foreach (Link l in wi.WorkItemLinks) { WorkItemLink wil = l as WorkItemLink; if (wil != null) { if (wil.TargetId == childId) { link = l as WorkItemLink; break; } } } Debug.Assert(link != null, "link is null"); link.IsLocked = isLocked; wi.Save(); }
private static void AssignFeature(WorkItemLink link, IEnumerable <Card> cards) { var card = cards.FirstOrDefault(c => c.Id == link.Target?.Id); if (card != null) { card.FeatureId = link.Source?.Id; card.ParentId = card.FeatureId; } }
/// <summary> /// The link work items. /// </summary> /// <param name="sourceId"> /// The source id. /// </param> /// <param name="targetIds"> /// The target ids. /// </param> /// <param name="linkTypeEnd"> /// The link type end. /// </param> public void LinkWorkItems(int sourceId, List <int> targetIds, string linkTypeEnd) { WorkItem wi = tfsManager.GetWorkItem(sourceId); foreach (int id in targetIds) { var wiLink = new WorkItemLink(tfsManager.ItemsStore.WorkItemLinkTypes["Is Produced By"].ReverseEnd, sourceId, id); wi.Links.Add(wiLink); } wi.Save(); }
private static void TfsExtras(string collectionUri, string teamProjectName, int childWorkItemId, int parentWorkItemId) { using (var tpc = new TfsTeamProjectCollection(new Uri(collectionUri))) { var workItemStore = tpc.GetService <WorkItemStore>(); var linkType = workItemStore.WorkItemLinkTypes[CoreLinkTypeReferenceNames.Hierarchy]; var link = new WorkItemLink(linkType.ReverseEnd, parentWorkItemId); var workitem = workItemStore.GetWorkItem(childWorkItemId); workitem.WorkItemLinks.Add(link); workitem.Save(); } }
internal static WorkItemLinkWrapper GetInstance() { WorkItemLink real = default(WorkItemLink); RealInstanceFactory(ref real); var instance = (WorkItemLinkWrapper)WorkItemLinkWrapper.GetWrapper(real); InstanceFactory(ref instance); if (instance == null) { Assert.Inconclusive("Could not Create Test Instance"); } return(instance); }
public void AddScenarioExperienceLink(int scenarioId, int experienceId) { string condition = String.Format("[System.Id] = {0}", scenarioId); WITUtil util = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty); WorkItem wi = util.WorkItems[0]; wi.Open(); var scenarioExperienceLink = WorkItemStore.WorkItemLinkTypes["Microsoft.DevDiv.ScenarioExperience"]; var link = new WorkItemLink(scenarioExperienceLink.ForwardEnd, experienceId); link.IsLocked = false; wi.WorkItemLinks.Add(link); wi.Save(); }
public void AddParentChildLink(int parentId, int childId, bool isLocked) { string condition = String.Format("[System.Id] = {0}", parentId); WITUtil util = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty); WorkItem wi = util.WorkItems[0]; wi.Open(); var hierarchicalLink = WorkItemStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"]; var link = new WorkItemLink(hierarchicalLink.ForwardEnd, childId); link.IsLocked = isLocked; wi.WorkItemLinks.Add(link); wi.Save(); }
private WorkItemLink GetWorkItemLinkFromLinkChange(TfsMigrationWorkItem source, WorkItemLinkChange linkChange) { WorkItemLink link = null; foreach (WorkItemLink l in source.WorkItem.WorkItemLinks) { if ((l.SourceId == linkChange.SourceID && l.TargetId == linkChange.TargetID) || (l.TargetId == linkChange.SourceID && l.SourceId == linkChange.TargetID)) { if (string.Equals(l.LinkTypeEnd.LinkType.ReferenceName, linkChange.LinkType, StringComparison.OrdinalIgnoreCase)) { link = l; break; } } } return(link); }
private void MapWorkItemLinks(List <WorkItem> validWorkItems, List <WorkItemLink> changedLinks, WorkItem sourceWI) { foreach (WorkItemLink sourceLink in sourceWI.WorkItemLinks) { WorkItemLink destinationLink = null; try { destinationLink = MapSingleWorkItemLink(sourceLink, validWorkItems); } catch (Exception ex) { this.EventSink.ExceptionWhileMappingLink(ex, sourceLink); } if (destinationLink != null) { changedLinks.Add(destinationLink); } }//for }
internal void AddWorkItemLink(IWorkItemExposed destination, string linkTypeName, IEnumerable <WorkItemLinkType> availableLinkTypes) { WorkItemLinkType workItemLinkType = availableLinkTypes .FirstOrDefault( t => new string[] { t.ForwardEnd.ImmutableName, t.ForwardEnd.Name, t.ReverseEnd.ImmutableName, t.ReverseEnd.Name } .Contains(linkTypeName, StringComparer.OrdinalIgnoreCase)); if (workItemLinkType == null) { throw new ArgumentOutOfRangeException(nameof(linkTypeName)); } WorkItemLinkTypeEnd destLinkType; #pragma warning disable S3240 if ( new string[] { workItemLinkType.ForwardEnd.ImmutableName, workItemLinkType.ForwardEnd.Name } .Contains(linkTypeName, StringComparer.OrdinalIgnoreCase)) { destLinkType = workItemLinkType.ForwardEnd; } else { destLinkType = workItemLinkType.ReverseEnd; } #pragma warning restore S3240 var relationship = new WorkItemLink(destLinkType, this.Id, destination.Id); // check it does not exist already if (!this.workItem.WorkItemLinks.Contains(relationship)) { this.Logger.AddingWorkItemLink(this.Id, destLinkType, destination.Id); this.workItem.WorkItemLinks.Add(relationship); } else { this.Logger.WorkItemLinkAlreadyExists(this.Id, destLinkType, destination.Id); } }
/// <inheritdoc/> public void SaveWorkItem(TfsWorkItem tfsWorkItem) { var item = tfsWorkItem.Item as WorkItem; if (item == null) { throw new InvalidOperationException("Invalid TfsWorkItem object."); } if (item.IsNew) { var linkType = this.workItemStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"]; var link = new WorkItemLink(linkType.ReverseEnd, this.parentWorkItem.Id) { Comment = tfsWorkItem.IssueSignature }; item.Links.Add(link); } else { foreach (var link in item.Links) { var linkToParent = link as RelatedLink; if (linkToParent != null && linkToParent.RelatedWorkItemId == this.parentWorkItem.Id) { linkToParent.Comment = tfsWorkItem.IssueSignature; } } } this.logger.Debug("Added a link to parent work item with {comment}", tfsWorkItem.IssueSignature); foreach (Field field in item.Validate()) { this.logger.Warning($"Work item field has invalid value: {field.Name}: {field.Status}"); } item.Save(); this.logger.Verbose("Saved the tfs work item. All is well!"); }
/// <summary> /// When implemented in a derived class, performs the execution of the activity. /// </summary> /// <param name="context">The execution context under which the activity executes.</param> protected override void Execute(CodeActivityContext context) { try { var inLinkType = context.GetValue <string>(LinkType); var inParentWorkItem = context.GetValue <WorkItem>(ParentWorkItem); var inChildWorkItem = context.GetValue <WorkItem>(ChildWorkItem); if (inParentWorkItem == null) { throw new Exception("ParentWorkItem is null."); } if (inChildWorkItem == null) { throw new Exception("ChildWorkItem is null."); } if (string.IsNullOrEmpty(inLinkType)) { throw new Exception("LinkType is empty."); } WorkItemLinkType outLinkType; if (inParentWorkItem.Project.Store.WorkItemLinkTypes.TryGetByName(inLinkType, out outLinkType)) { WorkItemLink newLink = new WorkItemLink(outLinkType.ForwardEnd, inParentWorkItem.Id, (inChildWorkItem.Id > 0) ? inChildWorkItem.Id : inChildWorkItem.TemporaryId); inParentWorkItem.WorkItemLinks.Add(newLink); inParentWorkItem.Save(); LogExtensions.LogInfo(this, string.Format("Activity CreateLink: The parent workitem {0} is now linked with the child workitem {1} with a link of the type: {2}", inParentWorkItem.Id, inChildWorkItem.Id, inLinkType)); } else { LogExtensions.LogInfo(this, string.Format("Activity CreateLink: {0} is not a valid link type.", inLinkType)); } } catch (Exception ex) { throw new Exception("Activity CreateLink:", ex); } }
private LinkChangeAction GetAddLinkChangeActionFromWorkItemLink(WorkItemLink workItemLink, LinkType linkType) { var sourceIdStr = workItemLink.SourceId.ToString(CultureInfo.InvariantCulture); var targetIdStr = workItemLink.TargetId.ToString(CultureInfo.InvariantCulture); var sourceArtifact = new ToolkitLinking.Artifact(TfsWorkItemHandler.UriFromId(sourceIdStr), WorkItemLinkTypeBase.s_sourceArtifactType); var targetArtifact = new ToolkitLinking.Artifact(TfsWorkItemHandler.UriFromId(targetIdStr), WorkItemLinkTypeBase.s_targetArtifactType); ToolkitLinking.ArtifactLink link; if (workItemLink.LinkTypeEnd.IsForwardLink) { link = new ToolkitLinking.ArtifactLink(sourceIdStr, sourceArtifact, targetArtifact, workItemLink.Comment, linkType, workItemLink.IsLocked); } else { link = new ToolkitLinking.ArtifactLink(targetIdStr, targetArtifact, sourceArtifact, workItemLink.Comment, linkType, workItemLink.IsLocked); } LinkChangeAction addLinkChangeAction = new LinkChangeAction(WellKnownChangeActionId.Add, link, LinkChangeAction.LinkChangeActionStatus.Created, false); return(addLinkChangeAction); }
private bool GetWorkItemLinkedDataRecursive(Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem, ref WorkItemProperties wiProperties, bool allowRecursion, bool isRecursiveCall = false) { // note: This method makes some assumptions about how the different items are connected in TFS. // Read more to find out which assumptions ;) wiProperties.Id = workItem.Id; wiProperties.WorkItemObject = workItem; if (!isRecursiveCall) { _currentRecursionDepth = 0; _recursedWorkItemIds = new List <int>(); } else { if (_recursedWorkItemIds.Contains(workItem.Id)) { //Caliburn.Micro.IoC.Get<IPopupService>().ShowMessage( //$"Got into a recursion cycle: encountered the same work item again (#{workItem.Id}: {workItem.Description}) Aborting search."); return(false); } if (_currentRecursionDepth >= MAX_RECURSION_DEPTH) { //Caliburn.Micro.IoC.Get<IPopupService>().ShowMessage( //$"Max recursion depth of {MAX_RECURSION_DEPTH} reached when reading data for work item #{workItem.Id}: {workItem.Description}. Aborting search."); return(false); } } _recursedWorkItemIds.Add(workItem.Id); _currentRecursionDepth++; bool retval = true; if (!workItem.Fields.Contains(FIELD_TYPE)) { return(retval); } wiProperties.State = workItem.State; // Recursion is only performed for Tasks; we don't care about the parents of Bugs or Backlog items. Field itemTypeField = workItem.Fields[FIELD_TYPE]; wiProperties.Type = ShortenWorkItemType((string)itemTypeField.Value); if (allowRecursion && wiProperties.Type == WI_TYPE_TASK) { // note: Tasks often have just one link to the parent (bug or backlog) item. var wiLinks = workItem.WorkItemLinks; if (wiLinks.Count == 0) { //retStr = $"[{id}: {type}: {state}]"; } else { WorkItemLink parent = null; if (wiLinks.Count == 1) { // If there's only one link, take that. parent = wiLinks[0]; } else { // Multiple links -> Search for Parent (Assuming only 1 parent). foreach (var wiLinkObject in wiLinks) { var wiLink = wiLinkObject as WorkItemLink; if (wiLink == null) { continue; } string linkTypeName = wiLink.LinkTypeEnd.Name; if (!IsAcceptedLinkType(linkTypeName)) { continue; } string wiType = GetWorkItemType(_tfs, wiLink.TargetId); if (!IsAcceptedWorkItemType(wiType)) { continue; } parent = wiLink; break; } //debug if (parent == null) { var sb = new StringBuilder(); sb.AppendLine($"Did not find a suitable parent item for a Task with recursion (depth {_currentRecursionDepth})."); sb.AppendLine("Found these link type names:"); foreach (var wiLinkObject in wiLinks) { sb.AppendLine((wiLinkObject as WorkItemLink)?.LinkTypeEnd.Name); } Caliburn.Micro.IoC.Get <IPopupService>()?.ShowMessage(sb.ToString()); } } if (parent != null && _tfs != null) { WorkItem linkedItem = _tfs.GetWorkItem(parent.TargetId); retval = GetWorkItemLinkedDataRecursive(linkedItem, ref wiProperties, allowRecursion: true, isRecursiveCall: true); } else { //retStr = $"[{id}: {type}: {state}]"; } } } else { // Not Task -> We'll take this item, no recursion if (workItem.Fields.Contains(FIELD_ORIGIN)) { var originField = workItem.Fields[FIELD_ORIGIN]; wiProperties.Origin = (string)originField.Value; } if (workItem.Fields.Contains(FIELD_TITLE)) { var titleField = workItem.Fields[FIELD_TITLE]; wiProperties.Title = (string)titleField.Value; } if (workItem.Fields.Contains(FIELD_ASSIGNED_TO)) { var assignedToField = workItem.Fields[FIELD_ASSIGNED_TO]; wiProperties.AssignedTo = (string)assignedToField.Value; } if (workItem.Fields.Contains(FIELD_SEVERITY)) { var severityField = workItem.Fields[FIELD_SEVERITY]; wiProperties.Severity = (string)severityField.Value; } if (workItem.Fields.Contains(FIELD_PRIORITY)) { var priorityField = workItem.Fields[FIELD_PRIORITY]; wiProperties.Priority = (int)priorityField.Value; } if (workItem.Fields.Contains(FIELD_PLANNED_RELEASE)) { var releaseField = workItem.Fields[FIELD_PLANNED_RELEASE]; wiProperties.PlannedRelease = (string)releaseField.Value; } //retStr = $"[{id}: {type}: {state}]"; } return(retval); }
public ReleasePackageVersionMetadata() { WorkItems = new WorkItemLink[0]; Commits = new CommitDetails[0]; }
/// <summary> /// Writes the specified link. /// </summary> /// <param name="link">The link.</param> /// <returns>System.String.</returns> private static string Write(WorkItemLink link) { return(String.Format("(WorkItemLink) Target Id:{0} Type:{1} ", link.TargetId, link.LinkTypeEnd.Name)); }
private static void AssignFeature(WorkItemLink link, IEnumerable<Card> cards) { var card = cards.FirstOrDefault(c => c.Id == link.Target?.Id); if (card != null) { card.FeatureId = link.Source?.Id; card.ParentId = card.FeatureId; } }
public WorkItemLinkWrapper(WorkItemLink link, IWorkItemRepository store, ILogEvents logger) { this.logger = logger; this.link = link; this.store = store; }
public bool Contains(IWorkItemLink link) { WorkItemLink item = ((WorkItemLinkWrapper)link).WorkItemLink; return(this.workItemLinkCollection.Contains(item)); }
public WorkItemLinkExposedWrapper(WorkItemLink item, IRuntimeContext context) { this.item = item; this.context = context; }
private void UpdateBackLogItemLink(WorkItem backlogItem, WorkItemLink taskLink1) { backlogItem.Links.Add(taskLink1); AddLog("updating backlogworkitem link - " + taskLink1.TargetId.ToString() + "- " + taskLink1.SourceId.ToString()); backlogItem.Save(); }
static partial void RealInstanceFactory(ref WorkItemLink real, [CallerMemberName] string callerName = "");
/// <summary> /// Processes a relationship between two work items /// </summary> /// <param name="wi">The source work item</param> /// <param name="wiLink">The link to the target work item</param> /// <param name="s">The work item stub that corrosponds to the source work item</param> private void ProcessLinks(WorkItem wi, WorkItemLink wiLink, WorkItemStub s) { int targetID = wiLink.TargetId; //Check to see if the work item that is related to this one is in the list of work items and if not, add it by //calling this method recursively. If it is in the list of work items then we've already //seen this work item and we just have to figure out how it is linked to this work item WorkItemStub result = _workItemStubs.Find( delegate(WorkItemStub stub) { return stub.ID == targetID; } ); //If the work item hasn't been processed yet, process it if (result == null) ProcessWorkItemCS(_wis.GetWorkItem(targetID)); //Check to see if the ID and relationship match (we can have more than one relationship between two work items //for example, we could have a parent/child relationship and also a predecessor/successor relationship WorkItemRelationship result1 = s.Related.Find( delegate(WorkItemRelationship stub) { return stub.ToString() == targetID.ToString() + wiLink.LinkTypeEnd.Name; } ); if (result1 == null) { bool found = false; //Before we add this relationship in, make sure we have never added this relationship anywhere at all //so we make sure each relationship (forward/reverse end of the same relationship) is unique in the //entire result set. for (int j = 0; j < _workItemStubs.Count; j++) { if (_workItemStubs[j].ID == targetID) { for (int k = 0; k < _workItemStubs[j].Related.Count; k++) { if (_workItemStubs[j].Related[k].ID == wi.Id) { found = true; break; } } } if (found) break; } //If we didn't find an existing relationship, make sure we add it to the //work item at the reverse end of the relationship. For example, in a Parent/ //Child relationship the Child is the Forward end of the relationship and //Parent is the reverse end of the relationship. We need to add this relationship //to the Parent to say that the parent has children so when the links are //written out to the DGML they point the right direction if (!found) { //get the relationship TempLinkType2 t = GetRelationship(wiLink.LinkTypeEnd.Name); //Determine if this is the forward or reverse end of the relationship if (t.Reverse == wiLink.LinkTypeEnd.Name) { //This is the reverse end of the relationship so add it, otherwise skip it altogether s.Related.Add(new WorkItemRelationship() { ID = targetID, End = wiLink.LinkTypeEnd.Name, Relationship = GetRelationship(wiLink.LinkTypeEnd.Name) }); } } } }
private WorkItemLink CreateTaskLink(WorkItem task1) { var linkType = workItemStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"]; var taskLink = new WorkItemLink(linkType.ForwardEnd, task1.Id); AddLog("created link- " + task1.Id.ToString()); return taskLink; }
public static void AddMappedLink(this WorkItem item, WorkItemLink link, Dictionary<int, int> idMap) { var mappedTargetId = idMap[link.TargetId]; var mappedLink = new WorkItemLink(link.LinkTypeEnd, mappedTargetId); item.WorkItemLinks.Add(mappedLink); }
internal void AddWorkItemLink(IWorkItemExposed destination, string linkTypeName, IEnumerable<WorkItemLinkType> availableLinkTypes) { WorkItemLinkType workItemLinkType = availableLinkTypes .FirstOrDefault( t => new string[] { t.ForwardEnd.ImmutableName, t.ForwardEnd.Name, t.ReverseEnd.ImmutableName, t.ReverseEnd.Name } .Contains(linkTypeName, StringComparer.OrdinalIgnoreCase)); if (workItemLinkType == null) { throw new ArgumentOutOfRangeException(nameof(linkTypeName)); } WorkItemLinkTypeEnd destLinkType; #pragma warning disable S3240 if ( new string[] { workItemLinkType.ForwardEnd.ImmutableName, workItemLinkType.ForwardEnd.Name } .Contains(linkTypeName, StringComparer.OrdinalIgnoreCase)) { destLinkType = workItemLinkType.ForwardEnd; } else { destLinkType = workItemLinkType.ReverseEnd; } #pragma warning restore S3240 var relationship = new WorkItemLink(destLinkType, this.Id, destination.Id); // check it does not exist already if (!this.workItem.WorkItemLinks.Contains(relationship)) { this.Logger.AddingWorkItemLink(this.Id, destLinkType, destination.Id); this.workItem.WorkItemLinks.Add(relationship); } else { this.Logger.WorkItemLinkAlreadyExists(this.Id, destLinkType, destination.Id); } }
static partial void RealInstanceFactory(ref WorkItemLink real, string callerName) { WorkItemLinkCollection collection = WorkItemLinkCollectionWrapper_UnitTests.GetRealInstance(); real = collection[0]; }
public void ExceptionWhileMappingLink(Exception ex, WorkItemLink sourceLink) { this.Error("While work item link {2}->{3} (type {4}): {0}\r\n{1}" , ex.Message, ex.StackTrace , sourceLink.SourceId, sourceLink.TargetId, sourceLink.LinkTypeEnd.Name); }
public int DeepCopy(WiDcConfig a_WiDcConfig) { this.store = new WorkItemStore(TfsTeamProjectCollectionFactory.GetTeamProjectCollection(a_WiDcConfig.tfsuri)); WorkItem workItem1 = this.store.GetWorkItem(a_WiDcConfig.RootWorkItemId); List <int> list1 = new List <int>(); this.touchedWiIds.Add(a_WiDcConfig.RootWorkItemId); Dictionary <int, string> dictionary = new Dictionary <int, string>(); foreach (WorkItemLink workItemLink in (VariableSizeList)workItem1.WorkItemLinks) { if (!this.touchedWiIds.Contains(workItemLink.TargetId)) { if (workItemLink.LinkTypeEnd.Name == a_WiDcConfig.PrimaryLinkTypeEnd) { int targetId = workItemLink.TargetId; int key = -1; if (!a_WiDcConfig.WorkItemTypesToIgnore.Contains(((object)this.store.GetWorkItem(targetId).Type.Name).ToString())) { if (!this.ReplacedIds.TryGetValue(targetId, out key)) { a_WiDcConfig.RootWorkItemId = targetId; key = this.DeepCopy(a_WiDcConfig); } list1.Add(targetId); dictionary.Add(key, workItemLink.LinkTypeEnd.Name); this.ReplacedIds.Add(targetId, key); } } else if (!a_WiDcConfig.WorkItemLinkTypesToIgnore.Contains(workItemLink.LinkTypeEnd.Name)) { this.CompleteLinkList.Add(workItemLink); } } } WorkItem workItem2 = !a_WiDcConfig.CopyAttachments ? workItem1.Copy(workItem1.Type, WorkItemCopyFlags.None) : workItem1.Copy(workItem1.Type, WorkItemCopyFlags.CopyFiles); workItem2.History = "Deep Copy: Copied original WI"; workItem2.Save(); WorkItemLink link1 = new WorkItemLink(this.store.WorkItemLinkTypes.LinkTypeEnds[a_WiDcConfig.HistoricLinkTypeEndTo], a_WiDcConfig.RootWorkItemId); //dd, 03.04.2014 - wegen Castingfehler //link1.Comment = a_WiDcConfig.HistoryComment + (object)"(" + (string)(object)workItem1.Id + "-->" + (string)(object)workItem2.Id + ")"; link1.Comment = a_WiDcConfig.HistoryComment + "(" + workItem1.Id.ToString() + "-->" + workItem2.Id.ToString() + ")"; workItem2.WorkItemLinks.Add(link1); workItem2.History = "Deep Copy: Added History Link"; workItem2.Save(); foreach (KeyValuePair <int, string> keyValuePair in dictionary) { WorkItemLink link2 = new WorkItemLink(this.store.WorkItemLinkTypes.LinkTypeEnds[keyValuePair.Value], keyValuePair.Key); workItem2.WorkItemLinks.Add(link2); } workItem2.History = "Deep Copy: Added Parent/Child Links to Work Items"; workItem2.Save(); List <Hyperlink> list2 = new List <Hyperlink>(); List <Hyperlink> list3 = new List <Hyperlink>(); foreach (Link link2 in (VariableSizeList)workItem1.Links) { if (link2.BaseType == BaseLinkType.Hyperlink) { Hyperlink hyperlink1 = link2 as Hyperlink; string location = hyperlink1.Location; if (a_WiDcConfig.ReplaceHyperlinkUri) { foreach (KeyValuePair <string, string> keyValuePair in a_WiDcConfig.UrlReplaceDic) { location = location.Replace(keyValuePair.Key, keyValuePair.Value); } } Hyperlink hyperlink2 = new Hyperlink(location); hyperlink2.Comment = link2.Comment; list2.Add(hyperlink2); list3.Add(hyperlink1); } } foreach (Hyperlink hyperlink in list3) { workItem2.Links.Remove((Link)hyperlink); } foreach (Hyperlink link2 in list2) { workItem2.Links.Add(link2); } workItem2.History = !a_WiDcConfig.ReplaceHyperlinkUri ? "Deep Copy: Added Hyperlinks (no URL replacement)" : "Deep Copy: Added Hyperlinks (with URL replacement)"; if (workItem2.IsValid()) { workItem2.Save(); } if (a_WiDcConfig.KeepChangesetLinks) { foreach (Link link2 in (VariableSizeList)workItem1.Links) { if (link2.BaseType == BaseLinkType.ExternalLink) { ExternalLink externalLink = link2 as ExternalLink; if (externalLink != null && externalLink.ArtifactLinkType.Name == "Fixed in Changeset") { workItem2.Links.Add(new ExternalLink(link2.ArtifactLinkType, externalLink.LinkedArtifactUri)); } } } workItem2.History = "Deep Copy: Added Changeset Links"; workItem2.Save(); } else if (a_WiDcConfig.KeepLinkToLatestChangesetOnly) { int num = a_WiDcConfig.NrOfChangesetLinksToKeep; List <ExternalLink> list4 = new List <ExternalLink>(); foreach (Link link2 in (VariableSizeList)workItem1.Links) { if (link2.BaseType == BaseLinkType.ExternalLink) { ExternalLink externalLink = link2 as ExternalLink; if (externalLink != null && externalLink.ArtifactLinkType.Name == "Fixed in Changeset") { list4.Add(externalLink); } } } ExternalLink externalLink1 = (ExternalLink)null; foreach (ExternalLink externalLink2 in list4) { if (externalLink1 == null) { externalLink1 = externalLink2; } else if (((object)externalLink1.LinkedArtifactUri).ToString().Substring(((object)externalLink1.LinkedArtifactUri).ToString().IndexOf("Changeset/")).CompareTo(((object)externalLink2.LinkedArtifactUri).ToString().Substring(((object)externalLink2.LinkedArtifactUri).ToString().IndexOf("Changeset/"))) < 0) { externalLink1 = externalLink2; } } if (externalLink1 != null) { workItem2.Links.Add(new ExternalLink(externalLink1.ArtifactLinkType, externalLink1.LinkedArtifactUri)); workItem2.History = "Deep Copy: Added latest Changeset Link"; workItem2.Save(); } } if (a_WiDcConfig.KeepVersionedItemLinks) { foreach (Link link2 in (VariableSizeList)workItem1.Links) { if (link2.BaseType == BaseLinkType.ExternalLink) { ExternalLink externalLink = link2 as ExternalLink; if (externalLink != null && externalLink.ArtifactLinkType.Name == "Source Code File") { workItem2.Links.Add(new ExternalLink(link2.ArtifactLinkType, externalLink.LinkedArtifactUri)); } } } } workItem2.History = "Deep Copy: Added Versioned Item Links"; workItem2.Save(); if (a_WiDcConfig.ReplaceCustomFieldValue) { Field field1 = (Field)null; foreach (Field field2 in (ReadOnlyList)workItem2.Fields) { if (field2.ReferenceName == a_WiDcConfig.CustomFieldRefName) { field1 = field2; break; } } if (field1 != null) { object obj = workItem2.Fields[a_WiDcConfig.CustomFieldRefName].Value; try { field1.Value = (object)a_WiDcConfig.CustomFieldValue; workItem2.History = "Deep Copy: Replaced Custom Field value."; workItem2.Save(); } catch { field1.Value = obj; workItem2.History = "Deep Copy: Replaced Custom Field value - FAILED [wrong value type!]."; workItem2.Save(); } } } return(workItem2.Id); }
/// <summary> /// The link work items. /// </summary> /// <param name="sourceId"> /// The source id. /// </param> /// <param name="targetIds"> /// The target ids. /// </param> /// <param name="linkTypeEnd"> /// The link type end. /// </param> public void LinkWorkItems(int sourceId, List<int> targetIds, string linkTypeEnd) { WorkItem wi = tfsManager.GetWorkItem(sourceId); foreach (int id in targetIds) { var wiLink = new WorkItemLink(tfsManager.ItemsStore.WorkItemLinkTypes["Is Produced By"].ReverseEnd, sourceId, id); wi.Links.Add(wiLink); } wi.Save(); }