示例#1
0
        public void GetProjectFileInfo_Retrieves_Files_From_All_Directory_Levels()
        {
            var projectAnalyzer = new ProjectAnalyzer(PartialProjectSetupFixture.TestStructure1Path, new AnalyzerResult(), new PortCoreConfiguration(), new ProjectResult());
            var projectFileInfo = projectAnalyzer.GetProjectFileInfo();

            Assert.AreEqual(projectFileInfo.Count(), 3);
            Assert.True(projectFileInfo.Any(fileInfo => fileInfo.Name.Equals(PartialProjectSetupFixture.TestXMLFileName)));
            Assert.True(projectFileInfo.Any(fileInfo => fileInfo.Name.Equals(PartialProjectSetupFixture.NestedTestClassFileName)));
            Assert.True(projectFileInfo.Any(fileInfo => fileInfo.Name.Equals(PartialProjectSetupFixture.NestedTestTextFileName)));
        }
示例#2
0
        public async Task <WebFormsPortingResult> PerformMigration()
        {
            LogHelper.LogInformation(string.Format(
                                         Constants.StartedOfLogTemplate,
                                         GetType().Name,
                                         Constants.ProjectMigrationLogAction,
                                         _inputProjectPath));

            // Order is important here
            InitializeProjectManagementStructures();
            InitializeServices();
            InitializeFactories();

            // Pass workspace build manager to factory constructor
            var fileConverterCollection = _fileConverterFactory.BuildMany(_webFormsProjectAnalyzer.GetProjectFileInfo());

            var ignorableFileInfo = _webFormsProjectAnalyzer.GetProjectIgnoredFiles();

            foreach (var fileInfo in ignorableFileInfo)
            {
                _blazorProjectBuilder.DeleteFileAndEmptyDirectories(fileInfo.FullName, _inputProjectPath);
            }

            var migrationTasks = fileConverterCollection.Select(fileConverter =>
                                                                // ContinueWith specifies the action to be run after each task completes,
                                                                // in this case it sends each generated file to the project builder
                                                                fileConverter.MigrateFileAsync().ContinueWith(generatedFiles =>
            {
                try
                {
                    _blazorProjectBuilder.DeleteFileAndEmptyDirectories(fileConverter.FullPath, _inputProjectPath);

                    // It's ok to use Task.Result here because the lambda within
                    // the ContinueWith block only executes once the original task
                    // is complete. Task.Result is also preferred because await
                    // would force our lambda expression to be async
                    foreach (FileInformation generatedFile in generatedFiles.Result)
                    {
                        _blazorProjectBuilder.WriteFileInformationToProject(generatedFile);
                    }
                }
                catch (Exception e)
                {
                    LogHelper.LogError(
                        e, Rules.Config.Constants.WebFormsErrorTag +
                        string.Format(Constants.OperationFailedLogTemplate, GetType().Name, Constants.FileMigrationLogAction));
                }
            }
                                                                                                              ));

            // Combines migration tasks into a single task we can await
            await Task.WhenAll(migrationTasks).ConfigureAwait(false);

            LogHelper.LogInformation(string.Format(Constants.GenericInformationLogTemplate, GetType().Name, MigrationTasksCompletedLogAction));

            WriteServiceDerivedFiles();
            var result = new WebFormsPortingResult()
            {
                Metrics = _metricsContext.Transform()
            };

            // TODO: Any necessary cleanup or last checks on new project

            LogHelper.LogInformation(string.Format(
                                         Constants.EndedOfLogTemplate,
                                         GetType().Name,
                                         Constants.ProjectMigrationLogAction,
                                         _inputProjectPath));

            return(result);
        }