in WiMigrator/CommandLine.cs [111:174]
private async Task ExecuteMigration(CommandOption migrate)
{
bool showedHelp = false;
ConfigJson configJson = null;
try
{
string configFileName = migrate.Value();
ConfigReaderJson configReaderJson = new ConfigReaderJson(configFileName);
configJson = configReaderJson.Deserialize();
var validatorContext = new ValidationContext(configJson);
using (var heartbeat = new ValidationHeartbeatLogger(validatorContext.WorkItemsMigrationState, validatorContext, validatorContext.Config.HeartbeatFrequencyInSeconds))
{
await new Validator(validatorContext).Validate();
heartbeat.Beat();
}
//TODO: Create a common method to take the validator context and created a migration context
var migrationContext = new MigrationContext(configJson);
migrationContext.WorkItemIdsUris = validatorContext.WorkItemIdsUris;
migrationContext.WorkItemTypes = validatorContext.TargetTypesAndFields;
migrationContext.IdentityFields = validatorContext.IdentityFields;
migrationContext.TargetAreaPaths = validatorContext.TargetAreaPaths;
migrationContext.TargetIterationPaths = validatorContext.TargetIterationPaths;
migrationContext.WorkItemsMigrationState = validatorContext.WorkItemsMigrationState;
migrationContext.TargetIdToSourceHyperlinkAttributeId = validatorContext.TargetIdToSourceHyperlinkAttributeId;
migrationContext.ValidatedWorkItemLinkRelationTypes = validatorContext.ValidatedWorkItemLinkRelationTypes;
migrationContext.RemoteLinkRelationTypes = validatorContext.RemoteLinkRelationTypes;
migrationContext.SourceFields = validatorContext.SourceFields;
migrationContext.FieldsThatRequireSourceProjectToBeReplacedWithTargetProject = validatorContext.FieldsThatRequireSourceProjectToBeReplacedWithTargetProject;
using (var heartbeat = new MigrationHeartbeatLogger(migrationContext.WorkItemsMigrationState, migrationContext.Config.HeartbeatFrequencyInSeconds))
{
await new Migrator(migrationContext).Migrate();
heartbeat.Beat();
}
}
catch (CommandParsingException e)
{
Logger.LogError(LogDestination.All, e, "Invalid command line option(s):");
commandLineApplication.ShowHelp();
showedHelp = true;
}
catch (Exception e) when (e is ValidationException)
{
Logger.LogError(LogDestination.All, e, "Validation error:");
}
catch (Exception e) when (e is MigrationException)
{
Logger.LogError(LogDestination.All, e, "Migration error:");
}
catch (Exception e)
{
Logger.LogError(LogDestination.All, e, $"Unexpected error: {e}");
}
finally
{
if (!showedHelp && configJson != null)
{
SendSummaryEmail(configJson);
}
}
}