Example #1
0
        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);
            }
        }
Example #2
0
        public async Task TestStaticFileConverter()
        {
            WebFormMetricContext metricContext = new WebFormMetricContext();
            string        sourceFilePath       = FileConverterSetupFixture.TestStaticFilePath;
            FileConverter fc = new StaticFileConverter(FileConverterSetupFixture.TestProjectPath, sourceFilePath, new TaskManagerService(), metricContext);

            IEnumerable <FileInformation> fileList = await fc.MigrateFileAsync();

            FileInformation fi = fileList.Single();

            byte[] bytes = fi.FileBytes;

            string relativePath = Path.GetRelativePath(FileConverterSetupFixture.TestProjectPath, sourceFilePath);

            Assert.IsTrue(bytes.Length == new FileInfo(sourceFilePath).Length);
            Assert.IsTrue(fi.RelativePath.Equals(relativePath));
        }