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 TestWebConfigFileConverter() { WebFormMetricContext metricContext = new WebFormMetricContext(); FileConverter fc = new ConfigFileConverter(FileConverterSetupFixture.TestProjectPath, FileConverterSetupFixture.TestWebConfigFilePath, new TaskManagerService(), metricContext); IEnumerable <FileInformation> fileList = await fc.MigrateFileAsync(); FileInformation fi = fileList.Single(); byte[] bytes = fi.FileBytes; var appSettingsContent = Encoding.UTF8.GetString(bytes); string newPath = Path.Combine(FileConverterSetupFixture.TestFilesDirectoryPath, "appsettings.json"); string relativePath = Path.GetRelativePath(FileConverterSetupFixture.TestProjectPath, newPath); Assert.True(appSettingsContent.Contains("UseMockData")); Assert.True(appSettingsContent.Contains("UseCustomizationData")); Assert.True(appSettingsContent.Contains("CatalogDBContext")); Assert.IsTrue(fi.RelativePath.Equals(relativePath)); }