Exemple #1
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);

            foreach (Link l in source.WorkItem.Links)
            {
                ExternalLink el = l as ExternalLink;

                if (el != null && IsMyLink(el))
                {
                    var link = new Toolkit.Linking.ArtifactLink(
                        source.WorkItem.Id.ToString(CultureInfo.InvariantCulture),
                        new Toolkit.Linking.Artifact(source.Uri, s_sourceArtifactType),
                        new Toolkit.Linking.Artifact(LinkingConstants.ExternalArtifactPrefix + el.LinkedArtifactUri, s_targetArtifactType),
                        el.Comment,
                        this);
                    linkChangeGroup.AddChangeAction(new LinkChangeAction(WellKnownChangeActionId.Add, link,
                                                                         LinkChangeAction.LinkChangeActionStatus.Created,
                                                                         false));
                }
            }

            linkChangeGroups.Add(linkChangeGroup);
        }
Exemple #2
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);

            ReadOnlyCollection <ExternalLink> myLinks = ExtractMyLinks(source.WorkItem);

            foreach (ExternalLink el in myLinks)
            {
                var link = new Toolkit.Linking.ArtifactLink(
                    source.WorkItem.Id.ToString(CultureInfo.InvariantCulture),
                    new Toolkit.Linking.Artifact(source.Uri, s_sourceArtifactType),
                    new Toolkit.Linking.Artifact(el.LinkedArtifactUri, s_targetArtifactType),
                    el.Comment,
                    this);
                linkChangeGroup.AddChangeAction(new LinkChangeAction(WellKnownChangeActionId.Add, link,
                                                                     LinkChangeAction.LinkChangeActionStatus.Created,
                                                                     false));
            }

            linkChangeGroups.Add(linkChangeGroup);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public virtual List <ILink> GetLinks(
            IArtifact sourceArtifact,
            LinkType linkType)
        {
            string id;
            bool   idExtractionRslt = TryExtractArtifactId(sourceArtifact, out id);

            Debug.Assert(idExtractionRslt);

            int      workItemId             = int.Parse(id);
            WorkItem workItem               = m_migrationSource.WorkItemStore.WorkItemStore.GetWorkItem(workItemId);
            var      sourceArtifactWorkItem = new TfsMigrationWorkItem(m_migrationSource.WorkItemStore.Core, workItem);

            var perWorkItemlinkChangeGroups = new List <LinkChangeGroup>();

            ExtractLinkChangeActionsCallback(sourceArtifactWorkItem, perWorkItemlinkChangeGroups, null);

            var links = new List <ILink>();

            foreach (LinkChangeGroup group in perWorkItemlinkChangeGroups)
            {
                foreach (LinkChangeAction action in group.Actions)
                {
                    if (!action.Link.LinkType.ReferenceName.Equals(linkType.ReferenceName))
                    {
                        continue;
                    }

                    string mappedLinkType = m_linkTranslationService.LinkConfigurationLookupService.FindMappedLinkType(
                        m_configurationService.SourceId, action.Link.LinkType.ReferenceName);
                    if (!m_linkTranslationService.LinkTypeSupportedByOtherSide(mappedLinkType))
                    {
                        continue;
                    }

                    if (!links.Contains(action.Link))
                    {
                        links.Add(action.Link);
                    }
                }
            }

            return(links);
        }
Exemple #5
0
        public virtual 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);

            foreach (Link l in source.WorkItem.Links)
            {
                RelatedLink rl = l as RelatedLink;

                if (rl != null)
                {
                    // v1 work item related link does not have direction info
                    // to avoid generating two link change actions for the same link
                    // we only pick one from the work item of smaller id
                    if (source.WorkItem.Id >= rl.RelatedWorkItemId)
                    {
                        continue;
                    }

                    var link = new Toolkit.Linking.ArtifactLink(
                        source.WorkItem.Id.ToString(CultureInfo.InvariantCulture),
                        new Toolkit.Linking.Artifact(source.Uri, s_sourceArtifactType),
                        new Toolkit.Linking.Artifact(TfsWorkItemHandler.UriFromId(rl.RelatedWorkItemId.ToString(CultureInfo.InvariantCulture)), s_targetArtifactType),
                        rl.Comment,
                        this);
                    linkChangeGroup.AddChangeAction(new LinkChangeAction(WellKnownChangeActionId.Add, link,
                                                                         LinkChangeAction.LinkChangeActionStatus.Created,
                                                                         false));
                }
            }

            linkChangeGroups.Add(linkChangeGroup);
        }
Exemple #6
0
        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)
                    {
                        LinkChangeAction addLinkChangeAction = GetAddLinkChangeActionFromWorkItemLink(l, linkType);
                        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);
        }
Exemple #7
0
        private void CreateLinkChangeGroupsForForceSyncItem(TfsMigrationWorkItem tfsMigrationWorkItem)
        {
            if (m_linkService == null)
            {
                Debug.Fail("LinkService is null");
                return;
            }

            var linkChangeGroups         = new List <LinkChangeGroup>();
            var detectedLinkChangeGroups = new List <LinkChangeGroup>();

            ExtractLinkChangeActionsCallback(tfsMigrationWorkItem, detectedLinkChangeGroups, null);

            if (detectedLinkChangeGroups.Count == 0)
            {
                TraceManager.TraceInformation("Number of non-Work Item links: {0}", 0);
            }
            else
            {
                Dictionary <string, LinkChangeGroup> perWorkItemConsolidatedLinkChangeGroup = new Dictionary <string, LinkChangeGroup>();
                for (int i = 0; i < detectedLinkChangeGroups.Count; ++i)
                {
                    foreach (LinkChangeAction action in detectedLinkChangeGroups[i].Actions)
                    {
                        if (!perWorkItemConsolidatedLinkChangeGroup.ContainsKey(action.Link.SourceArtifact.Uri))
                        {
                            var linkChangeGroup = new LinkChangeGroup(
                                action.Link.SourceArtifactId, LinkChangeGroup.LinkChangeGroupStatus.Created, false);
                            perWorkItemConsolidatedLinkChangeGroup.Add(action.Link.SourceArtifact.Uri, linkChangeGroup);
                        }
                        perWorkItemConsolidatedLinkChangeGroup[action.Link.SourceArtifact.Uri].AddChangeAction(action);
                    }
                }

                foreach (var workItemLinkGroup in perWorkItemConsolidatedLinkChangeGroup)
                {
                    string workItemIdStr = TfsWorkItemHandler.IdFromUri(workItemLinkGroup.Key);
                    TraceManager.TraceInformation("Detected {0} non-Work Item links for force sync Work Item '{1}'",
                                                  workItemLinkGroup.Value.Actions.Count, workItemIdStr);

                    if (workItemLinkGroup.Value.Actions.Count > 0)
                    {
                        workItemLinkGroup.Value.IsForcedSync = true;
                        linkChangeGroups.Add(workItemLinkGroup.Value);
                    }
                }
            }

            if (tfsMigrationWorkItem.WorkItem.WorkItemLinks.Count > 0)
            {
                // Handle work item to work item links
                LinkChangeGroup workItemlinkChangeGroup = new LinkChangeGroup(
                    tfsMigrationWorkItem.WorkItem.Id.ToString(CultureInfo.InvariantCulture), LinkChangeGroup.LinkChangeGroupStatus.Created, false);

                Dictionary <string, LinkType> linkTypesByName = new Dictionary <string, LinkType>();
                foreach (WorkItemLink workItemLink in tfsMigrationWorkItem.WorkItem.WorkItemLinks)
                {
                    string   linkTypeName = workItemLink.LinkTypeEnd.LinkType.ReferenceName;
                    LinkType linkType;
                    if (!linkTypesByName.TryGetValue(linkTypeName, out linkType))
                    {
                        ExtendedLinkProperties extendedLinkProperties = new ExtendedLinkProperties();

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

                    LinkChangeAction addLinkChangeAction = GetAddLinkChangeActionFromWorkItemLink(workItemLink, linkType);
                    workItemlinkChangeGroup.AddChangeAction(addLinkChangeAction);
                }
                if (workItemlinkChangeGroup.Actions.Count > 0)
                {
                    workItemlinkChangeGroup.IsForcedSync = true;
                    linkChangeGroups.Add(workItemlinkChangeGroup);
                    TraceManager.TraceInformation("Detected {0} Work Item links for force sync Work Item '{1}'",
                                                  workItemlinkChangeGroup.Actions.Count, tfsMigrationWorkItem.WorkItem.Id);
                }
            }

            // Persist link change groups to DB
            if (linkChangeGroups.Count > 0)
            {
                m_linkService.AddChangeGroups(linkChangeGroups);
            }
        }
Exemple #8
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);
        }
Exemple #9
0
        public override 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);

            foreach (Link l in source.WorkItem.Links)
            {
                RelatedLink rl = l as RelatedLink;

                if (rl != null)
                {
                    // v1 work item related link does not have direction info
                    // to avoid generating two link change actions for the same link
                    // we only pick one from the work item of smaller id
                    if (source.WorkItem.Id >= rl.RelatedWorkItemId)
                    {
                        continue;
                    }

                    #region TFS 2010 specific logic
                    if (rl.LinkTypeEnd != null &&
                        rl.LinkTypeEnd.LinkType != null)
                    {
                        if (rl.LinkTypeEnd.LinkType.ReferenceName.Equals(Tfs2010RelatedLinkTypeReferenceName, StringComparison.OrdinalIgnoreCase))
                        {
                            #endregion

                            var link = new Toolkit.Linking.ArtifactLink(
                                source.WorkItem.Id.ToString(CultureInfo.InvariantCulture),
                                new Toolkit.Linking.Artifact(source.Uri, s_sourceArtifactType),
                                new Toolkit.Linking.Artifact(TfsWorkItemHandler.UriFromId(rl.RelatedWorkItemId.ToString(CultureInfo.InvariantCulture)), s_targetArtifactType),
                                rl.Comment, this, rl.IsLocked);
                            linkChangeGroup.AddChangeAction(new LinkChangeAction(WellKnownChangeActionId.Add, link,
                                                                                 LinkChangeAction.LinkChangeActionStatus.Created,
                                                                                 false));
                        }
                    }
                    else
                    {
                        var link = new Toolkit.Linking.ArtifactLink(
                            source.WorkItem.Id.ToString(CultureInfo.InvariantCulture),
                            new Toolkit.Linking.Artifact(source.Uri, s_sourceArtifactType),
                            new Toolkit.Linking.Artifact(TfsWorkItemHandler.UriFromId(rl.RelatedWorkItemId.ToString(CultureInfo.InvariantCulture)), s_targetArtifactType),
                            rl.Comment,
                            this);
                        linkChangeGroup.AddChangeAction(new LinkChangeAction(WellKnownChangeActionId.Add, link,
                                                                             LinkChangeAction.LinkChangeActionStatus.Created,
                                                                             false));
                    }
                }
            }

            linkChangeGroups.Add(linkChangeGroup);
        }
Exemple #10
0
 public void ExtractLinkChangeActions(TfsMigrationWorkItem source, List <LinkChangeGroup> linkChangeGroups, WorkItemLinkStore store)
 {
     return;
 }