|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using Microsoft.Extensions.Logging; |
| 5 | +using Microsoft.Extensions.Options; |
| 6 | +using Microsoft.TeamFoundation.WorkItemTracking.Client; |
| 7 | +using MigrationTools.Enrichers; |
| 8 | +using MigrationTools.Processors.Infrastructure; |
| 9 | +using MigrationTools.Tools; |
| 10 | + |
| 11 | +namespace MigrationTools.Processors |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Work item type validation processor. Basically it just runs the <see cref="TfsWorkItemTypeValidatorTool"/> |
| 15 | + /// to validate work item types. The validation is run always, even if the tool iself is disabled. |
| 16 | + /// Neither this processor, nor the tool do not perform any changes to the source or target system. |
| 17 | + /// </summary> |
| 18 | + public class TfsWorkItemTypeValidatorProcessor : TfsProcessor |
| 19 | + { |
| 20 | + public TfsWorkItemTypeValidatorProcessor( |
| 21 | + IOptions<TfsWorkItemTypeValidatorProcessorOptions> options, |
| 22 | + TfsCommonTools tfsCommonTools, |
| 23 | + ProcessorEnricherContainer processorEnrichers, |
| 24 | + IServiceProvider services, |
| 25 | + ITelemetryLogger telemetry, |
| 26 | + ILogger<TfsWorkItemTypeValidatorProcessor> logger) |
| 27 | + : base(options, tfsCommonTools, processorEnrichers, services, telemetry, logger) |
| 28 | + { |
| 29 | + } |
| 30 | + |
| 31 | + public new TfsWorkItemTypeValidatorProcessorOptions Options => (TfsWorkItemTypeValidatorProcessorOptions)base.Options; |
| 32 | + |
| 33 | + protected override void InternalExecute() |
| 34 | + { |
| 35 | + if (!CommonTools.WorkItemTypeValidatorTool.Enabled) |
| 36 | + { |
| 37 | + Log.LogInformation("Work item type validation tool is disabled, but this processor will still" |
| 38 | + + " run the validation. No changes are done to source or target system."); |
| 39 | + } |
| 40 | + List<WorkItemType> sourceWits = Source.WorkItems.Project |
| 41 | + .ToProject() |
| 42 | + .WorkItemTypes |
| 43 | + .Cast<WorkItemType>() |
| 44 | + .ToList(); |
| 45 | + List<WorkItemType> targetWits = Target.WorkItems.Project |
| 46 | + .ToProject() |
| 47 | + .WorkItemTypes |
| 48 | + .Cast<WorkItemType>() |
| 49 | + .ToList(); |
| 50 | + bool validationResult = CommonTools.WorkItemTypeValidatorTool |
| 51 | + .ValidateWorkItemTypes(sourceWits, targetWits, Target.Options.ReflectedWorkItemIdField); |
| 52 | + if (Options.StopIfValidationFails && !validationResult) |
| 53 | + { |
| 54 | + Log.LogInformation($"'{nameof(Options.StopIfValidationFails)}' is set to 'true', so migration process will stop now."); |
| 55 | + Environment.Exit(-1); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments