in src/CTA.WebForms/MigrationManager.cs [54:120]
public async Task<WebFormsPortingResult> PerformMigration()
{
LogHelper.LogInformation(string.Format(
Constants.StartedOfLogTemplate,
GetType().Name,
Constants.ProjectMigrationLogAction,
_inputProjectPath));
// Order is important here
InitializeProjectManagementStructures();
InitializeServices();
InitializeFactories();
// Pass workspace build manager to factory constructor
var fileConverterCollection = _fileConverterFactory.BuildMany(_webFormsProjectAnalyzer.GetProjectFileInfo());
var ignorableFileInfo = _webFormsProjectAnalyzer.GetProjectIgnoredFiles();
foreach(var fileInfo in ignorableFileInfo)
{
_blazorProjectBuilder.DeleteFileAndEmptyDirectories(fileInfo.FullName, _inputProjectPath);
}
var migrationTasks = fileConverterCollection.Select(fileConverter =>
// ContinueWith specifies the action to be run after each task completes,
// in this case it sends each generated file to the project builder
fileConverter.MigrateFileAsync().ContinueWith(generatedFiles =>
{
try
{
_blazorProjectBuilder.DeleteFileAndEmptyDirectories(fileConverter.FullPath, _inputProjectPath);
// It's ok to use Task.Result here because the lambda within
// the ContinueWith block only executes once the original task
// is complete. Task.Result is also preferred because await
// would force our lambda expression to be async
foreach (FileInformation generatedFile in generatedFiles.Result)
{
_blazorProjectBuilder.WriteFileInformationToProject(generatedFile);
}
}
catch (Exception e)
{
LogHelper.LogError(
e, Rules.Config.Constants.WebFormsErrorTag +
string.Format(Constants.OperationFailedLogTemplate, GetType().Name, Constants.FileMigrationLogAction));
}
}
));
// Combines migration tasks into a single task we can await
await Task.WhenAll(migrationTasks).ConfigureAwait(false);
LogHelper.LogInformation(string.Format(Constants.GenericInformationLogTemplate, GetType().Name, MigrationTasksCompletedLogAction));
WriteServiceDerivedFiles();
var result = new WebFormsPortingResult() { Metrics = _metricsContext.Transform() };
// TODO: Any necessary cleanup or last checks on new project
LogHelper.LogInformation(string.Format(
Constants.EndedOfLogTemplate,
GetType().Name,
Constants.ProjectMigrationLogAction,
_inputProjectPath));
return result;
}