Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
        private void InitializeServices()
        {
            _taskManager            = new TaskManagerService();
            _lifecycleManager       = new LifecycleManagerService();
            _viewImportService      = new ViewImportService();
            _programCsService       = new ProgramCsService();
            _appRazorService        = new AppRazorService();
            _hostPageService        = new HostPageService();
            _blazorWorkspaceManager = new WorkspaceManagerService();

            // By convention, we expect the root namespace to share a name with the project
            // root folder, we normalize the folder name before using it in case the folder name
            // is not a valid identifier
            var rootNamespace = Utilities.NormalizeNamespaceIdentifier(_analyzerResult.ProjectResult.ProjectName);

            _programCsService.ProgramCsNamespace = rootNamespace;
            _hostPageService.HostNamespace       = rootNamespace;
            _blazorWorkspaceManager.CreateSolutionFile();
        }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
        public string ConvertDirective(string directiveName, string directiveString, string originalFilePath, string projectName, ViewImportService viewImportService)
        {
            // TODO: We want to make sure that certain directives only occur once (i.e. layout,
            // inherits, etc.) Need to find a better way to detect and deal with those or perhaps
            // just leave it up the the developer given that detecting which layout or base class
            // to choose is difficult
            var migrationResults = GetMigratedAttributes(directiveString, directiveName, projectName);

            // Want to ensure that the general directive conversion stays at the front if it exists
            migrationResults = GetMigratedDirectives(directiveName, originalFilePath).Concat(migrationResults);

            // Remove any using directive results and send them to the viewImports service
            migrationResults = migrationResults.Where(migrationResult => {
                if (migrationResult.MigrationResultType == DirectiveMigrationResultType.UsingDirective)
                {
                    viewImportService.AddViewImport(migrationResult.Content);
                    return(false);
                }

                return(true);
            });

            return(string.Join(Environment.NewLine, migrationResults.Select(migrationResult => migrationResult.Content)));
        }
Ejemplo n.º 5
0
        public static string ConvertEmbeddedCode(string htmlString, string originalFilePath, ViewImportService viewImportService)
        {
            htmlString = EmbeddedCodeReplacers.ReplaceOneWayDataBinds(htmlString);
            htmlString = EmbeddedCodeReplacers.ReplaceRawExprs(htmlString);
            htmlString = EmbeddedCodeReplacers.ReplaceHTMLEncodedExprs(htmlString);
            htmlString = EmbeddedCodeReplacers.ReplaceAspExprs(htmlString);
            htmlString = EmbeddedCodeReplacers.ReplaceAspComments(htmlString);
            htmlString = EmbeddedCodeReplacers.ReplaceEmbeddedCodeBlocks(htmlString);

            return(htmlString);
        }
Ejemplo n.º 6
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)));
 }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
 public void SetUp()
 {
     _viewImportService = new ViewImportService();
 }