Example #1
0
        private ILink RealizeArtifactLinkFromEDM(RTArtifactLink rtArtifactLink)
        {
            Debug.Assert(LinkService.LinkEngine.AllSessionServiceContainerPairs.ContainsKey(SessionId) &&
                         LinkService.LinkEngine.AllSessionServiceContainerPairs[SessionId].ContainsKey(SourceId));
            ServiceContainer serviceContainer = LinkService.LinkEngine.AllSessionServiceContainerPairs[SessionId][SourceId];
            var linkProvider = serviceContainer.GetService(typeof(ILinkProvider)) as ILinkProvider;

            Debug.Assert(null != linkProvider);

            rtArtifactLink.LinkTypeReference.Load();
            string linkTypeRefName = rtArtifactLink.LinkType.ReferenceName;

            if (!linkProvider.SupportedLinkTypes.ContainsKey(linkTypeRefName))
            {
                throw new MigrationException(MigrationToolkitResources.ErrorLinkTypeNotSupported, linkTypeRefName);
            }

            LinkType linkType = linkProvider.SupportedLinkTypes[linkTypeRefName];

            var link = new ArtifactLink(rtArtifactLink.SourceArtifactId,
                                        new Artifact(rtArtifactLink.SourceArtifactUri, linkType.SourceArtifactType),
                                        new Artifact(rtArtifactLink.TargetArtifactUri, linkType.TargetArtifactType),
                                        rtArtifactLink.Comment, linkType, rtArtifactLink.IsLocked ?? false);

            return(link);
        }
Example #2
0
        private void ExtractDirectedLinks(
            WorkItem workItem,
            NonCyclicReferenceClosure closure)
        {
            List <int> workItemIdsToProcess = new List <int>();

            foreach (WorkItemLink l in workItem.WorkItemLinks)
            {
                if (!TFStringComparer.LinkName.Equals(l.LinkTypeEnd.LinkType.ReferenceName, ReferenceName))
                {
                    continue;
                }

                var sourceIdStr    = l.SourceId.ToString(CultureInfo.InvariantCulture);
                var targetIdStr    = l.TargetId.ToString(CultureInfo.InvariantCulture);
                var sourceUri      = TfsWorkItemHandler.UriFromId(sourceIdStr);
                var targetUri      = TfsWorkItemHandler.UriFromId(targetIdStr);
                var sourceArtifact = new ToolkitLinking.Artifact(sourceUri, s_sourceArtifactType);
                var targetArtifact = new ToolkitLinking.Artifact(targetUri, s_targetArtifactType);

                if (!closure.SourceArtifactUris.Contains(targetUri) &&
                    !closure.TargetArtifactUris.Contains(targetUri))
                {
                    workItemIdsToProcess.Add(l.TargetId);
                }

                if (l.LinkTypeEnd.IsForwardLink)
                {
                    var link = new ToolkitLinking.ArtifactLink(sourceIdStr, sourceArtifact, targetArtifact, l.Comment, this);
                    closure.AddValidLink(link);
                }
            }

            foreach (var workItemId in workItemIdsToProcess)
            {
                var wi = m_store.GetWorkItem(workItemId);
                if (null == wi)
                {
                    continue;
                }

                ExtractDirectedLinks(wi, closure);
            }
        }
Example #3
0
        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);
        }
Example #4
0
        public void ExtractLinkChangeActions(TfsMigrationWorkItem source, List <LinkChangeGroup> linkChangeGroups, WorkItemLinkStore store)
        {
            if (null == source)
            {
                throw new ArgumentNullException("source");
            }

            if (null == source.WorkItem)
            {
                throw new ArgumentException("source.WorkItem is null");
            }

            var linkChangeGroup = new LinkChangeGroup(
                source.WorkItem.Id.ToString(CultureInfo.InvariantCulture), LinkChangeGroup.LinkChangeGroupStatus.Created, false);

            List <string> revertedLinkSourceWorkItemUris = new List <string>();

            if (null != store)
            {
                revertedLinkSourceWorkItemUris = store.GetRevertedLinkSourceItems(source.Uri, ReferenceName);
            }

            foreach (WorkItemLink l in source.WorkItem.WorkItemLinks)
            {
                #region obsolete
                //// always recognize the "ForwardLink"
                //if (!l.LinkTypeEnd.IsForwardLink)
                //{
                //    continue;
                //}
                #endregion

                // always recognize the WorkItem with smaller Id for non-directional link
                if (!l.LinkTypeEnd.LinkType.IsDirectional && l.SourceId > l.TargetId)
                {
                    continue;
                }

                if (!TFStringComparer.LinkName.Equals(l.LinkTypeEnd.LinkType.ReferenceName, ReferenceName))
                {
                    continue;
                }

                var sourceIdStr    = l.SourceId.ToString(CultureInfo.InvariantCulture);
                var targetIdStr    = l.TargetId.ToString(CultureInfo.InvariantCulture);
                var sourceArtifact = new ToolkitLinking.Artifact(TfsWorkItemHandler.UriFromId(sourceIdStr), s_sourceArtifactType);
                var targetArtifact = new ToolkitLinking.Artifact(TfsWorkItemHandler.UriFromId(targetIdStr), s_targetArtifactType);

                ToolkitLinking.ArtifactLink link;
                if (l.LinkTypeEnd.IsForwardLink)
                {
                    link = new ToolkitLinking.ArtifactLink(sourceIdStr, sourceArtifact, targetArtifact, l.Comment, this, l.IsLocked);
                }
                else
                {
                    link = new ToolkitLinking.ArtifactLink(targetIdStr, targetArtifact, sourceArtifact, l.Comment, this, l.IsLocked);
                    if (revertedLinkSourceWorkItemUris.Contains(targetArtifact.Uri))
                    {
                        revertedLinkSourceWorkItemUris.Remove(targetArtifact.Uri);
                    }
                }

                var linkChangeAction = new LinkChangeAction(WellKnownChangeActionId.Add,
                                                            link,
                                                            LinkChangeAction.LinkChangeActionStatus.Created,
                                                            false);

                linkChangeGroup.AddChangeAction(linkChangeAction);
            }

            foreach (string revertedLinkSrcItemUri in revertedLinkSourceWorkItemUris)
            {
                string          sourceWorkItemId = TfsWorkItemHandler.IdFromUri(revertedLinkSrcItemUri);
                LinkChangeGroup group            =
                    new LinkChangeGroup(sourceWorkItemId, LinkChangeGroup.LinkChangeGroupStatus.Created, false);
                var deleteLinkChangeAction = new LinkChangeAction(
                    WellKnownChangeActionId.Delete,
                    new ToolkitLinking.ArtifactLink(sourceWorkItemId,
                                                    new ToolkitLinking.Artifact(revertedLinkSrcItemUri, s_sourceArtifactType),
                                                    new ToolkitLinking.Artifact(source.Uri, s_targetArtifactType),
                                                    string.Empty, this),
                    LinkChangeAction.LinkChangeActionStatus.Created, false);
                group.AddChangeAction(deleteLinkChangeAction);
                linkChangeGroups.Add(group);
            }

            linkChangeGroups.Add(linkChangeGroup);
        }
        private LinkChangeGroup GetLinkChangeGroupFromLinkChanges(TfsMigrationWorkItem source)
        {
            LinkChangeGroup linkChangeGroup = new LinkChangeGroup(
                source.WorkItem.Id.ToString(CultureInfo.InvariantCulture), LinkChangeGroup.LinkChangeGroupStatus.Created, false);

            Dictionary <string, LinkType> linkTypesByName = new Dictionary <string, LinkType>();

            foreach (WorkItemLinkChange linkChange in source.LinkChanges)
            {
                LinkType linkType;
                if (!linkTypesByName.TryGetValue(linkChange.LinkType, out linkType))
                {
                    ExtendedLinkProperties extendedLinkProperties = new ExtendedLinkProperties();

                    linkType = new WorkItemLinkTypeBase(linkChange.LinkType,
                                                        linkChange.LinkType,
                                                        extendedLinkProperties,
                                                        m_migrationSource.WorkItemStore.WorkItemStore);
                    linkTypesByName.Add(linkChange.LinkType, linkType);
                }

                bool actionAdded = false;
                if (linkChange.IsActive)  // Link added
                {
                    // Get matching link l from WorkItem links collection
                    WorkItemLink l = GetWorkItemLinkFromLinkChange(source, linkChange);

                    if (l != null)
                    {
                        var sourceIdStr    = l.SourceId.ToString(CultureInfo.InvariantCulture);
                        var targetIdStr    = l.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 (l.LinkTypeEnd.IsForwardLink)
                        {
                            link = new ToolkitLinking.ArtifactLink(sourceIdStr, sourceArtifact, targetArtifact, l.Comment, linkType, l.IsLocked);
                        }
                        else
                        {
                            link = new ToolkitLinking.ArtifactLink(targetIdStr, targetArtifact, sourceArtifact, l.Comment, linkType, l.IsLocked);
                        }

                        var addLinkChangeAction = new LinkChangeAction(WellKnownChangeActionId.Add,
                                                                       link,
                                                                       LinkChangeAction.LinkChangeActionStatus.Created,
                                                                       false);
                        addLinkChangeAction.ServerLinkChangeId = linkChange.RowVersion.ToString();
                        linkChangeGroup.AddChangeAction(addLinkChangeAction);
                        actionAdded = true;
                    }
                    else
                    {
                        TraceManager.TraceInformation(String.Format(
                                                          "Unable to find link on work item {0} corresponding to detected link addition from {1} to {2} of type {3}; it may have been recently deleted",
                                                          source.WorkItem.Id, linkChange.SourceID, linkChange.TargetID, linkChange.LinkType));
                    }
                }
                else // Link deleted
                {
                    var deleteLinkChangeAction = new LinkChangeAction(
                        WellKnownChangeActionId.Delete,
                        new ToolkitLinking.ArtifactLink(linkChange.SourceID.ToString(),
                                                        new ToolkitLinking.Artifact(TfsWorkItemHandler.UriFromId(linkChange.SourceID.ToString()), WorkItemLinkTypeBase.s_sourceArtifactType),
                                                        new ToolkitLinking.Artifact(TfsWorkItemHandler.UriFromId(linkChange.TargetID.ToString()), WorkItemLinkTypeBase.s_targetArtifactType),
                                                        string.Empty, linkType),
                        LinkChangeAction.LinkChangeActionStatus.Created, false);
                    deleteLinkChangeAction.ServerLinkChangeId = linkChange.RowVersion.ToString();
                    linkChangeGroup.AddChangeAction(deleteLinkChangeAction);
                    actionAdded = true;
                }

                if (actionAdded)
                {
                    TraceManager.TraceVerbose("Adapter: Generating link change action: {0} '{1}'->'{2}' (Type: {3})",
                                              linkChange.IsActive ? "Add" : "Delete", linkChange.SourceID, linkChange.TargetID, linkChange.LinkType);
                }
            }

            return(linkChangeGroup);
        }