/// <summary> /// Finds the link type based on an end name /// </summary> /// <param name="value">The end to use in the search (such as Parent)</param> /// <returns>The name of the relationship (such as Parent/Child)</returns> private TempLinkType2 GetRelationship(string value) { TempLinkType2 s = _links.Find( delegate(TempLinkType2 stub) { return(stub.Reverse == value); } ); if (s == null) { s = _links.Find( delegate(TempLinkType2 stub) { return(stub.Forward == value); } ); } return(s); }
/// <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) }); } } } }