public FileConverter Build(FileInfo document) { // NOTE // Existing Type: FileInfo = System.IO.FileInfo // Our New Type: FileInformation = CTA.WebForms.FileInformationModel.FileInformation // Add logic to determine the type of FileInformation // object to create, likely using the file type specified // in the FileInfo object string extension = document.Extension; FileConverter fc; try { if (extension.Equals(Constants.CSharpCodeFileExtension)) { fc = new CodeFileConverter(_sourceProjectPath, document.FullName, _blazorWorkspaceManager, _webFormsProjectAnalyzer, _classConverterFactory, _taskManagerService, _metricsContext); } else if (extension.Equals(Constants.WebFormsConfigFileExtension)) { fc = new ConfigFileConverter(_sourceProjectPath, document.FullName, _taskManagerService, _metricsContext); } else if (extension.Equals(Constants.WebFormsPageMarkupFileExtension) || extension.Equals(Constants.WebFormsControlMarkupFileExtenion) || extension.Equals(Constants.WebFormsMasterPageMarkupFileExtension) || extension.Equals(Constants.WebFormsGlobalMarkupFileExtension)) { fc = new ViewFileConverter(_sourceProjectPath, document.FullName, _viewImportService, _taskManagerService, _metricsContext); } else if (extension.Equals(Constants.CSharpProjectFileExtension)) { fc = new ProjectFileConverter(_sourceProjectPath, document.FullName, _blazorWorkspaceManager, _webFormsProjectAnalyzer, _taskManagerService, _metricsContext); } else if (StaticResourceExtensions.Contains(extension)) { fc = new StaticResourceFileConverter(_sourceProjectPath, document.FullName, _hostPageService, _taskManagerService, _metricsContext); } else { fc = new StaticFileConverter(_sourceProjectPath, document.FullName, _taskManagerService, _metricsContext); } return(fc); } catch (Exception e) { LogHelper.LogError(e, $"{Rules.Config.Constants.WebFormsErrorTag}Could not build appropriate file converter for {document.FullName}."); return(null); } }
public async Task TestProjectFileConverter() { WebFormMetricContext metricContext = new WebFormMetricContext(); FileConverter fc = new ProjectFileConverter(DownloadTestProjectsFixture.EShopOnBlazorSolutionPath, DownloadTestProjectsFixture.EShopLegacyWebFormsProjectPath, _blazorWorkspaceManager, _webFormsProjectAnalyzer, new TaskManagerService(), metricContext); IEnumerable <FileInformation> fileList = await fc.MigrateFileAsync(); FileInformation fi = fileList.Single(); byte[] bytes = fi.FileBytes; var projectFileContents = Encoding.UTF8.GetString(bytes); string relativePath = Path.GetRelativePath(DownloadTestProjectsFixture.EShopOnBlazorSolutionPath, DownloadTestProjectsFixture.EShopLegacyWebFormsProjectPath); Assert.True(fi.RelativePath.Equals(relativePath)); Assert.True(projectFileContents.Contains("PackageReference")); Assert.True(projectFileContents.Contains("EntityFramework")); Assert.True(projectFileContents.Contains("log4net")); Assert.True(projectFileContents.Contains("Microsoft.NET.Sdk.Web")); Assert.True(projectFileContents.Contains("Autofac")); }