Example #1
0
        internal TfsWITMigrationProvider(
            string serverUrl,
            string teamProject,
            string targetWorkItemId)
        {
            TfsMigrationDataSource dataSourceConfig = InitializeMigrationDataSource();

            // Allow multiple filter strings from other adapters
            // Debug.Assert(filters.Count == 1, "filters.Count != 1 for WIT migration source");
            dataSourceConfig.Filter     = string.Empty;
            dataSourceConfig.ServerId   = serverUrl;
            dataSourceConfig.ServerName = serverUrl;
            dataSourceConfig.Project    = teamProject;

            this.m_migrationSource = new TfsWITMigrationSource(
                serverUrl,
                dataSourceConfig.CreateWorkItemStore());

            if (!string.IsNullOrEmpty(targetWorkItemId))
            {
                int workItemId;
                if (int.TryParse(targetWorkItemId, out workItemId))
                {
                    m_migrationSource.WorkItemStore.TargetWorkItemId = workItemId;
                }
            }

            this.m_migrationSource.WorkItemStore.ByPassrules = true;
        }
        internal TfsWITAnalysisProvider(
            string serverUrl,
            string teamProject)
        {
            TfsMigrationDataSource dataSourceConfig = InitializeMigrationDataSource();

            // Allow multiple filter strings from other adapters
            // Debug.Assert(filters.Count == 1, "filters.Count != 1 for WIT migration source");
            dataSourceConfig.Filter     = string.Empty;
            dataSourceConfig.ServerId   = serverUrl;
            dataSourceConfig.ServerName = serverUrl;
            dataSourceConfig.Project    = teamProject;

            this.m_migrationSource = new TfsWITMigrationSource(
                serverUrl,
                dataSourceConfig.CreateWorkItemStore());
        }
Example #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="cfg">Configuration</param>
        public TfsCore(TfsMigrationDataSource cfg)
        {
            m_rwLock = new ReaderWriterLock();
            m_cfg    = cfg;
            //m_missingArea = missingArea;
            //m_missingIteration = missingIteration;

            m_srv = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(cfg.ServerName));
            m_srv.EnsureAuthenticated();
            TraceManager.TraceInformation("Authenticated User for Uri {0} is '{1}'", m_srv.Uri, m_srv.AuthorizedIdentity.DisplayName);

            //// Verify whether the user is in the service account group. Throw an exception if it is not.
            //// TODO: move this to proper location
            //IGroupSecurityService gss = (IGroupSecurityService)m_srv.GetService(typeof(IGroupSecurityService));
            //Identity serviceAccountIdentity = gss.ReadIdentity(SearchFactor.ServiceApplicationGroup, null, QueryMembership.None);
            //if (!gss.IsMember(serviceAccountIdentity.Sid, m_srv.AuthenticatedUserIdentity.Sid))
            //{
            //    throw new MigrationException(
            //        string.Format(TfsWITAdapterResources.UserNotInServiceAccountGroup, m_srv.AuthenticatedUserName, m_srv.Name));
            //}

            m_store = CreateWorkItemStore();
            m_name  = string.Format(
                CultureInfo.InvariantCulture,
                "{0} ({1})",
                m_store.TeamProjectCollection.Name,
                m_cfg.Project);

            Project p = m_store.Projects[cfg.Project];

            m_projectUri = p.Uri.ToString();
            m_projectId  = p.Id;

            //// Check existence of default area and iteration, if any
            //if (!string.IsNullOrEmpty(cfg.DefaultArea))
            //{
            //    m_defaultAreaId = GetNode(Node.TreeType.Area, cfg.DefaultArea, false);
            //}
            //else
            //{
            //    m_defaultAreaId = p.Id;
            //}
            //if (!string.IsNullOrEmpty(cfg.DefaultIteration))
            //{
            //    m_defaultIterationId = GetNode(Node.TreeType.Iteration, cfg.DefaultIteration, false);
            //}
            //else
            //{
            //    m_defaultIterationId = p.Id;
            //}
            /// TODO: replace the code below with configuration in consideration
            m_defaultAreaId      = p.Id;
            m_defaultIterationId = p.Id;

            // Obtain registration info
            IRegistration regSvc = (IRegistration)m_store.TeamProjectCollection.GetService(typeof(IRegistration));

            RegistrationEntry[] res = regSvc.GetRegistrationEntries(ToolNames.WorkItemTracking);

            if (res.Length != 1)
            {
                throw new MigrationException(TfsWITAdapterResources.ErrorMalformedRegistrationData, cfg.ServerName);
            }

            RegistrationEntry e = res[0];

            // Extract all data from the registration entry.
            for (int i = 0; i < e.ServiceInterfaces.Length; i++)
            {
                ServiceInterface si = e.ServiceInterfaces[i];

                if (TFStringComparer.ServiceInterface.Equals(si.Name, ServiceInterfaces.WorkItem))
                {
                    m_witUrl = si.Url;
                }
                else if (TFStringComparer.ServiceInterface.Equals(si.Name, "ConfigurationSettingsUrl"))
                {
                    m_configUrl = si.Url;
                }
            }

            for (int i = 0; i < e.RegistrationExtendedAttributes.Length; i++)
            {
                RegistrationExtendedAttribute a = e.RegistrationExtendedAttributes[i];

                if (RegistrationUtilities.Compare(a.Name, "AttachmentServerUrl") == 0)
                {
                    m_attachUrl = a.Value;
                    break;
                }
            }

            if (string.IsNullOrEmpty(m_witUrl) || string.IsNullOrEmpty(m_configUrl) ||
                string.IsNullOrEmpty(m_attachUrl))
            {
                throw new MigrationException(TfsWITAdapterResources.ErrorMalformedRegistrationData,
                                             m_cfg.ServerName);
            }

            m_attachUrl = CombineUrl(m_attachUrl, m_witUrl);
        }
Example #4
0
        private void InitializeTfsClient()
        {
            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 = m_migrationServiceContainer;

            m_migrationSource.WorkItemStore.LocalWorkDir = GetLocalWorkDir();

            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;
            }

            if (m_migrationSource.WorkItemStore.ByPassrules)
            {
                m_migrationSource.WorkItemStore.Core.CheckBypassRulePermission();
            }
        }