public void TestBuildManyBasic() { var files = new[] { new FileInfo(_testCodeFilePath), new FileInfo(_testConfigFilePath), new FileInfo(_testStaticFilePath), new FileInfo(_testViewFilePath), new FileInfo(_testProjectFilePath) }; List <FileConverter> fileObjects = _fileConverterFactory.BuildMany(files).ToList(); Assert.True(typeof(CodeFileConverter).IsInstanceOfType(fileObjects[0])); Assert.True(typeof(ConfigFileConverter).IsInstanceOfType(fileObjects[1])); Assert.True(typeof(StaticResourceFileConverter).IsInstanceOfType(fileObjects[2])); Assert.True(typeof(ViewFileConverter).IsInstanceOfType(fileObjects[3])); Assert.True(typeof(ProjectFileConverter).IsInstanceOfType(fileObjects[4])); }
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); }