Esempio n. 1
0
        private JsonPatchOperation GetAddHyperlinkWithCommentOperation(IList <WorkItem> targetWorkItems, WorkItemMigrationState state, int sourceId, int targetId, WorkItem sourceWorkItem, ISet <string> enabledPhaseStatuses)
        {
            IList <WorkItemRelation> targetRelations = targetWorkItems.First(a => a.Id == targetId).Relations;

            foreach (WorkItemRelation targetRelation in targetRelations)
            {
                if (RelationHelpers.IsRelationHyperlinkToSourceWorkItem(context, targetRelation, sourceId))
                {
                    string hyperlink = context.WorkItemIdsUris[sourceId];

                    // only store the enabled phase statuses
                    RevAndPhaseStatus newRevAndPhaseStatus = new RevAndPhaseStatus();
                    newRevAndPhaseStatus.Rev         = sourceWorkItem.Rev.Value;
                    newRevAndPhaseStatus.PhaseStatus = enabledPhaseStatuses;
                    state.RevAndPhaseStatus          = newRevAndPhaseStatus;

                    // get the key even if its letter case is different but it matches otherwise
                    string idKeyFromFields = targetRelation.Attributes.GetKeyIgnoringCase(Constants.RelationAttributeId);
                    object attributeId     = targetRelation.Attributes[idKeyFromFields];

                    JsonPatchOperation addHyperlinkWithCommentOperation = MigrationHelpers.GetHyperlinkAddOperation(hyperlink, newRevAndPhaseStatus.GetCommentRepresentation(), attributeId);
                    return(addHyperlinkWithCommentOperation);
                }
            }

            throw new Exception($"Could not find hyperlink to source work item on target work item with id: {targetId}. Expected source work item id: {sourceId}");
        }
Esempio n. 2
0
        private IDictionary <int, WorkItemRelation> GetTargetIdToHyperlinkToSourceRelationMapping(IList <WorkItem> targetWorkItems, IDictionary <int, WorkItemMigrationState> targetToWorkItemMigrationState)
        {
            Dictionary <int, WorkItemRelation> result = new Dictionary <int, WorkItemRelation>();

            foreach (WorkItem targetWorkItem in targetWorkItems)
            {
                if (targetWorkItem.Relations == null)
                {
                    throw new ValidationException($"Target work item with id: {targetWorkItem.Id} does not have any relations.");
                }

                foreach (WorkItemRelation relation in targetWorkItem.Relations)
                {
                    //check for hyperlink to the source - used for incremental updates
                    int sourceId = targetToWorkItemMigrationState[targetWorkItem.Id.Value].SourceId;
                    int targetId = targetWorkItem.Id.Value;
                    if (RelationHelpers.IsRelationHyperlinkToSourceWorkItem(ValidationContext, relation, sourceId))
                    {
                        result.Add(targetId, relation);
                        break;
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
        private RevAndPhaseStatus GetRevAndPhaseStatus(WorkItem targetWorkItem, int sourceWorkItemId)
        {
            if (targetWorkItem.Relations != null)
            {
                foreach (WorkItemRelation relation in targetWorkItem.Relations)
                {
                    if (RelationHelpers.IsRelationHyperlinkToSourceWorkItem(context, relation, sourceWorkItemId))
                    {
                        // get the key even if its letter case is different but it matches otherwise
                        string keyFromFields = relation.Attributes.GetKeyIgnoringCase(Constants.RelationAttributeComment);
                        string relationRevAndPhaseStatusComment = relation.Attributes[keyFromFields].ToString();

                        RevAndPhaseStatus revAndPhaseStatus = new RevAndPhaseStatus(relationRevAndPhaseStatusComment);
                        return(revAndPhaseStatus);
                    }
                }
            }

            throw new Exception($"Could not find comment in relation hyperlink to source work item on target work item with id: {targetWorkItem.Id.Value}. Expected source work item id: {sourceWorkItemId}");
        }