public static string CreateConflictDetails(
            string sourceItemId,
            string sourceItemRevision,
            string sourceFieldRefName,
            WorkItemType targetWorkItemType)
        {
            InvalidFieldConflictTypeDetails dtls =
                new InvalidFieldConflictTypeDetails(sourceItemId, sourceItemRevision, sourceFieldRefName, targetWorkItemType);

            return(dtls.Properties.ToString());
        }
예제 #2
0
        private bool CanResolveByFieldMap(
            MigrationConflict conflict,
            ConflictResolutionRule rule)
        {
            if (conflict.ConflictedChangeAction == null)
            {
                throw new InvalidOperationException();
            }

            if (conflict.ConflictedChangeAction.MigrationActionDescription == null)
            {
                throw new InvalidOperationException();
            }

            var actionDataKeys = new InvalidFieldConflictUseFieldMapAction().ActionDataKeys;

            if (actionDataKeys.Count != rule.DataField.Length)
            {
                TraceManager.TraceInformation(TfsWITAdapterResources.ErrorResolutionRuleContainsInvalidData,
                                              rule.RuleReferenceName);
                return(false);
            }
            foreach (DataField df in rule.DataField)
            {
                if (!actionDataKeys.Contains(df.FieldName))
                {
                    TraceManager.TraceInformation(TfsWITAdapterResources.ErrorResolutionRuleContainsInvalidDataField,
                                                  rule.RuleReferenceName, df.FieldName);
                    return(false);
                }
            }

            string mapFromValue = rule.DataFieldDictionary[InvalidFieldConflictUseFieldMapAction.DATAKEY_MAP_FROM];
            InvalidFieldConflictType conflictType = conflict.ConflictType as InvalidFieldConflictType;

            if (null == conflictType)
            {
                throw new InvalidOperationException();
            }
            InvalidFieldConflictTypeDetails conflictDetails = conflictType.GetConflictDetails(conflict);

            return(TFStringComparer.WorkItemFieldReferenceName.Equals(mapFromValue, conflictDetails.SourceFieldRefName));
        }
        public override string TranslateConflictDetailsToReadableDescription(string dtls)
        {
            if (string.IsNullOrEmpty(dtls))
            {
                throw new ArgumentNullException("dtls");
            }

            InvalidFieldConflictTypeDetails details = null;

            try
            {
                ConflictDetailsProperties properties = ConflictDetailsProperties.Deserialize(dtls);
                details = new InvalidFieldConflictTypeDetails(properties);
            }
            catch (Exception)
            {
                try
                {
                    GenericSerializer <InvalidFieldConflictTypeDetails> serializer =
                        new GenericSerializer <InvalidFieldConflictTypeDetails>();

                    details = serializer.Deserialize(dtls);
                }
                catch (Exception)
                {
                    // do nothing, fall back to raw string later
                }
            }

            if (null != details)
            {
                return(string.Format(
                           "Source Item {0} (revision {1}) contains Field {2} that does not exist on Work Item Type '{3}' of the target project '{4}'.",
                           details.SourceWorkItemID, details.SourceWorkItemRevision,
                           details.SourceFieldRefName, details.TargetWorkItemType, details.TargetTeamProject));
            }
            else
            {
                return(dtls);
            }
        }
예제 #4
0
        private ConflictResolutionResult ResolveByFieldMap(MigrationConflict conflict, ConflictResolutionRule rule, out List <MigrationAction> actions)
        {
            actions = null;

            InvalidFieldConflictType conflictType = conflict.ConflictType as InvalidFieldConflictType;

            if (null == conflictType)
            {
                throw new InvalidOperationException();
            }

            string mapFromValue = rule.DataFieldDictionary[InvalidFieldConflictUseFieldMapAction.DATAKEY_MAP_FROM];
            string mapToValue   = rule.DataFieldDictionary[InvalidFieldConflictUseFieldMapAction.DATAKEY_MAP_TO];

            if (string.IsNullOrEmpty(mapToValue))
            {
                return(DropField(conflict, mapFromValue));
            }

            InvalidFieldConflictTypeDetails conflictDetails = conflictType.GetConflictDetails(conflict);

            //
            // apply field map to the Action's Description document
            //
            XmlDocument desc   = conflict.ConflictedChangeAction.MigrationActionDescription;
            XmlNode     column = desc.SelectSingleNode(string.Format(
                                                           @"/WorkItemChanges/Columns/Column[@ReferenceName=""{0}""]", conflictDetails.SourceFieldRefName));

            if (column == null ||
                !TFStringComparer.WorkItemFieldReferenceName.Equals(mapFromValue, column.Attributes["ReferenceName"].Value))
            {
                return(new ConflictResolutionResult(false, ConflictResolutionType.Other));
            }
            column.Attributes["ReferenceName"].Value = mapToValue;

            //note: changes to "MigrationConflict conflict" is saved by the conflict manager automatically
            return(new ConflictResolutionResult(true, ConflictResolutionType.UpdatedConflictedChangeAction));
        }