Exemple #1
0
 protected override void InternalExecute()
 {
     Log.LogInformation("Processor::InternalExecute::Start");
     EnsureConfigured();
     ProcessorEnrichers.ProcessorExecutionBegin(this);
     nodeStructureEnricher = Services.GetRequiredService <TfsNodeStructure>();
     nodeStructureEnricher.Configure(new TfsNodeStructureOptions()
     {
         Enabled = true, NodeBasePaths = _Options.NodeBasePaths, PrefixProjectToNodes = _Options.PrefixProjectToNodes
     });
     nodeStructureEnricher.ProcessorExecutionBegin(null);
     ProcessorEnrichers.ProcessorExecutionEnd(this);
     Log.LogInformation("Processor::InternalExecute::End");
 }
        internal void InitializeWorkItemMigrationContext()
        {
            var workItemServer = Engine.Source.GetService <WorkItemServer>();

            attachmentEnricher    = new TfsAttachmentEnricher(workItemServer, _config.AttachmentWorkingPath, _config.AttachmentMaxSize);
            workItemLinkEnricher  = Services.GetRequiredService <TfsWorkItemLinkEnricher>();
            embededImagesEnricher = Services.GetRequiredService <TfsEmbededImagesEnricher>();
            gitRepositoryEnricher = Services.GetRequiredService <TfsGitRepositoryEnricher>();
            nodeStructureEnricher = Services.GetRequiredService <TfsNodeStructure>();
            nodeStructureEnricher.Configure(new TfsNodeStructureOptions()
            {
                Enabled = true, NodeBasePaths = _config.NodeBasePaths, PrefixProjectToNodes = _config.PrefixProjectToNodes
            });
            nodeStructureEnricher.ProcessorExecutionBegin(null);

            _witClient = new WorkItemTrackingHttpClient(Engine.Target.Config.AsTeamProjectConfig().Collection, Engine.Target.Credentials);
            //Validation: make sure that the ReflectedWorkItemId field name specified in the config exists in the target process, preferably on each work item type.
            PopulateIgnoreList();
        }
        protected override void InternalExecute()
        {
            Log.LogInformation("WorkItemMigrationContext::InternalExecute ");
            if (_config == null)
            {
                throw new Exception("You must call Configure() first");
            }
            var workItemServer = Engine.Source.GetService <WorkItemServer>();

            attachmentEnricher          = new TfsAttachmentEnricher(workItemServer, _config.AttachmentWorkingPath, _config.AttachmentMaxSize);
            workItemLinkEnricher        = Services.GetRequiredService <TfsWorkItemLinkEnricher>();
            embededImagesEnricher       = Services.GetRequiredService <TfsEmbededImagesEnricher>();
            workItemEmbededLinkEnricher = Services.GetRequiredService <TfsWorkItemEmbededLinkEnricher>();
            gitRepositoryEnricher       = Services.GetRequiredService <TfsGitRepositoryEnricher>();
            nodeStructureEnricher       = Services.GetRequiredService <TfsNodeStructure>();
            nodeStructureEnricher.Configure(new TfsNodeStructureOptions()
            {
                Enabled = _config.NodeStructureEnricherEnabled ?? true, NodeBasePaths = _config.NodeBasePaths, PrefixProjectToNodes = _config.PrefixProjectToNodes
            });
            nodeStructureEnricher.Configure(new TfsNodeStructureOptions()
            {
                Enabled = _config.NodeStructureEnricherEnabled ?? true, NodeBasePaths = _config.NodeBasePaths, PrefixProjectToNodes = _config.PrefixProjectToNodes
            });
            nodeStructureEnricher.ProcessorExecutionBegin(null);
            revisionManager = Services.GetRequiredService <TfsRevisionManager>();
            revisionManager.Configure(new TfsRevisionManagerOptions()
            {
                Enabled = true, MaxRevisions = _config.MaxRevisions, ReplayRevisions = _config.ReplayRevisions
            });

            var stopwatch = Stopwatch.StartNew();

            try
            {
                //Validation: make sure that the ReflectedWorkItemId field name specified in the config exists in the target process, preferably on each work item type.
                PopulateIgnoreList();

                string sourceQuery =
                    string.Format(
                        @"SELECT [System.Id], [System.Tags] FROM WorkItems WHERE [System.TeamProject] = @TeamProject {0} ORDER BY {1}",
                        _config.WIQLQueryBit, _config.WIQLOrderBit);

                // Inform the user that he maybe has to be patient now
                contextLog.Information("Querying items to be migrated: {SourceQuery} ...", sourceQuery);
                var sourceWorkItems = Engine.Source.WorkItems.GetWorkItems(sourceQuery);
                contextLog.Information("Replay all revisions of {sourceWorkItemsCount} work items?", sourceWorkItems.Count);
                //////////////////////////////////////////////////
                contextLog.Information("Found target project as {@destProject}", Engine.Target.WorkItems.Project.Name);
                //////////////////////////////////////////////////////////FilterCompletedByQuery
                if (_config.FilterWorkItemsThatAlreadyExistInTarget)
                {
                    contextLog.Information("[FilterWorkItemsThatAlreadyExistInTarget] is enabled. Searching for work items that have already been migrated to the target...", sourceWorkItems.Count());

                    string targetWIQLQueryBit = FixAreaPathAndIterationPathForTargetQuery(_config.WIQLQueryBit, Engine.Source.WorkItems.Project.Name, Engine.Target.WorkItems.Project.Name, contextLog);
                    sourceWorkItems = ((TfsWorkItemMigrationClient)Engine.Target.WorkItems).FilterExistingWorkItems(sourceWorkItems, new TfsWiqlDefinition()
                    {
                        OrderBit = _config.WIQLOrderBit, QueryBit = targetWIQLQueryBit
                    }, (TfsWorkItemMigrationClient)Engine.Source.WorkItems);
                    contextLog.Information("!! After removing all found work items there are {SourceWorkItemCount} remaining to be migrated.", sourceWorkItems.Count());
                }
                //////////////////////////////////////////////////

                var result = validateConfig.ValidatingRequiredField(Engine.Target.Config.AsTeamProjectConfig().ReflectedWorkItemIDFieldName, sourceWorkItems);
                if (!result)
                {
                    var ex = new InvalidFieldValueException("Not all work items in scope contain a valid ReflectedWorkItemId Field!");
                    Log.LogError(ex, "Not all work items in scope contain a valid ReflectedWorkItemId Field!");
                    throw ex;
                }
                //////////////////////////////////////////////////
                _current       = 1;
                _count         = sourceWorkItems.Count;
                _elapsedms     = 0;
                _totalWorkItem = sourceWorkItems.Count;
                foreach (WorkItemData sourceWorkItemData in sourceWorkItems)
                {
                    var sourceWorkItem = TfsExtensions.ToWorkItem(sourceWorkItemData);
                    workItemLog = contextLog.ForContext("SourceWorkItemId", sourceWorkItem.Id);
                    using (LogContext.PushProperty("sourceWorkItemTypeName", sourceWorkItem.Type.Name))
                        using (LogContext.PushProperty("currentWorkItem", _current))
                            using (LogContext.PushProperty("totalWorkItems", _totalWorkItem))
                                using (LogContext.PushProperty("sourceWorkItemId", sourceWorkItem.Id))
                                    using (LogContext.PushProperty("sourceRevisionInt", sourceWorkItem.Revision))
                                        using (LogContext.PushProperty("targetWorkItemId", null))
                                        {
                                            ProcessWorkItemAsync(sourceWorkItemData, _config.WorkItemCreateRetryLimit).Wait();
                                            if (_config.PauseAfterEachWorkItem)
                                            {
                                                Console.WriteLine("Do you want to continue? (y/n)");
                                                if (Console.ReadKey().Key != ConsoleKey.Y)
                                                {
                                                    workItemLog.Warning("USER ABORTED");
                                                    break;
                                                }
                                            }
                                        }
                }
            }
            finally
            {
                if (_config.FixHtmlAttachmentLinks)
                {
                    embededImagesEnricher?.ProcessorExecutionEnd(null);
                }

                stopwatch.Stop();
                contextLog.Information("DONE in {Elapsed}", stopwatch.Elapsed.ToString("c"));
            }
        }