Exemplo n.º 1
0
        /// <summary>
        /// Generate delta table
        /// </summary>
        internal void GenerateDeltaTables(Guid sourceId)
        {
            Debug.Assert(m_serviceContainers.ContainsKey(sourceId),
                         string.Format(MigrationToolkitResources.UnknownSourceId, sourceId));

            IAnalysisProvider analysisProvider;

            if (!m_analysisProviders.TryGetValue(sourceId, out analysisProvider))
            {
                throw new MigrationException(string.Format(
                                                 MigrationToolkitResources.Culture,
                                                 MigrationToolkitResources.UnknownSourceId,
                                                 sourceId));
            }

            try
            {
                ChangeGroupService cgService =
                    m_serviceContainers[sourceId].GetService(typeof(ChangeGroupService)) as ChangeGroupService;
                Debug.Assert(null != cgService, "Change group service is not properly initialized");
                cgService.RemoveIncompleteChangeGroups();

                analysisProvider.GenerateDeltaTable();
            }
            catch (MigrationUnresolvedConflictException)
            {
                // We have already created an unresolved conflict, just return.
                return;
            }
            catch (Exception e)
            {
                ConflictManager manager = m_serviceContainers[sourceId].GetService(typeof(ConflictManager)) as ConflictManager;
                ErrorManager.TryHandleException(e, manager);
            }
        }
        /// <summary>
        /// Initialize configuration services and add it to service container
        /// </summary>
        private void CreateServices()
        {
            Debug.Assert(m_serviceContainers.Count == 2);
            ChangeGroupManager changeGroupManager = null;

            foreach (KeyValuePair <Guid, ServiceContainer> container in m_serviceContainers)
            {
                ConfigurationService configurationService = new ConfigurationService(m_globalConfiguration, Configuration, container.Key);
                container.Value.AddService(typeof(ConfigurationService), configurationService);

                var sqlChangeGroupManager             = new SqlChangeGroupManager(m_session, container.Key);
                ChangeGroupService changeGroupService = new ChangeGroupService(sqlChangeGroupManager);
                sqlChangeGroupManager.ChangeGroupService = changeGroupService;
                container.Value.AddService(typeof(ChangeGroupService), changeGroupService);

                if (null == changeGroupManager)
                {
                    changeGroupManager = sqlChangeGroupManager;
                }
                else
                {
                    changeGroupManager.OtherSideChangeGroupManager    = sqlChangeGroupManager;
                    sqlChangeGroupManager.OtherSideChangeGroupManager = changeGroupManager;
                }
            }
        }
        /// <summary>
        /// Initialize method of the session object
        /// </summary>
        internal void Initialize(int sessionRunId)
        {
            m_internalSessionRunId = sessionRunId;

            // fully initialize the change group managers
            foreach (var serviceContainer in m_serviceContainers.Values)
            {
                ChangeGroupService changeGroupService = serviceContainer.GetService(typeof(ChangeGroupService)) as ChangeGroupService;
                changeGroupService.Initialize(sessionRunId);
            }
        }
Exemplo n.º 4
0
        private bool updateConversionHistory(MigrationConflict conflict, ConflictResolutionRule rule, IServiceContainer serviceContainer)
        {
            if (!rule.DataFieldDictionary.ContainsKey(VCContentConflictUserMergeChangeAction.MigrationInstructionChangeId) ||
                !rule.DataFieldDictionary.ContainsKey(VCContentConflictUserMergeChangeAction.DeltaTableChangeId))
            {
                return(false);
            }

            ChangeGroupService changeGroupService       = serviceContainer.GetService(typeof(ChangeGroupService)) as ChangeGroupService;
            string             migrationInstructionName = rule.DataFieldDictionary[VCContentConflictUserMergeChangeAction.MigrationInstructionChangeId];
            string             deltaTableName           = rule.DataFieldDictionary[VCContentConflictUserMergeChangeAction.DeltaTableChangeId];
            string             comment = rule.RuleDescription;

            return(changeGroupService.UpdateConversionHistoryAndRemovePendingChangeGroups(migrationInstructionName, deltaTableName, comment));
        }
Exemplo n.º 5
0
        private void DetectBasicConflicts(ChangeGroupService targetChangeGroupService, Guid targetSystemId, Guid sourceSystemId)
        {
            TraceManager.TraceInformation("Starting basic conflict detection");
            if (null == m_basicConflictAnalysisService)
            {
                return;
            }

            m_basicConflictAnalysisService.Configuration            = m_session.Configuration;
            m_basicConflictAnalysisService.TargetChangeGroupService = targetChangeGroupService;
            m_basicConflictAnalysisService.ConflictManager          = m_serviceContainers[targetSystemId].GetService(typeof(ConflictManager)) as ConflictManager;
            m_basicConflictAnalysisService.TranslationService       = m_translationService;
            m_basicConflictAnalysisService.TargetSystemId           = targetSystemId;
            m_basicConflictAnalysisService.SourceSystemId           = sourceSystemId;
            m_basicConflictAnalysisService.Analyze();
            TraceManager.TraceInformation("Finishing basic conflict detection");
        }
Exemplo n.º 6
0
        private void ProviderDetectConflicts(Guid targetSystemId, ChangeGroupService targetChangeGroupService)
        {
            Debug.Assert(m_serviceContainers.ContainsKey(targetSystemId),
                         string.Format(MigrationToolkitResources.UnknownSourceId, targetSystemId));

            IAnalysisProvider targetAnalysisProvider;

            if (!m_analysisProviders.TryGetValue(targetSystemId, out targetAnalysisProvider))
            {
                throw new MigrationException(string.Format(
                                                 MigrationToolkitResources.Culture,
                                                 MigrationToolkitResources.UnknownSourceId,
                                                 targetSystemId));
            }

            try
            {
                int pageNumber = 0;
                IEnumerable <ChangeGroup> changeGroups;
                do
                {
                    TraceManager.TraceInformation("Loading {0} ChangeGroup(s)", m_pageSize);
                    changeGroups = targetChangeGroupService.NextMigrationInstructionTablePage(pageNumber++, m_pageSize, true, false);

                    foreach (ChangeGroup nextChangeGroup in changeGroups)
                    {
                        TraceManager.TraceInformation("Target AnalysisProvider detecting conflicts in ChangeGroup #{0}", nextChangeGroup.ChangeGroupId);
                        targetAnalysisProvider.DetectConflicts(nextChangeGroup);
                    }
                }while (changeGroups.Count() == m_pageSize);
            }
            catch (MigrationUnresolvedConflictException)
            {
                // We have already created an unresolved conflict, just return.
                return;
            }
            catch (Exception e)
            {
                ConflictManager manager = m_serviceContainers[targetSystemId].GetService(typeof(ConflictManager)) as ConflictManager;
                ErrorManager.TryHandleException(e, manager);
            }
        }
        /// <summary>
        /// Establish migration context (e.g. WIT metadata sync) on the "sourceId" side
        /// </summary>
        /// <param name="sourceId"></param>
        internal virtual void EstablishContext(Guid sourceId)
        {
            Debug.Assert(m_serviceContainers.ContainsKey(sourceId),
                         string.Format(MigrationToolkitResources.UnknownSourceId, sourceId));

            IMigrationProvider migrationProvider;

            if (!m_migrationProviders.TryGetValue(sourceId, out migrationProvider))
            {
                throw new MigrationException(string.Format(
                                                 MigrationToolkitResources.Culture,
                                                 MigrationToolkitResources.UnknownSourceId,
                                                 sourceId));
            }

            Guid masterSourceId = GetMasterSourceId(sourceId);

            Debug.Assert(!masterSourceId.Equals(Guid.Empty));

            ChangeGroupService sourceSystemChangeGroupService =
                m_serviceContainers[masterSourceId].GetService(typeof(ChangeGroupService)) as ChangeGroupService;

            try
            {
                migrationProvider.EstablishContext(sourceSystemChangeGroupService);
            }
            catch (MigrationUnresolvedConflictException)
            {
                // We have already created an unresolved conflict, just return.
                return;
            }
            catch (Exception e)
            {
                ConflictManager manager = m_serviceContainers[sourceId].GetService(typeof(ConflictManager)) as ConflictManager;
                ErrorManager.TryHandleException(e, manager);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initialize analysis services
        /// </summary>
        private void RegisterServices(Guid sourceId, RuntimeSession session)
        {
            Debug.Assert(m_serviceContainers.ContainsKey(sourceId),
                         string.Format(MigrationToolkitResources.UnknownSourceId, sourceId));

            ChangeActionRegistrationService changeActionRegistrationService = new ChangeActionRegistrationService();

            m_serviceContainers[sourceId].AddService(typeof(ChangeActionRegistrationService), changeActionRegistrationService);

            ContentTypeRegistrationService contentTypeRegistrationService = new ContentTypeRegistrationService();

            m_serviceContainers[sourceId].AddService(typeof(ContentTypeRegistrationService), contentTypeRegistrationService);

            ConflictManager conflictManagementService = new ConflictManager(sourceId);

            conflictManagementService.ScopeId = new Guid(m_session.Configuration.SessionUniqueId);
            m_serviceContainers[sourceId].AddService(typeof(ConflictManager), conflictManagementService);
            conflictManagementService.InitializePhase1(m_serviceContainers[sourceId]);

            RegisterGenericeConflicts(conflictManagementService);
            RegisterSessionSpecificConflicts(conflictManagementService, session.Configuration.SessionType);

            ICommentDecorationService commentDecorationService = new CommentDecorationService(m_session, m_serviceContainers[sourceId]);

            m_serviceContainers[sourceId].AddService(typeof(ICommentDecorationService), commentDecorationService);

            ChangeGroupService changeGroupService = m_serviceContainers[sourceId].GetService(typeof(ChangeGroupService)) as ChangeGroupService;

            if (changeGroupService != null)
            {
                changeGroupService.PreChangeGroupSaved += new EventHandler <ChangeGroupEventArgs>(changeGroupService_PreChangeGroupSaved);
                if (!m_changeGroupServices.ContainsKey(sourceId))
                {
                    m_changeGroupServices.Add(sourceId, changeGroupService);
                }
            }
        }
        internal void Migrate(Guid targetSideSourceId, SessionOrchestrationPolicy orchPolicy)
        {
            try
            {
                Debug.Assert(m_serviceContainers.ContainsKey(targetSideSourceId), string.Format(MigrationToolkitResources.UnknownSourceId, targetSideSourceId));

                ChangeGroupService changegroupService = (ChangeGroupService)m_serviceContainers[targetSideSourceId].GetService(
                    typeof(ChangeGroupService));
                Debug.Assert(changegroupService != null, string.Format("Change group service on {0} is not loaded", targetSideSourceId));

                changegroupService.DemoteInProgressActionsToPending();

                int pageNumber = 0;
                IEnumerable <ChangeGroup> changeGroups = null;

                long?firstConflictedChangeGroupId = null;
                if (StopMigrationEngineOnBasicConflict)
                {
                    firstConflictedChangeGroupId = changegroupService.GetFirstConflictedChangeGroup(ChangeStatus.Pending);
                }

                do
                {
                    // NOTE: we do not increment pageNumber here, because the processed ChangeGroups are marked "Complete" and no longer
                    //       appear in the table
                    TraceManager.TraceInformation("Loading {0} ChangeGroup(s)", m_pageSize);
                    changeGroups = changegroupService.NextMigrationInstructionTablePage(pageNumber, m_pageSize, false, false);

                    foreach (ChangeGroup nextChangeGroup in changeGroups)
                    {
                        if (firstConflictedChangeGroupId.HasValue &&
                            firstConflictedChangeGroupId <= nextChangeGroup.ChangeGroupId)
                        {
                            // we should not process any conflicted change group or the following ones
                            // if StopMigrationEngineOnBasicConflict is the policy
                            return;
                        }

                        //ToDo Session.OnMigratingChangeStarting(args);
                        TraceManager.TraceInformation("Processing ChangeGroup #{0}", nextChangeGroup.ChangeGroupId);
                        ProcessMigrInstructionTableEntry(nextChangeGroup, targetSideSourceId);
                        nextChangeGroup.UpdateStatus(ChangeStatus.InProgress);

                        if (NoActiveMigrationInstructionInChangeGroup(nextChangeGroup))
                        {
                            nextChangeGroup.Complete();
                            continue;
                        }

                        ConversionResult result;
                        try
                        {
                            result = m_migrationProviders[targetSideSourceId].ProcessChangeGroup(nextChangeGroup);
                        }
                        catch (MigrationUnresolvedConflictException)
                        {
                            // We have already created an unresolved conflict, just return.
                            return;
                        }
                        catch (Exception e)
                        {
                            ConflictManager manager = m_serviceContainers[targetSideSourceId].GetService(typeof(ConflictManager)) as ConflictManager;
                            ErrorManager.TryHandleException(e, manager);
                            return;
                        }

                        if (!result.ContinueProcessing)
                        {
                            return;
                        }

                        if (!string.IsNullOrEmpty(result.ChangeId))
                        {
                            FinishChangeGroupMigration(nextChangeGroup, result);
                            InvokePostChangeGroupMigrationAddins(targetSideSourceId, nextChangeGroup);
                        }
                        orchPolicy.Check();
                    }
                }while (changeGroups.Count() == m_pageSize);
            }
            catch (Microsoft.TeamFoundation.Migration.Toolkit.SessionOrchestrationPolicy.StopSingleTripException)
            {
                throw;
            }
            catch (Microsoft.TeamFoundation.Migration.Toolkit.SessionOrchestrationPolicy.StopSessionException)
            {
                throw;
            }
            catch (Exception e)
            {
                ConflictManager manager = m_serviceContainers[targetSideSourceId].GetService(typeof(ConflictManager)) as ConflictManager;
                ErrorManager.TryHandleException(e, manager);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Generate migration instructions
        /// </summary>
        internal void GenerateMigrationInstructions(Guid targetSystemId)
        {
            try
            {
                // Given target system, find change group service for source and for ourselves...
                ConfigurationService configurationService = m_serviceContainers[targetSystemId].GetService(typeof(ConfigurationService)) as ConfigurationService;

                // ToDo, not sure, we can probably just pass in ource system id to let target change group service to load it. But source/target may be different, not sqlchangegroupmanager
                ChangeGroupService sourceChangeGroupService = m_serviceContainers[configurationService.MigrationPeer].GetService(typeof(ChangeGroupService)) as ChangeGroupService;
                ChangeGroupService targetChangeGroupService = m_serviceContainers[targetSystemId].GetService(typeof(ChangeGroupService)) as ChangeGroupService;

                // CopySourceDeltaTableToTarget
                //ChangeGroup deltaTableEntry;

                if (StopMigrationEngineOnBasicConflict)
                {
                    // if one of the delta table entry on source side is conflicted, we stop
                    long?firstConflictedChangeGroupId = sourceChangeGroupService.GetFirstConflictedChangeGroup(ChangeStatus.DeltaPending);
                    if (firstConflictedChangeGroupId.HasValue)
                    {
                        return;
                    }

                    // if one of the migration instruction for target side is conflict, we also stop
                    firstConflictedChangeGroupId = targetChangeGroupService.GetFirstConflictedChangeGroup(ChangeStatus.Pending);
                    if (firstConflictedChangeGroupId.HasValue)
                    {
                        return;
                    }
                }

                ChangeActionRegistrationService changeActionRegistrationService =
                    m_serviceContainers[targetSystemId].GetService(typeof(ChangeActionRegistrationService)) as ChangeActionRegistrationService;

                int pageNumber = 0;
                IEnumerable <ChangeGroup> changeGroups;
                do
                {
                    // NOTE: we do not increment pageNumber here, because the processed ChangeGroups are marked "DeltaComplete" and no longer
                    //       appear in the delta table
                    changeGroups = sourceChangeGroupService.NextDeltaTablePage(pageNumber, m_pageSize, false);
                    foreach (ChangeGroup deltaTableEntry in changeGroups)
                    {
                        TraceManager.TraceInformation(string.Format(
                                                          "Generating migration instruction for ChangeGroup {0}",
                                                          deltaTableEntry.ChangeGroupId));

                        ChangeGroup migrationInstructionChangeGroup = targetChangeGroupService.CreateChangeGroupForMigrationInstructionTable(deltaTableEntry);

                        // NOTE:
                        // migration instruction change group is created using the target change group manager/service
                        // however, the MigrationItems in it are created by the source-side adapter
                        // by setting the UseOtherSideMigrationItemSerializers flag, we tell this change group to use the source-side change group manager
                        // to find the registered IMigrationItem serializer to persist these MigrationItems
                        migrationInstructionChangeGroup.UseOtherSideMigrationItemSerializers = true;

                        migrationInstructionChangeGroup.ReflectedChangeGroupId = deltaTableEntry.ChangeGroupId;

                        foreach (MigrationAction action in deltaTableEntry.Actions)
                        {
                            try
                            {
                                BeforeCopyDeltaTableEntryToMigrationInstructionTable(action, configurationService.MigrationPeer);
                            }
                            catch (UnmappedWorkItemTypeException unmappedWITEx)
                            {
                                ConflictManager conflictManager =
                                    m_serviceContainers[configurationService.MigrationPeer].GetService(typeof(ConflictManager)) as ConflictManager;

                                var conflict = WITUnmappedWITConflictType.CreateConflict(unmappedWITEx.SourceWorkItemType, action);

                                List <MigrationAction> actions;
                                var result = conflictManager.TryResolveNewConflict(conflictManager.SourceId, conflict, out actions);

                                if (!result.Resolved)
                                {
                                    continue;
                                }
                                else
                                {
                                    if (result.ResolutionType == ConflictResolutionType.SkipConflictedChangeAction)
                                    {
                                        action.State = ActionState.Skipped;
                                        continue;
                                    }
                                    else
                                    {
                                        // NOTE:
                                        // So far this conflict can only be:
                                        // 1. manually resolved (skipped) AFTER
                                        //    the configuration is updated with the requirement WIT mapping;
                                        // 2. skipping the conflicted migration action (i.e. not migrating the source
                                        //    Work Item type.
                                        Debug.Assert(
                                            false,
                                            string.Format("WITUnmappedWITConflict is auto-resolved. Skipping this assertion will SKIP the original conflicted action '{0}'.",
                                                          action.ActionId.ToString()));
                                        action.State = ActionState.Skipped;
                                        continue;
                                    }
                                }
                            }

                            if (action.State == ActionState.Skipped || action.ChangeGroup.ContainsBackloggedAction)
                            {
                                continue;
                            }
                            ChangeActionHandler actionHandler;
                            if (changeActionRegistrationService.TryGetChangeActionHandler(action.Action, action.ItemTypeReferenceName, out actionHandler))
                            {
                                try
                                {
                                    actionHandler(action, migrationInstructionChangeGroup);
                                }
                                catch (MigrationUnresolvedConflictException)
                                {
                                    // We have already created an unresolved conflict, just return.
                                    return;
                                }
                                catch (Exception e)
                                {
                                    ConflictManager manager = m_serviceContainers[targetSystemId].GetService(typeof(ConflictManager)) as ConflictManager;
                                    ErrorManager.TryHandleException(e, manager);
                                }
                            }
                            else
                            {
                                string            analysisProviderName;
                                IAnalysisProvider analysisProvider;
                                if (m_analysisProviders.TryGetValue(targetSystemId, out analysisProvider))
                                {
                                    analysisProviderName = analysisProvider.GetType().ToString();
                                }
                                else
                                {
                                    Debug.Fail("Unable to find IAnalysisProvider with Id: " + targetSystemId);
                                    analysisProviderName = "Unknown";
                                }
                                throw new MigrationException(
                                          string.Format(MigrationToolkitResources.Culture, MigrationToolkitResources.UnknownChangeAction,
                                                        action.Action.ToString(), analysisProviderName));
                            }
                        }

                        if (!migrationInstructionChangeGroup.ContainsBackloggedAction &&
                            migrationInstructionChangeGroup.Actions.Count > 0)
                        {
                            ChangeStatus status = migrationInstructionChangeGroup.Status;
                            migrationInstructionChangeGroup.Status = ChangeStatus.ChangeCreationInProgress;
                            migrationInstructionChangeGroup.Owner  = deltaTableEntry.Owner; // owner may be translated too
                            // Save the partial Change group into DB.
                            migrationInstructionChangeGroup.Save();

                            // Commit the status change together.
                            migrationInstructionChangeGroup.Status = status;
                            deltaTableEntry.Status = ChangeStatus.DeltaComplete;
                            migrationInstructionChangeGroup.Manager.BatchUpdateStatus(
                                new ChangeGroup[] { migrationInstructionChangeGroup, deltaTableEntry });
                        }
                        else
                        {
                            // If all change actions in the delta table entry are skipped.
                            // Just mark the delta table entry as completed.
                            deltaTableEntry.UpdateStatus(ChangeStatus.DeltaComplete);
                        }

                        if (this.StopRequested)
                        {
                            return;
                        }
                    }
                }while (changeGroups.Count() == m_pageSize);

                DetectBasicConflicts(targetChangeGroupService, targetSystemId, configurationService.MigrationPeer);

                if (this.StopRequested)
                {
                    return;
                }

                ProviderDetectConflicts(targetSystemId, targetChangeGroupService);

                if (this.StopRequested)
                {
                    return;
                }

                // dispose the target side delta table entries after we've done all conflict analysis
                targetChangeGroupService.BatchMarkMigrationInstructionsAsPending();
            }
            catch (Exception e)
            {
                ConflictManager manager = m_serviceContainers[targetSystemId].GetService(typeof(ConflictManager)) as ConflictManager;
                ErrorManager.TryHandleException(e, manager);
            }
        }
 public virtual void EstablishContext(ChangeGroupService sourceSystemChangeGroupService)
 {
     return;
 }