Пример #1
0
        private bool TryIgnoreNonFieldConflict(MigrationConflict conflict)
        {
            long targetChangeActionId;
            bool retVal = WITEditEditConflictType.TryGetConflictedTargetChangeActionId(conflict.ConflictDetails, out targetChangeActionId);

            if (!retVal)
            {
                // backward compatibility:
                // old-style edit/edit conflict details does not include target change action id
                // in that case, we can't find a change action to complete the anlaysis
                return(false);
            }

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                // find the target-side change action (should be a delta table entry)
                var targetChangeActionQuery = context.RTChangeActionSet.Where(a => a.ChangeActionId == targetChangeActionId);
                if (targetChangeActionQuery.Count() != 1)
                {
                    return(false);
                }
                RTChangeAction targetChangeAction = targetChangeActionQuery.First();

                XmlDocument targetSideChanges = new XmlDocument();
                targetSideChanges.LoadXml(targetChangeAction.ActionData);

                // if there are edits on the same field, we *cannot* ignore the conflict
                return(!(EditOnSameField(conflict.ConflictedChangeAction.MigrationActionDescription, targetSideChanges)));
            }
        }
Пример #2
0
        private bool TakeSource(MigrationConflict conflict)
        {
            // find the target-side change action (should be a delta table entry)
            // SIDE NOTE:
            //  upon detection of a wit edit/edit conflict, we create
            //  1. an edit/edit conflict for the source side change group/action
            //  2. a chainonconflictconflict for the target side's (using the source-side conflict id as the scopehint)
            // look up for target-side conflicted change action id
            long targetChangeActionId;
            bool retVal = WITEditEditConflictType.TryGetConflictedTargetChangeActionId(conflict.ConflictDetails, out targetChangeActionId);

            if (!retVal)
            {
                // backward compatibility:
                // old-style edit/edit conflict details does not include target change action id
                // in that case, we can't find a change action to complete the anlaysis
                return(false);
            }

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                Debug.Assert(conflict.ConflictedChangeAction != null, "Edit/Edit conflict ConflictedCangeAction is NULL");

                // Extract all fields updated in the target change action
                string[] sourceSideChangedFields = ExtractFieldRefNames(conflict.ConflictedChangeAction.MigrationActionDescription);

                // find the target-side change action (should be a delta table entry)
                var changeActionQuery = context.RTChangeActionSet.Where(a => a.ChangeActionId == targetChangeActionId);
                if (changeActionQuery.Count() != 1)
                {
                    return(false);
                }
                RTChangeAction targetChangeAction = changeActionQuery.First();

                // drop the source-side updated fields from the target-side change
                // example:
                // source side change includes Field1, Field2, Field3
                // target side change includes Field1, Field2, Field5, Field 6
                // By taking source, we want to migrate Field1, Field2, Field3 to target side
                // Then migrate Field5, Field 6 to source side, i.e. dropping Field1, Field2
                XmlDocument targetSideChanges = new XmlDocument();
                targetSideChanges.LoadXml(targetChangeAction.ActionData);
                DropFields(targetSideChanges, sourceSideChangedFields);

                // update result for target change
                targetChangeAction.ActionData = targetSideChanges.OuterXml;
                SkipChangeWithZeroFieldUpdates(targetChangeAction);

                context.TrySaveChanges();
                return(true);
            }
        }
Пример #3
0
        private bool TakeTarget(MigrationConflict conflict)
        {
            // look up for target-side conflicted change action id
            long targetChangeActionId;
            bool retVal = WITEditEditConflictType.TryGetConflictedTargetChangeActionId(conflict.ConflictDetails, out targetChangeActionId);

            if (!retVal)
            {
                // backward compatibility:
                // old-style edit/edit conflict details does not include target change action id
                // in that case, we can't find a change action to complete the anlaysis
                return(false);
            }

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                Debug.Assert(conflict.ConflictedChangeAction != null, "Edit/Edit conflict ConflictedCangeAction is NULL");

                // find the target-side change action (should be a delta table entry)
                var changeActionQuery = context.RTChangeActionSet.Where(a => a.ChangeActionId == targetChangeActionId);
                if (changeActionQuery.Count() != 1)
                {
                    return(false);
                }
                RTChangeAction targetChangeAction = changeActionQuery.First();

                // Extract all fields updated in the target change action
                XmlDocument targetSideChanges = new XmlDocument();
                targetSideChanges.LoadXml(targetChangeAction.ActionData);
                string[] targetSideChangedFields = ExtractFieldRefNames(targetSideChanges);

                // drop the target-side updated fields from the source-side change
                // example:
                // target side change includes Field1, Field2, Field3
                // source side change includes Field1, Field2, Field5, Field 6
                // By taking target, we want to migrate Field1, Field2, Field3 to source side
                // Then migrate Field5, Field 6 to target side, i.e. dropping Field1, Field2
                DropFields(conflict.ConflictedChangeAction.MigrationActionDescription, targetSideChangedFields);

                // update result for source change
                if (!ChangeContainsFieldUpdates(conflict.ConflictedChangeAction.MigrationActionDescription))
                {
                    conflict.ConflictedChangeAction.ChangeGroup.Status = ChangeStatus.Skipped;
                    conflict.ConflictedChangeAction.ChangeGroup.Save();
                }

                // since we will return ConflictResolutionType.UpdatedConflictedChangeAction, conflict manager will update the conflicted change action for us
                return(true);
            }
        }