private bool TryGetSessionUniqueId(Configuration config, MigrationSource migrationSource, out Guid sessionUniqueId)
        {
            sessionUniqueId = Guid.Empty;

            try
            {
                Guid migrationSourceUniqueId = new Guid(migrationSource.InternalUniqueId);

                foreach (var session in config.SessionGroup.Sessions.Session)
                {
                    Guid leftSource  = new Guid(session.LeftMigrationSourceUniqueId);
                    Guid rightSource = new Guid(session.RightMigrationSourceUniqueId);

                    if (migrationSourceUniqueId.Equals(leftSource) || migrationSourceUniqueId.Equals(rightSource))
                    {
                        sessionUniqueId = session.SessionUniqueIdGuid;
                        return(true);
                    }
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }
Exemple #2
0
        private void InitializeCQClient()
        {
            Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource migrationSourceConfig = m_configurationService.MigrationSource;
            string dbSet  = migrationSourceConfig.ServerUrl;
            string userDb = migrationSourceConfig.SourceIdentifier;

            ICredentialManagementService credManagementService =
                m_serviceContainer.GetService(typeof(ICredentialManagementService)) as ICredentialManagementService;

            ICQLoginCredentialManager loginCredManager =
                CQLoginCredentialManagerFactory.CreateCredentialManager(credManagementService, migrationSourceConfig);

            // connect to user session
            UserSessionConnConfig = new ClearQuestConnectionConfig(loginCredManager.UserName,
                                                                   loginCredManager.Password,
                                                                   userDb,
                                                                   dbSet);
            m_userSession = CQConnectionFactory.GetUserSession(UserSessionConnConfig);

            #region we won't need admin session until we start syncing cq schema
            //// connect to admin session
            //if (!string.IsNullOrEmpty(loginCredManager.AdminUserName))
            //{
            //    AdminSessionConnConfig = new ClearQuestConnectionConfig(loginCredManager.AdminUserName,
            //                                                                loginCredManager.AdminPassword ?? string.Empty,
            //                                                                userDb,
            //                                                                dbSet);
            //    m_adminSession = CQConnectionFactory.GetAdminSession(AdminSessionConnConfig);
            //}
            #endregion
            MigrationContext = new ClearQuestMigrationContext(m_userSession, migrationSourceConfig);
        }
        public bool LinkTypeSupportedByOtherSide(string linkTypeReferenceName, Guid sourceId)
        {
            Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource peerMigrationSource =
                (sourceId == new Guid(LeftMigrationSource.InternalUniqueId)) ? RightMigrationSource : LeftMigrationSource;
            ILinkProvider linkProvider;

            if (m_linkProvidersByMigrationSourceId.TryGetValue(new Guid(peerMigrationSource.InternalUniqueId), out linkProvider))
            {
                return(linkProvider.SupportedLinkTypes.ContainsKey(linkTypeReferenceName));
            }
            else
            {
                return(false);
            }
        }
        private void CompareAddins(MigrationSource newMS, SettingsAddins newMSAddins, SettingsAddins currMSAddins)
        {
            if (newMSAddins.Addin.Count != currMSAddins.Addin.Count)
            {
                Guid sessionUniqueId;
                if (!TryGetSessionUniqueId(m_newConfig, newMS, out sessionUniqueId))
                {
                    return;
                }
                else
                {
                    SetImpactForSessionChange(sessionUniqueId);
                    return;
                }
            }

            foreach (var newAddin in newMSAddins.Addin)
            {
                bool matching = false;
                foreach (var currAddin in currMSAddins.Addin)
                {
                    if (newAddin.ReferenceName.Equals(currAddin.ReferenceName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (AddinCustomSettingMatches(newAddin, currAddin))
                        {
                            matching = true;
                        }

                        break;
                    }
                }

                if (!matching)
                {
                    Guid sessionUniqueId;
                    if (!TryGetSessionUniqueId(m_newConfig, newMS, out sessionUniqueId))
                    {
                        return;
                    }
                    else
                    {
                        SetImpactForSessionChange(sessionUniqueId);
                        return;
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Returns an IDiffProvider given a Migration source and a Dictionary of the providers found
        /// </summary>
        private IDiffProvider GetDiffProviderForMigrationSource(
            Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource migrationSource,
            Dictionary <Guid, ProviderHandler> providerHandlers)
        {
            Guid            providerGuid     = new Guid(migrationSource.InternalUniqueId);
            ProviderHandler providerHandler  = providerHandlers[providerGuid];
            Type            diffProviderType = Session.SessionType == SessionTypeEnum.VersionControl ? typeof(IVCDiffProvider) : typeof(IWITDiffProvider);
            IDiffProvider   diffProvider     = providerHandler.Provider.GetService(diffProviderType) as IDiffProvider;

            if (diffProvider == null)
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture, ServerDiffResources.ProviderDoesNotImplementVCDiffInterface, providerHandler.ProviderName));
            }

            DiffServiceContainer = new ServiceContainer();
            DiffServiceContainer.AddService(typeof(ConfigurationService), new ConfigurationService(Config, Session, providerGuid));
            DiffServiceContainer.AddService(typeof(Session), Session);
            DiffServiceContainer.AddService(typeof(ICredentialManagementService), new CredentialManagementService(Config));

            // If this is a work item session, and the provider implements ILinkProvider, get and initialize
            // the ILinkProvider service and add it to the ServiceContainer so that the IDiffProvider implementation
            // can get and use the ILinkProvider implementation
            ILinkProvider linkProvider = null;

            if (Session.SessionType == SessionTypeEnum.WorkItemTracking)
            {
                DiffServiceContainer.AddService(typeof(ITranslationService), new WITTranslationService(Session, null));

                linkProvider = providerHandler.Provider.GetService(typeof(ILinkProvider)) as ILinkProvider;
                if (linkProvider != null)
                {
                    ServerDiffLinkTranslationService diffLinkTranslationService =
                        new ServerDiffLinkTranslationService(this, new Guid(migrationSource.InternalUniqueId), new LinkConfigurationLookupService(Config.SessionGroup.Linking));
                    DiffServiceContainer.AddService(typeof(ILinkTranslationService), diffLinkTranslationService);

                    linkProvider.Initialize(DiffServiceContainer);
                    linkProvider.RegisterSupportedLinkTypes();
                    DiffServiceContainer.AddService(typeof(ILinkProvider), linkProvider);
                    m_linkProvidersByMigrationSourceId.Add(new Guid(migrationSource.InternalUniqueId), linkProvider);
                }
            }

            diffProvider.InitializeServices(DiffServiceContainer);
            diffProvider.InitializeClient(migrationSource);

            return(diffProvider);
        }
Exemple #6
0
        void TestEnvironment_AddCQWebUrlBase(MigrationTestEnvironment env, Configuration config)
        {
            Debug.Assert(config.SessionGroup.Sessions.Session.Count == 1);

            Guid leftSrcUniqueId = new Guid(config.SessionGroup.Sessions.Session[0].LeftMigrationSourceUniqueId);
            Guid leftProviderId  = new Guid(config.SessionGroup.MigrationSources[leftSrcUniqueId].ProviderReferenceName);

            if (leftProviderId.Equals(new Guid("D9637401-7385-4643-9C64-31585D77ED16"))) // CQ adapter id
            {
                Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource migrSrc = config.SessionGroup.MigrationSources[leftSrcUniqueId];
                if (null != migrSrc)
                {
                    CustomSetting setting = new CustomSetting();
                    setting.SettingKey   = "CQWebRecordUrlFormat";
                    setting.SettingValue = TestCQHyperLinkBaseUrl;
                    migrSrc.CustomSettings.CustomSetting.Add(setting);
                }
            }
        }
Exemple #7
0
        protected virtual void InitializeCQClient()
        {
            Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource migrationSourceConfig = m_configurationService.MigrationSource;
            string dbSet  = migrationSourceConfig.ServerUrl;
            string userDb = migrationSourceConfig.SourceIdentifier;

            ICredentialManagementService credManagementService =
                m_analysisServiceContainer.GetService(typeof(ICredentialManagementService)) as ICredentialManagementService;

            ICQLoginCredentialManager loginCredManager =
                CQLoginCredentialManagerFactory.CreateCredentialManager(credManagementService, migrationSourceConfig);

            // connect to user session
            UserSessionConnConfig = new ClearQuestConnectionConfig(loginCredManager.UserName,
                                                                   loginCredManager.Password,
                                                                   userDb,
                                                                   dbSet);
            m_userSession = CQConnectionFactory.GetUserSession(UserSessionConnConfig);

            #region admin session is not needed until we sync context
            //// connect to admin session
            //if (!string.IsNullOrEmpty(loginCredManager.AdminUserName))
            //{
            //    AdminSessionConnConfig = new ClearQuestConnectionConfig(loginCredManager.AdminUserName,
            //                                                                loginCredManager.AdminPassword ?? string.Empty,
            //                                                                userDb,
            //                                                                dbSet);
            //    m_adminSession = CQConnectionFactory.GetAdminSession(AdminSessionConnConfig);
            //}
            #endregion

            // parse the filter strings in the configuration file
            m_filters = new CQRecordFilters(m_configurationService.Filters, m_userSession);

            m_migrationContext = new ClearQuestMigrationContext(m_userSession, migrationSourceConfig);
        }
        public Endpoint(
            MonitorWatcher watcher,
            RuntimeEntityModel context,
            RTSession rtSession,
            RTMigrationSource rtMigrationSource,
            bool isRightMigrationSource,
            RTMigrationSource peerMigrationSource)
        {
            m_monitorWatcher = watcher;

            // TODO: Consider moving all of this initialization code to a new EndpointContext class that contains everything that the
            // Poll() method needs to do its job, and then have MonitorWatcher.GetEndpoints() pass the EndpointContext object as the single
            // arg to this constructor.

            this.Context                = context;
            this.RTMigrationSource      = rtMigrationSource;
            this.IsRightMigrationSource = isRightMigrationSource;
            this.PeerRTMigrationSource  = peerMigrationSource;

            BusinessModelManager businessModelManager = new BusinessModelManager();

            if (rtSession.SessionGroup == null)
            {
                rtSession.SessionGroupReference.Load();
            }

            Config = businessModelManager.LoadConfiguration(rtSession.SessionGroup.GroupUniqueId);
            if (Config == null)
            {
                throw new ApplicationException(
                          String.Format(CultureInfo.InvariantCulture, MigrationToolkitResources.SessionGroupNotFound,
                                        rtSession.SessionGroup.GroupUniqueId.ToString()));
            }

            // TODO: Modify ProdviderManager to take a constructor that does not require a Config and that just loads
            // all providers in the Plugins directory, then move this code up to the MonitorWatcher constructor and pass the
            // providerHandlers down as another argument to this constructor
            ProviderManager providerManager = new ProviderManager(Config);
            Dictionary <Guid, ProviderHandler> providerHandlers = providerManager.LoadProvider(new DirectoryInfo(Constants.PluginsFolderName));

            ProviderHandler providerHandler;

            if (!providerHandlers.TryGetValue(this.RTMigrationSource.UniqueId, out providerHandler))
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture,
                                                  MigrationToolkitResources.ProviderHandlerNotLoadedForMigrationSouce,
                                                  this.RTMigrationSource.FriendlyName));
            }

            Debug.Assert(providerHandler.Provider != null);
            SyncMonitorProvider = providerHandler.Provider.GetService(typeof(ISyncMonitorProvider)) as ISyncMonitorProvider;
            if (SyncMonitorProvider == null)
            {
                throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture,
                                                                MigrationToolkitResources.ProviderDoesNotImplementISyncMonitor,
                                                                providerHandler.ProviderName));
            }

            // Find the Session object corresponding to the RTSession
            if (Config.SessionGroup != null && Config.SessionGroup.Sessions != null)
            {
                foreach (var aSession in Config.SessionGroup.Sessions.Session)
                {
                    if (string.Equals(aSession.SessionUniqueId, rtSession.SessionUniqueId.ToString(), StringComparison.Ordinal))
                    {
                        Session = aSession;
                        break;
                    }
                }
            }
            if (Session == null)
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture,
                                                  MigrationToolkitResources.SessionNotFoundForMigrationSource,
                                                  rtSession.SessionGroup.GroupUniqueId.ToString(), RTMigrationSource.FriendlyName));
            }

            Guid migrationSourceGuid = new Guid(isRightMigrationSource ? Session.RightMigrationSourceUniqueId : Session.LeftMigrationSourceUniqueId);

            Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource migrationSource = Config.GetMigrationSource(migrationSourceGuid);
            Session.MigrationSources.Add(migrationSourceGuid, migrationSource);

            var serviceContainer = new ServiceContainer();

            serviceContainer.AddService(typeof(ITranslationService), new SyncMonitorTranslationService(Session));
            // We pass null for the global Configuration to the ConfigurationService constructor because its not handy and not needed in this context
            serviceContainer.AddService(typeof(ConfigurationService), new ConfigurationService(null, Session, migrationSourceGuid));
            SyncMonitorProvider.InitializeServices(serviceContainer);
            SyncMonitorProvider.InitializeClient(migrationSource);

            int filterPairIndex = IsRightMigrationSource ? 1 : 0;

            foreach (var filterPair in Session.Filters.FilterPair)
            {
                if (!filterPair.Neglect)
                {
                    m_filterStrings.Add(VCTranslationService.TrimTrailingPathSeparator(filterPair.FilterItem[filterPairIndex].FilterString));
                }
            }
        }
        private ConflictResolutionResult ResolveBySubmitMissingChanges(
            IServiceContainer serviceContainer,
            MigrationConflict conflict,
            ConflictResolutionRule rule,
            out List <MigrationAction> actions)
        {
            actions = null;
            var retVal = new ConflictResolutionResult(false, ConflictResolutionType.Other);

            WITTranslationService translationService = serviceContainer.GetService(typeof(ITranslationService)) as WITTranslationService;

            Debug.Assert(null != translationService, "translationService is not initialized or not a wit translation service");

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                RTSessionGroup rtSessionGroup = FindSessionGroupForConflictedAction(conflict, context);
                if (null == rtSessionGroup)
                {
                    return(retVal);
                }

                BM.BusinessModelManager bmm = new BM.BusinessModelManager();
                BM.Configuration        sessionGroupConfig = bmm.LoadConfiguration(rtSessionGroup.GroupUniqueId);

                // find target-side migration source config
                var  parentChangeGroup       = FindChangeGroupForConflictedAction(conflict, context);
                Guid targetMigrationSourceId = parentChangeGroup.SourceUniqueId;
                BM.MigrationSource targetMigrationSourceConfig = sessionGroupConfig.SessionGroup.MigrationSources[targetMigrationSourceId];
                if (null == targetMigrationSourceConfig)
                {
                    return(retVal);
                }

                // find source-side migration source config
                RTSession  rtSession     = FindSessionForConflictedAction(conflict, context);
                BM.Session parentSession = null;
                foreach (BM.Session s in sessionGroupConfig.SessionGroup.Sessions.Session)
                {
                    if (new Guid(s.SessionUniqueId).Equals(rtSession.SessionUniqueId))
                    {
                        parentSession = s;
                        break;
                    }
                }
                if (parentSession == null)
                {
                    return(retVal);
                }
                Guid sourceMigrationSourceId = ((new Guid(parentSession.LeftMigrationSourceUniqueId)).Equals(targetMigrationSourceId))
                    ? new Guid(parentSession.RightMigrationSourceUniqueId) : new Guid(parentSession.LeftMigrationSourceUniqueId);
                BM.MigrationSource sourceMigrationSourceConfig = sessionGroupConfig.SessionGroup.MigrationSources[sourceMigrationSourceId];
                if (null == sourceMigrationSourceConfig)
                {
                    return(retVal);
                }

                string sourceServerUrl   = sourceMigrationSourceConfig.ServerUrl;
                string sourceTeamProject = sourceMigrationSourceConfig.SourceIdentifier;
                string targetServerUrl   = targetMigrationSourceConfig.ServerUrl;
                string targetTeamProject = targetMigrationSourceConfig.SourceIdentifier;

                string srcWorkItemIdStr = TfsMigrationWorkItemStore.GetSourceWorkItemId(conflict.ConflictedChangeAction);
                Debug.Assert(!string.IsNullOrEmpty(srcWorkItemIdStr), "srcWorkItemId is null or empty");
                int srcWorkItemId;
                if (!int.TryParse(srcWorkItemIdStr, out srcWorkItemId))
                {
                    return(retVal);
                }

                string srcRevRanges    = rule.DataFieldDictionary[HistoryNotFoundSubmitMissingChangesAction.DATAKEY_REVISION_RANGE];
                int[]  sourceRevToSync = new int[0];
                if (string.IsNullOrEmpty(srcRevRanges))
                {
                    sourceRevToSync = ExtractMissingRevs(conflict.ConflictedChangeAction);
                }
                else
                {
                    if (!IntegerRange.TryParseRangeString(srcRevRanges, out sourceRevToSync))
                    {
                        return(retVal);
                    }
                }
                if (sourceRevToSync.Length == 0)
                {
                    return(retVal);
                }

                try
                {
                    // compute delta from source side
                    TfsWITAnalysisProvider analysisProvider = new TfsWITAnalysisProvider(sourceServerUrl, sourceTeamProject);
                    WorkItem sourceWorkItem = analysisProvider.GetWorkItem(srcWorkItemId);

                    Hist.MigrationAction[] sourceRevDetails = new Hist.MigrationAction[sourceRevToSync.Length];
                    for (int revIndex = 0; revIndex < sourceRevToSync.Length; ++revIndex)
                    {
                        var details = new TfsWITRecordDetails(sourceWorkItem, sourceRevToSync[revIndex]);
                        SanitizeDetails(details);
                        translationService.MapWorkItemTypeFieldValues(
                            sourceWorkItem.Id.ToString(), details.DetailsDocument, sourceMigrationSourceId);

                        TfsConstants.ChangeActionId actionId = (sourceRevToSync[revIndex] == 1 ? TfsConstants.ChangeActionId.Add : TfsConstants.ChangeActionId.Edit);
                        sourceRevDetails[revIndex] = new Hist.MigrationAction(sourceWorkItem.Id.ToString(), details, actionId);
                    }

                    // migrate to target side
                    TfsWITMigrationProvider migrationProvider = new TfsWITMigrationProvider(targetServerUrl, targetTeamProject, string.Empty);
                    Hist.ConversionResult   conversionResult  = migrationProvider.ProcessChangeGroup(sourceRevDetails);

                    // update conversion history
                    ConversionResult convRslt = new ConversionResult(sourceMigrationSourceId, targetMigrationSourceId);
                    convRslt.ChangeId           = HistoryNotFoundResolutionChangeId;
                    convRslt.ContinueProcessing = true;

                    foreach (var itemConvHist in conversionResult.ItemConversionHistory)
                    {
                        convRslt.ItemConversionHistory.Add(new ItemConversionHistory(
                                                               itemConvHist.SourceItemId, itemConvHist.SourceItemVersion, itemConvHist.TargetItemId, itemConvHist.TargetItemVersion));
                    }

                    parentChangeGroup.SessionRunReference.Load();
                    int sessionRunId = parentChangeGroup.SessionRun.Id;
                    convRslt.Save(sessionRunId, sourceMigrationSourceId);
                }
                catch (Exception ex)
                {
                    TraceManager.TraceException(ex);
                    retVal.Comment = ex.ToString();
                    return(retVal);
                }
            }

            retVal.Resolved = true;
            return(retVal);
        }
Exemple #10
0
 public LightWeightSource(Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource source)
 {
     FriendlyName = source.FriendlyName;
     UniqueId     = new Guid(source.InternalUniqueId);
 }
        private void InitializeTfsClient()
        {
            Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource migrationSourceConfiguration = m_configurationService.MigrationSource;
            Debug.Assert(null != migrationSourceConfiguration, "cannot get MigrationSource config from Session");


            TfsMigrationDataSource            dataSourceConfig = InitializeMigrationDataSource();
            ReadOnlyCollection <MappingEntry> filters          = m_configurationService.Filters;

            // Allow multiple filter strings from other adapters
            // Debug.Assert(filters.Count == 1, "filters.Count != 1 for WIT migration source");
            dataSourceConfig.Filter     = filters[0].Path;
            dataSourceConfig.ServerId   = migrationSourceConfiguration.ServerIdentifier;
            dataSourceConfig.ServerName = migrationSourceConfiguration.ServerUrl;
            dataSourceConfig.Project    = migrationSourceConfiguration.SourceIdentifier;

            this.m_migrationSource = new TfsWITMigrationSource(
                migrationSourceConfiguration.InternalUniqueId,
                dataSourceConfig.CreateWorkItemStore());
            this.m_migrationSource.WorkItemStore.ServiceContainer = this.m_analysisServiceContainer;

            bool?enableReflectedIdInsertion = null;

            foreach (CustomSetting setting in migrationSourceConfiguration.CustomSettings.CustomSetting)
            {
                if (setting.SettingKey.Equals(TfsConstants.DisableAreaPathAutoCreation, StringComparison.InvariantCultureIgnoreCase))
                {
                    m_migrationSource.WorkItemStore.Core.DisableAreaPathAutoCreation =
                        TfsWITCustomSetting.GetBooleanSettingValueDefaultToTrue(setting);
                }
                else if (setting.SettingKey.Equals(TfsConstants.DisableIterationPathAutoCreation, StringComparison.InvariantCultureIgnoreCase))
                {
                    m_migrationSource.WorkItemStore.Core.DisableIterationPathAutoCreation =
                        TfsWITCustomSetting.GetBooleanSettingValueDefaultToTrue(setting);
                }
                else if (setting.SettingKey.Equals(TfsConstants.EnableBypassRuleDataSubmission, StringComparison.InvariantCultureIgnoreCase))
                {
                    m_migrationSource.WorkItemStore.ByPassrules =
                        TfsWITCustomSetting.GetBooleanSettingValueDefaultToTrue(setting);
                }
                else if (setting.SettingKey.Equals(TfsConstants.ReflectedWorkItemIdFieldReferenceName, StringComparison.OrdinalIgnoreCase))
                {
                    m_migrationSource.WorkItemStore.ReflectedWorkItemIdFieldReferenceName = setting.SettingValue;
                }
                else if (setting.SettingKey.Equals(TfsConstants.EnableInsertReflectedWorkItemId))
                {
                    bool val;
                    if (bool.TryParse(setting.SettingValue, out val))
                    {
                        enableReflectedIdInsertion = val;
                    }
                }
            }

            if (!enableReflectedIdInsertion.HasValue)
            {
                // default to enable
                enableReflectedIdInsertion = true;
                m_migrationSource.WorkItemStore.EnableInsertReflectedWorkItemId = enableReflectedIdInsertion.Value;
            }

            if (string.IsNullOrEmpty(m_migrationSource.WorkItemStore.ReflectedWorkItemIdFieldReferenceName))
            {
                m_migrationSource.WorkItemStore.ReflectedWorkItemIdFieldReferenceName = TfsConstants.MigrationTracingFieldRefName;
            }
        }