/// <summary> /// Starts the migration process from webforms project to a blazor server project. /// </summary> /// <param name="webFormsProject">Source project to read data from.</param> /// <param name="blazorServerProject">Target server blazor project to inject into.</param> /// <param name="steps">The migration steps that are to be run.</param> public async Task StartMigration(VsProject webFormsProject, VsProject blazorServerProject, MigrationSteps steps) { try { //bounds checking that migration steps were provided. if (steps == null) { await _statusTracking.UpdateStepStatusAsync(MigrationStepEnum.MigrationProcess, MigrationStatusEnum.Failed); await _statusTracking.UpdateCurrentStatusAsync(MigrationStepEnum.MigrationProcess, MessageTypeEnum.Error, "Could not determine which migration steps are to be perform migration aborted."); await _statusTracking.UpdateMigrationFinishedAsync(); return; } //Bounds checking that the web forms project was provided. if (webFormsProject == null) { await _statusTracking.UpdateStepStatusAsync(MigrationStepEnum.MigrationProcess, MigrationStatusEnum.Failed); await _statusTracking.UpdateCurrentStatusAsync(MigrationStepEnum.MigrationProcess, MessageTypeEnum.Error, "Internal error occured, no web forms project was provided the migration was aborted."); await _statusTracking.UpdateMigrationFinishedAsync(); return; } //Bounds checking if the blazor server project was provided. if (blazorServerProject == null) { await _statusTracking.UpdateStepStatusAsync(MigrationStepEnum.MigrationProcess, MigrationStatusEnum.Failed); await _statusTracking.UpdateCurrentStatusAsync(MigrationStepEnum.MigrationProcess, MessageTypeEnum.Error, "Internal error occured, no blazor server project was provided the migration was aborted."); await _statusTracking.UpdateMigrationFinishedAsync(); return; } //Starting the migration process by caching the web forms project data await _statusTracking.UpdateStepStatusAsync(MigrationStepEnum.MigrationProcess, MigrationStatusEnum.Running); await _statusTracking.UpdateCurrentStatusAsync(MigrationStepEnum.MigrationProcess, MessageTypeEnum.Information, "Please wait loading the data from the web forms project..."); //Loading the visual studio models from the webFormsProject. //This is a resource intensive task we only need to do this once since we are never updating the web forms project. //We will cache this data and pass it on to all parts of the migration process //var filePath = new DirectoryInfo(webFormsProject.Path).FullName; var webFormProjectData = await webFormsProject.LoadAllProjectData(false); //Confirming the web forms data has been cached if (webFormProjectData.Any()) { await _statusTracking.UpdateStepStatusAsync(MigrationStepEnum.MigrationProcess, MigrationStatusEnum.Passed); await _statusTracking.UpdateCurrentStatusAsync(MigrationStepEnum.MigrationProcess, MessageTypeEnum.Information, "Web forms data has been cached, migration beginning."); } else { await _statusTracking.UpdateStepStatusAsync(MigrationStepEnum.MigrationProcess, MigrationStatusEnum.Failed); await _statusTracking.UpdateCurrentStatusAsync(MigrationStepEnum.MigrationProcess, MessageTypeEnum.Error, "Failed to load the web forms project data, cannot continue the migration process."); await _statusTracking.UpdateMigrationFinishedAsync(); return; } //Running the migration steps in sequential order if (steps.Startup) { await MigrateStartupAsync(webFormProjectData, webFormsProject, blazorServerProject); } if (steps.HttpModules) { await MigrateHttpModulesAsync(webFormProjectData, webFormsProject, blazorServerProject); } if (steps.StaticFiles) { await MigrateStaticFiles(webFormProjectData, webFormsProject, blazorServerProject); } if (steps.Bundling) { await MigrateBundling(webFormProjectData, webFormsProject, blazorServerProject); } if (steps.AspxPages) { await MigrateAspxFiles(webFormProjectData, webFormsProject, blazorServerProject); } if (steps.Configuration) { await MigrateConfig(webFormProjectData, webFormsProject, blazorServerProject); } if (steps.AppLogic) { await MigrateLogic(webFormProjectData, webFormsProject, blazorServerProject); } } catch (Exception unhandledError) { //Updating the dialog with the unhandled error that occured. await _statusTracking.UpdateCurrentStatusAsync(MigrationStepEnum.MigrationProcess, MessageTypeEnum.Error, $"The migration process had an unhandled error, the migration process is aborting. The following error occured. '{unhandledError.Message}'"); } finally { //Informing the hosting dialog the migration has finished. await _statusTracking.UpdateMigrationFinishedAsync(); } }