Esempio n. 1
0
        public void SetUp()
        {
            WebFormMetricContext metricContext = new WebFormMetricContext();

            _classConverterFactory = new ClassConverterFactory(string.Empty, new LifecycleManagerService(), new TaskManagerService(), metricContext);
            _workspaceManager      = new WorkspaceManagerService();
            _workspaceManager.CreateSolutionFile();
            _workspaceManager.NotifyNewExpectedProject();
            _primaryProjectId = _workspaceManager.CreateProjectFile("TestProjectName", metadataReferences: _metadataReferences);
        }
Esempio n. 2
0
 public MigrationManager(string inputProjectPath, AnalyzerResult analyzerResult,
                         ProjectConfiguration projectConfiguration, ProjectResult projectResult)
 {
     _inputProjectPath     = inputProjectPath;
     _solutionPath         = projectConfiguration.SolutionPath;
     _analyzerResult       = analyzerResult;
     _projectConfiguration = projectConfiguration;
     _projectResult        = projectResult;
     _metricsContext       = new WebFormMetricContext();
 }
Esempio n. 3
0
 public ViewFileConverter(
     string sourceProjectPath,
     string fullPath,
     ViewImportService viewImportService,
     TaskManagerService taskManagerService,
     WebFormMetricContext metricsContext)
     : base(sourceProjectPath, fullPath, taskManagerService)
 {
     _viewImportService = viewImportService;
     _controlActions    = new List <ControlConversionAction>();
     _metricsContext    = metricsContext;
 }
Esempio n. 4
0
 public PageCodeBehindClassConverter(
     string relativePath,
     string sourceProjectPath,
     SemanticModel sourceFileSemanticModel,
     TypeDeclarationSyntax originalDeclarationSyntax,
     INamedTypeSymbol originalClassSymbol,
     TaskManagerService taskManager,
     WebFormMetricContext metricsContext)
     : base(relativePath, sourceProjectPath, sourceFileSemanticModel, originalDeclarationSyntax, originalClassSymbol, taskManager)
 {
     _newLifecycleLines = new Dictionary <BlazorComponentLifecycleEvent, IEnumerable <StatementSyntax> >();
     _metricsContext    = metricsContext;
 }
Esempio n. 5
0
 public ControlCodeBehindClassConverter(
     string relativePath,
     string sourceProjectPath,
     SemanticModel sourceFileSemanticModel,
     TypeDeclarationSyntax originalDeclarationSyntax,
     INamedTypeSymbol originalClassSymbol,
     TaskManagerService taskManager,
     WebFormMetricContext metricsContext)
     : base(relativePath, sourceProjectPath, sourceFileSemanticModel, originalDeclarationSyntax, originalClassSymbol, taskManager)
 {
     _metricsContext = metricsContext;
     // TODO: Register with the necessary services
 }
Esempio n. 6
0
        public ClassConverterFactory(string sourceProjectPath,
                                     LifecycleManagerService lcManager,
                                     TaskManagerService taskManager,
                                     WebFormMetricContext metricsContext)
        {
            _sourceProjectPath = sourceProjectPath;
            _lifecycleManager  = lcManager;
            _taskManager       = taskManager;
            _metricsContext    = metricsContext;

            // TODO: Receive services required for ClassConverters
            // via constructor parameters
        }
Esempio n. 7
0
 public HttpHandlerClassConverter(
     string relativePath,
     string sourceProjectPath,
     SemanticModel sourceFileSemanticModel,
     TypeDeclarationSyntax originalDeclarationSyntax,
     INamedTypeSymbol originalClassSymbol,
     LifecycleManagerService lifecycleManager,
     TaskManagerService taskManager,
     WebFormMetricContext metricsContext)
     : base(relativePath, sourceProjectPath, sourceFileSemanticModel, originalDeclarationSyntax, originalClassSymbol, taskManager)
 {
     _lifecycleManager = lifecycleManager;
     _lifecycleManager.NotifyExpectedMiddlewareSource();
     _metricsContext = metricsContext;
 }
Esempio n. 8
0
        public ProjectFileConverter(
            string sourceProjectPath,
            string fullPath,
            WorkspaceManagerService blazorWorkspaceManager,
            ProjectAnalyzer projectAnalyzer,
            TaskManagerService taskManagerService,
            WebFormMetricContext metricsContext
            ) : base(sourceProjectPath, fullPath, taskManagerService)
        {
            _blazorWorkspaceManager = blazorWorkspaceManager;
            _projectAnalyzer        = projectAnalyzer;
            _metricsContext         = metricsContext;

            _blazorWorkspaceManager.NotifyNewExpectedProject();
        }
Esempio n. 9
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));
        }
Esempio n. 10
0
        public GlobalClassConverter(
            string relativePath,
            string sourceProjectPath,
            SemanticModel sourceFileSemanticModel,
            TypeDeclarationSyntax originalDeclarationSyntax,
            INamedTypeSymbol originalClassSymbol,
            LifecycleManagerService lifecycleManager,
            TaskManagerService taskManager,
            WebFormMetricContext metricsContext)
            : base(relativePath, sourceProjectPath, sourceFileSemanticModel, originalDeclarationSyntax, originalClassSymbol, taskManager)
        {
            _lifecycleManager = lifecycleManager;
            _lifecycleManager.NotifyExpectedMiddlewareSource();

            _configureMethodStatements = new List <StatementSyntax>();
            _keepableMethods           = new List <MethodDeclarationSyntax>();
            _endOfClassComments        = new List <string>();
            _metricsContext            = metricsContext;
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
        public void Setup()
        {
            var webFormsProjectAnalyzer = new ProjectAnalyzer(_testProjectPath, new AnalyzerResult(), new PortCoreConfiguration(), new ProjectResult());
            var blazorWorkspaceManager  = new WorkspaceManagerService();
            var taskManagerService      = new TaskManagerService();

            blazorWorkspaceManager.CreateSolutionFile();
            WebFormMetricContext metricContext = new WebFormMetricContext();

            _fileConverterFactory = new FileConverterFactory(
                _testProjectPath,
                blazorWorkspaceManager,
                webFormsProjectAnalyzer,
                new ViewImportService(),
                new ClassConverterFactory(string.Empty, new LifecycleManagerService(), taskManagerService, metricContext),
                new HostPageService(),
                taskManagerService,
                metricContext);
        }
Esempio n. 13
0
 public FileConverterFactory(
     string sourceProjectPath,
     WorkspaceManagerService blazorWorkspaceManager,
     ProjectAnalyzer webFormsProjectAnalyzer,
     ViewImportService viewImportService,
     ClassConverterFactory classConverterFactory,
     HostPageService hostPageService,
     TaskManagerService taskManagerService,
     WebFormMetricContext metricsContext)
 {
     _sourceProjectPath       = sourceProjectPath;
     _blazorWorkspaceManager  = blazorWorkspaceManager;
     _webFormsProjectAnalyzer = webFormsProjectAnalyzer;
     _viewImportService       = viewImportService;
     _classConverterFactory   = classConverterFactory;
     _hostPageService         = hostPageService;
     _taskManagerService      = taskManagerService;
     _metricsContext          = metricsContext;
 }
Esempio n. 14
0
        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"));
        }
Esempio n. 15
0
        public CodeFileConverter(
            string sourceProjectPath,
            string fullPath,
            WorkspaceManagerService blazorWorkspaceManager,
            ProjectAnalyzer webFormsProjectAnalyzer,
            ClassConverterFactory classConverterFactory,
            TaskManagerService taskManagerService,
            WebFormMetricContext metricsContext) : base(sourceProjectPath, fullPath, taskManagerService)
        {
            // May not need this anymore but not sure yet
            _blazorWorkspaceBuilder  = blazorWorkspaceManager;
            _webFormsProjectAnaylzer = webFormsProjectAnalyzer;
            _classConverterFactory   = classConverterFactory;
            _metricsContext          = metricsContext;

            try
            {
                _fileModel = _webFormsProjectAnaylzer.AnalyzerResult.ProjectBuildResult?.SourceFileBuildResults?
                             .Single(r => r.SourceFileFullPath.Equals(fullPath, StringComparison.OrdinalIgnoreCase))?.SemanticModel;
            }
            catch (Exception e)
            {
                LogHelper.LogError(e, $"{Rules.Config.Constants.WebFormsErrorTag}Exception occurred when trying to retrieve semantic model for the file {FullPath}. " +
                                   "Semantic Model will default to null.");
            }

            if (_fileModel != null)
            {
                _classConverters = _classConverterFactory.BuildMany(RelativePath, _fileModel);
            }
            else
            {
                _classConverters = new List <ClassConverter>();
                LogHelper.LogWarning($"Semantic model was not found so class conversion cannot take place. Returning zero class converters for file: {FullPath}");
            }
        }
Esempio n. 16
0
        public static string ConstructBlazorDirectives(string content, string originalFilePath, string projectName, ViewImportService viewImportService, WebFormMetricContext metricContext)
        {
            var directiveName      = DirectiveNameRegex.Match(content).Groups[DirectiveNameRegexGroupName].Value;
            var directiveConverter = SupportedControls.DirectiveRulesMap.ContainsKey(directiveName) ?
                                     SupportedControls.DirectiveRulesMap[directiveName] : SupportedControls.DefaultDirectiveConverter;

            metricContext.CollectActionMetrics(WebFormsActionType.DirectiveConversion, directiveName + "DirectiveConverter");

            return(directiveConverter.ConvertDirective(directiveName, content.Trim(), originalFilePath, projectName, viewImportService));
        }
Esempio n. 17
0
 public ConfigFileConverter(string sourceProjectPath, string fullPath, TaskManagerService taskManagerService, WebFormMetricContext metricsContext)
     : base(sourceProjectPath, fullPath, taskManagerService)
 {
     _relativeDirectory = Path.GetDirectoryName(RelativePath);
     _metricsContext    = metricsContext;
 }
Esempio n. 18
0
 public static string ReplaceDirectives(string htmlString, string originalFilePath, string projectName, ViewImportService viewImportService, WebFormMetricContext metricContext)
 {
     return(DirectiveRegex.Replace(htmlString, match => ConstructBlazorDirectives(
                                       match.Groups[EmbeddedExpressionRegexGroupName].Value,
                                       originalFilePath,
                                       projectName,
                                       viewImportService, metricContext)));
 }
Esempio n. 19
0
 public StaticResourceFileConverter(string sourceProjectPath, string fullPath, HostPageService hostPageService, TaskManagerService taskManagerService, WebFormMetricContext metricsContext)
     : base(sourceProjectPath, fullPath, taskManagerService)
 {
     _hostPageService = hostPageService;
     _metricsContext  = metricsContext;
 }