public async Task ConvertDocumentAsync <TLanguageConversion>(string documentFilePath, Span selected, CancellationToken cancellationToken) where TLanguageConversion : ILanguageConversion, new()
        {
            try {
                await EnsureBuiltAsync();

                var conversionResult = await _joinableTaskFactory.RunAsync(async() => {
                    var result = await ConvertDocumentUnhandledAsync <TLanguageConversion>(documentFilePath, selected, cancellationToken);
                    await WriteConvertedFilesAndShowSummaryAsync(new[] { result }.ToAsyncEnumerable());
                    return(result);
                });

                if ((await GetOptions()).CopyResultToClipboardForSingleDocument)
                {
                    await SetClipboardTextOnUiThreadAsync(conversionResult.ConvertedCode ?? conversionResult.GetExceptionsAsString());

                    await _outputWindow.WriteToOutputWindowAsync(Environment.NewLine + "Conversion result copied to clipboard.");

                    await VisualStudioInteraction.ShowMessageBoxAsync(_serviceProvider, "Conversion result copied to clipboard.", $"Conversion result copied to clipboard. {conversionResult.GetExceptionsAsString()}", false);
                }
            } catch (OperationCanceledException) {
                if (!_packageCancellation.CancelAll.IsCancellationRequested)
                {
                    await _outputWindow.WriteToOutputWindowAsync(Environment.NewLine + "Previous conversion cancelled", forceShow : true);
                }
            }
        }
Esempio n. 2
0
        private async Task ConvertDocumentsAsync(IReadOnlyCollection <string> documentsPath, CancellationToken cancellationToken)
        {
            if (documentsPath.Count == 0)
            {
                await VisualStudioInteraction.ShowMessageBoxAsync("Unable to find any files valid for conversion.");

                return;
            }

            try {
                await _codeConversion.ConvertDocumentsAsync <VBToCSConversion>(documentsPath, cancellationToken);
            } catch (Exception ex) {
                await _package.ShowExceptionAsync(ex);
            }
        }
Esempio n. 3
0
        private async Task <bool> UserHasConfirmedOverwriteAsync(List <string> files, List <string> errors, IReadOnlyCollection <string> pathsToOverwrite)
        {
            var maxExamples = 30; // Avoid a huge unreadable dialog going off the screen
            var exampleText = pathsToOverwrite.Count > maxExamples ? $". First {maxExamples} examples" : "";
            await _outputWindow.WriteToOutputWindowAsync(Environment.NewLine + "Awaiting user confirmation for overwrite....", forceShow : true);

            bool shouldOverwrite = await VisualStudioInteraction.ShowMessageBoxAsync("Overwrite solution and referencing projects?",
                                                                                     $@"The current solution file and any referencing projects will be overwritten to reference the new project(s){exampleText}:
* {string.Join(Environment.NewLine + "* ", pathsToOverwrite.Take(maxExamples))}

The old contents will be copied to 'currentFilename.bak'.
Please 'Reload All' when Visual Studio prompts you.", true, files.Count > errors.Count);

            await _outputWindow.WriteToOutputWindowAsync(shouldOverwrite? "confirmed" : "declined");

            return(shouldOverwrite);
        }