private void WriteConvertedFilesAndShowSummary(IEnumerable <ConversionResult> convertedFiles) { var files = new List <string>(); var errors = new List <string>(); string longestFilePath = null; var longestFileLength = -1; var solutionDir = Path.GetDirectoryName(_visualStudioWorkspace.CurrentSolution.FilePath); VisualStudioInteraction.OutputWindow.WriteToOutputWindow(Intro); VisualStudioInteraction.OutputWindow.ForceShowOutputPane(); foreach (var convertedFile in convertedFiles) { var sourcePath = convertedFile.SourcePathOrNull ?? ""; var sourcePathRelativeToSolutionDir = PathRelativeToSolutionDir(solutionDir, sourcePath); if (sourcePath != "") { if (!string.IsNullOrWhiteSpace(convertedFile.ConvertedCode)) { var path = ToggleExtension(sourcePath); if (convertedFile.ConvertedCode.Length > longestFileLength) { longestFileLength = convertedFile.ConvertedCode.Length; longestFilePath = path; } files.Add(path); File.WriteAllText(path, convertedFile.ConvertedCode); } LogProgress(convertedFile, errors, sourcePathRelativeToSolutionDir); } } VisualStudioInteraction.OutputWindow.WriteToOutputWindow(GetConversionSummary(files, errors)); VisualStudioInteraction.OutputWindow.ForceShowOutputPane(); if (longestFilePath != null) { VisualStudioInteraction.OpenFile(new FileInfo(longestFilePath)).SelectAll(); } }
private void WriteConvertedFilesAndShowSummary(IEnumerable <ConversionResult> convertedFiles) { var files = new List <string>(); var errors = new List <string>(); string longestFilePath = null; var longestFileLength = -1; var solutionDir = Path.GetDirectoryName(_visualStudioWorkspace.CurrentSolution.FilePath); VisualStudioInteraction.OutputWindow.WriteToOutputWindow(Intro); VisualStudioInteraction.OutputWindow.ForceShowOutputPane(); foreach (var convertedFile in convertedFiles) { var sourcePath = convertedFile.SourcePathOrNull; if (convertedFile.Success && sourcePath != null) { var path = ToggleExtension(sourcePath); if (convertedFile.ConvertedCode.Length > longestFileLength) { longestFileLength = convertedFile.ConvertedCode.Length; longestFilePath = path; } files.Add(path); File.WriteAllText(path, convertedFile.ConvertedCode); LogCompleted(solutionDir, path); } else { errors.Add(convertedFile.GetExceptionsAsString()); LogError(solutionDir, convertedFile); } } VisualStudioInteraction.OutputWindow.WriteToOutputWindow(GetConversionSummary(files, errors)); VisualStudioInteraction.OutputWindow.ForceShowOutputPane(); if (longestFilePath != null) { VisualStudioInteraction.OpenFile(new FileInfo(longestFilePath)).SelectAll(); } }
private void FinalizeConversion(List <string> files, List <string> errors, string longestFilePath, List <ConversionResult> filesToOverwrite) { var options = GetOptions(); var pathsToOverwrite = string.Join(Environment.NewLine + "* ", filesToOverwrite.Select(f => PathRelativeToSolutionDir(f.SourcePathOrNull))); var shouldOverwriteSolutionAndProjectFiles = filesToOverwrite.Any() && (options.AlwaysOverwriteFiles || UserHasConfirmedOverwrite(files, errors, pathsToOverwrite)); if (shouldOverwriteSolutionAndProjectFiles) { var titleMessage = options.CreateBackups ? "Creating backups and overwriting files:" : "Overwriting files:" + ""; _outputWindow.WriteToOutputWindow(titleMessage); foreach (var fileToOverwrite in filesToOverwrite) { if (options.CreateBackups) { File.Copy(fileToOverwrite.SourcePathOrNull, fileToOverwrite.SourcePathOrNull + ".bak", true); } fileToOverwrite.WriteToFile(); var targetPathRelativeToSolutionDir = PathRelativeToSolutionDir(fileToOverwrite.TargetPathOrNull); _outputWindow.WriteToOutputWindow(Environment.NewLine + $"* {targetPathRelativeToSolutionDir}"); } files = files.Concat(filesToOverwrite.Select(f => f.SourcePathOrNull)).ToList(); } else if (longestFilePath != null) { VisualStudioInteraction.OpenFile(new FileInfo(longestFilePath)).SelectAll(); } var conversionSummary = GetConversionSummary(files, errors); _outputWindow.WriteToOutputWindow(conversionSummary); _outputWindow.ForceShowOutputPane(); }