Skip to content

Commit

Permalink
Merge pull request #114 from Lyra1337/master
Browse files Browse the repository at this point in the history
extended LinkMapper to support external links
  • Loading branch information
rjmurillo authored Mar 3, 2017
2 parents 1b3d9a1 + 42a39e0 commit 30e9e37
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 21 deletions.
11 changes: 11 additions & 0 deletions src/Qwiq.Core/IExternalLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Tfs = Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace Microsoft.Qwiq
{
public interface IExternalLink : ILink
{
string LinkedArtifactUri { get; }

string ArtifactLinkTypeName { get; }
}
}
53 changes: 32 additions & 21 deletions src/Qwiq.Core/LinkMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Microsoft.Qwiq.Exceptions;
using Microsoft.Qwiq.Proxies;
using Tfs = Microsoft.TeamFoundation.WorkItemTracking.Client;
Expand All @@ -9,36 +10,46 @@ internal class LinkMapper
{
public Tfs.Link Map(ILink link, Tfs.WorkItem item)
{
if (link.BaseType == BaseLinkType.RelatedLink)
switch (link.BaseType)
{
var relatedLink = (IRelatedLink)link;
var linkTypeEnd = LinkTypeEndMapper.Map(item.Store, relatedLink.LinkTypeEnd);
return new Tfs.RelatedLink(linkTypeEnd, relatedLink.RelatedWorkItemId);
}
if (link.BaseType == BaseLinkType.Hyperlink)
{
var hyperlink = (IHyperlink) link;
return new Tfs.Hyperlink(hyperlink.Location);
case BaseLinkType.RelatedLink:
var relatedLink = (IRelatedLink)link;
var linkTypeEnd = LinkTypeEndMapper.Map(item.Store, relatedLink.LinkTypeEnd);
return new Tfs.RelatedLink(linkTypeEnd, relatedLink.RelatedWorkItemId);

case BaseLinkType.Hyperlink:
var hyperlink = (IHyperlink)link;
return new Tfs.Hyperlink(hyperlink.Location);

case BaseLinkType.ExternalLink:
var externalLink = (IExternalLink)link;
var registeredLinkType = RegisteredLinkTypeMapper.Map(item.Store, externalLink.ArtifactLinkTypeName);
return new Tfs.ExternalLink(registeredLinkType, externalLink.LinkedArtifactUri);

default:
throw new ArgumentException("Unknown link type", nameof(link));
}
throw new ArgumentException("Unknown link type", nameof(link));
}

public ILink Map(Tfs.Link link)
{
if (link.BaseType == Tfs.BaseLinkType.RelatedLink)
switch (link.BaseType)
{
var relatedLink = (Tfs.RelatedLink) link;
return ExceptionHandlingDynamicProxyFactory.Create<IRelatedLink>(new RelatedLinkProxy(relatedLink));
case Tfs.BaseLinkType.RelatedLink:
var relatedLink = (Tfs.RelatedLink)link;
return ExceptionHandlingDynamicProxyFactory.Create<IRelatedLink>(new RelatedLinkProxy(relatedLink));

}
if (link.BaseType == Tfs.BaseLinkType.Hyperlink)
{
var hyperlink = (Tfs.Hyperlink) link;
return ExceptionHandlingDynamicProxyFactory.Create<IHyperlink>(new HyperlinkProxy(hyperlink));
}
case Tfs.BaseLinkType.Hyperlink:
var hyperlink = (Tfs.Hyperlink)link;
return ExceptionHandlingDynamicProxyFactory.Create<IHyperlink>(new HyperlinkProxy(hyperlink));

case Tfs.BaseLinkType.ExternalLink:
var externalLink = (Tfs.ExternalLink)link;
return ExceptionHandlingDynamicProxyFactory.Create<IExternalLink>(new ExternalLinkProxy(externalLink));

throw new ArgumentException("Unknown link type", nameof(link));
default:
throw new ArgumentException("Unknown link type", nameof(link));
}
}
}
}

24 changes: 24 additions & 0 deletions src/Qwiq.Core/Proxies/ExternalLinkProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Tfs = Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace Microsoft.Qwiq.Proxies
{
public class ExternalLinkProxy : LinkProxy, IExternalLink
{
private readonly Tfs.ExternalLink externalLink;

internal ExternalLinkProxy(Tfs.ExternalLink externalLink) : base(externalLink)
{
this.externalLink = externalLink;
}

public string LinkedArtifactUri
{
get { return this.externalLink.LinkedArtifactUri; }
}

public string ArtifactLinkTypeName
{
get { return this.externalLink.ArtifactLinkType.Name; }
}
}
}
3 changes: 3 additions & 0 deletions src/Qwiq.Core/Qwiq.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
<Compile Include="IField.cs" />
<Compile Include="IFieldCollection.cs" />
<Compile Include="IFieldConflict.cs" />
<Compile Include="IExternalLink.cs" />
<Compile Include="IHyperlink.cs" />
<Compile Include="IIdentityDescriptor.cs" />
<Compile Include="IIdentityManagementService.cs" />
Expand Down Expand Up @@ -292,6 +293,7 @@
<Compile Include="Proxies\FieldCollectionProxy.cs" />
<Compile Include="Proxies\FieldConflictProxy.cs" />
<Compile Include="Proxies\FieldProxy.cs" />
<Compile Include="Proxies\ExternalLinkProxy.cs" />
<Compile Include="Proxies\HyperlinkProxy.cs" />
<Compile Include="Proxies\IdentityDescriptorProxy.cs" />
<Compile Include="Proxies\IdentityManagementServiceProxy.cs" />
Expand All @@ -314,6 +316,7 @@
<Compile Include="Proxies\WorkItemStoreProxy.cs" />
<Compile Include="Proxies\WorkItemTypeProxy.cs" />
<Compile Include="QueryFactory.cs" />
<Compile Include="RegisteredLinkTypeMapper.cs" />
<Compile Include="SaveFlags.cs" />
<Compile Include="ServerRejectedChangesException.cs" />
<Compile Include="ValidationException.cs" />
Expand Down
13 changes: 13 additions & 0 deletions src/Qwiq.Core/RegisteredLinkTypeMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Linq;
using Tfs = Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace Microsoft.Qwiq
{
internal static class RegisteredLinkTypeMapper
{
public static Tfs.RegisteredLinkType Map(Tfs.WorkItemStore store, string linkTypeName)
=> store.RegisteredLinkTypes
.OfType<Tfs.RegisteredLinkType>()
.FirstOrDefault(x => x.Name == linkTypeName);
}
}

0 comments on commit 30e9e37

Please sign in to comment.