示例#1
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));
        }
示例#2
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));
        }