Skip to content

Commit

Permalink
Feature/52 links not added to workitem (#131)
Browse files Browse the repository at this point in the history
* Adding try catch when adding links to workitem, to catch exceptions. Checking if the link  to be added  is not a duplicated link in the exisitng links collection.

* Correcting logging message by showing related workitem id.
  • Loading branch information
madkoo authored and MOlausson committed Nov 27, 2019
1 parent a6aba46 commit 2d7f4d9
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/WorkItemMigrator/WorkItemImport/Agent.cs
Expand Up @@ -582,16 +582,42 @@ private bool AddLink(WiLink link, WorkItem wi)

if (linkEnd != null)
{
var relatedLink = new RelatedLink(linkEnd, link.TargetWiId);
relatedLink = ResolveCiclycalLinks(relatedLink, wi);
wi.Links.Add(relatedLink);
return true;
try
{
var relatedLink = new RelatedLink(linkEnd, link.TargetWiId);
relatedLink = ResolveCiclycalLinks(relatedLink, wi);
if (!IsDuplicateWorkItemLink(wi.Links, relatedLink))
{
wi.Links.Add(relatedLink);
return true;
}
return false;
}

catch (Exception ex)
{

Logger.Log(LogLevel.Error, ex.Message);
return false;
}
}
else
return false;

}

private bool IsDuplicateWorkItemLink(LinkCollection links, RelatedLink relatedLink)
{
if (links.Contains(relatedLink))
{
Logger.Log(LogLevel.Warning, $"Duplicate work item link, related workitem id: {relatedLink.RelatedWorkItemId}");
return false;
}
return true;


}

private RelatedLink ResolveCiclycalLinks(RelatedLink link, WorkItem wi)
{
if (link.LinkTypeEnd.LinkType.IsNonCircular && DetectCycle(wi, link))
Expand Down

0 comments on commit 2d7f4d9

Please sign in to comment.