コード例 #1
0
        internal (string projFile, bool success) LogReport(string logFile, int processExitCode,
                                                           string projectName, string xprojLocation, IVsUpgradeLogger pLogger)
        {
            (string, bool) LogAndReturnError()
            {
                pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, xprojLocation,
                                   string.Format(VSResources.XprojMigrationFailedCannotReadReport, logFile));
                pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, xprojLocation,
                                   GetDotnetGeneralErrorString(projectName, xprojLocation, Path.GetDirectoryName(xprojLocation), logFile, processExitCode));
                return(string.Empty, false);
            }

            if (!_fileSystem.FileExists(logFile))
            {
                return(LogAndReturnError());
            }

            MigrationReport mainReport = JsonConvert.DeserializeObject <MigrationReport>(_fileSystem.ReadAllText(logFile));

            if (mainReport == null)
            {
                return(LogAndReturnError());
            }

            // We're calling migrate on a single project and have don't follow turned on. We shouldn't see any other migration reports.
            Assumes.True(mainReport.ProjectMigrationReports.Count == 1);
            ProjectMigrationReport report = mainReport.ProjectMigrationReports[0];

            if (report.Failed)
            {
                pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, xprojLocation,
                                   GetDotnetGeneralErrorString(projectName, xprojLocation, report.ProjectDirectory, logFile, processExitCode));
            }

            foreach (MigrationError error in report.Errors)
            {
                pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, xprojLocation, error.FormattedErrorMessage);
            }

            foreach (string warn in report.Warnings)
            {
                pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_WARNING, projectName, xprojLocation, warn);
            }

            _fileSystem.RemoveFile(logFile);
            return(report.OutputMSBuildProject, report.Succeeded);
        }
コード例 #2
0
        private IFileSystem CreateFileSystem(bool withEntries       = true,
                                             MigrationReport report = null,
                                             bool withXprojUser     = false,
                                             bool withProjectLock   = false,
                                             bool withGlobalJson    = false)
        {
            var fileSystem = new IFileSystemMock();

            if (withEntries)
            {
                fileSystem.CreateDirectory(RootLocation);
                fileSystem.CreateDirectory(BackupLocation);
                fileSystem.Create(XprojLocation);
                fileSystem.Create(ProjectJsonLocation);
                if (withXprojUser)
                {
                    fileSystem.Create(XprojUserLocation);
                }

                if (withProjectLock)
                {
                    fileSystem.Create(ProjectLockJsonLocation);
                }

                if (withGlobalJson)
                {
                    fileSystem.WriteAllText(GlobalJsonLocation, JsonConvert.SerializeObject(new object()));
                }
            }

            fileSystem.SetTempFile(LogFileLocation);

            if (withEntries)
            {
                report = report ?? new MigrationReport(1, new List <ProjectMigrationReport>()
                {
                    new ProjectMigrationReport(true, CsprojLocation, RootLocation, ProjectName, new List <string>(), new List <MigrationError>())
                });
                fileSystem.WriteAllText(LogFileLocation, JsonConvert.SerializeObject(report));
            }

            return(fileSystem);
        }
コード例 #3
0
        public void LogWithErrors_MessagesAreLoggedToVs()
        {
            var fileSystem      = CreateFileSystem(withEntries: false);
            var migrationReport = new MigrationReport(0, new List <ProjectMigrationReport>
            {
                new ProjectMigrationReport(false, string.Empty, RootLocation, ProjectName, new List <string>
                {
                    "Sample Warning 1",
                    "Sample Warning 2"
                }, new List <MigrationError> {
                    new MigrationError("asdf1234", "General Error", "An error has occurred"),
                    new MigrationError("fdsa4321", "Specific Error", "A different error has occurred")
                })
            });

            fileSystem.WriteAllText(LogFileLocation, JsonConvert.SerializeObject(migrationReport));

            var loggedMessages = new List <LogMessage>();
            var logger         = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages);
            var migrator       = CreateInstance(ProcessRunnerFactory.CreateRunner(), fileSystem);

            var(projectFile, success) = migrator.LogReport(LogFileLocation, VSConstants.E_ABORT, ProjectName, XprojLocation, logger);
            Assert.Equal(string.Empty, projectFile);
            Assert.False(success);
            Assert.Equal(5, loggedMessages.Count);
            Assert.Contains(new LogMessage
            {
                File    = XprojLocation,
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_WARNING,
                Message = "Sample Warning 1",
                Project = ProjectName
            }, loggedMessages);
            Assert.Contains(new LogMessage
            {
                File    = XprojLocation,
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_WARNING,
                Message = "Sample Warning 2",
                Project = ProjectName
            }, loggedMessages);
            Assert.Contains(new LogMessage
            {
                File    = XprojLocation,
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_ERROR,
                Message = "asdf1234::General Error: An error has occurred",
                Project = ProjectName
            }, loggedMessages);
            Assert.Contains(new LogMessage
            {
                File    = XprojLocation,
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_ERROR,
                Message = "fdsa4321::Specific Error: A different error has occurred",
                Project = ProjectName
            }, loggedMessages);
            Assert.Contains(new LogMessage
            {
                File    = XprojLocation,
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_ERROR,
                Message = string.Format(VSResources.XprojMigrationGeneralFailure, ProjectName, MigrateCommand, VSConstants.E_ABORT),
                Project = ProjectName
            }, loggedMessages);
        }