示例#1
0
        private 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" : "";

            return(VisualStudioInteraction.ShowMessageBoxAsync(_serviceProvider,
                                                               "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));
        }
        public async Task PerformDocumentConversionAsync <TLanguageConversion>(string documentFilePath, Span selected) where TLanguageConversion : ILanguageConversion, new()
        {
            var conversionResult = await Task.Run(async() => {
                var result = await ConvertDocumentUnhandledAsync <TLanguageConversion>(documentFilePath, selected);
                await WriteConvertedFilesAndShowSummaryAsync(new[] { result });
                return(result);
            });

            if ((await GetOptions()).CopyResultToClipboardForSingleDocument)
            {
                Clipboard.SetText(conversionResult.ConvertedCode ?? conversionResult.GetExceptionsAsString());
                await _outputWindow.WriteToOutputWindowAsync("Conversion result copied to clipboard.");

                await VisualStudioInteraction.ShowMessageBoxAsync(_serviceProvider, "Conversion result copied to clipboard.", conversionResult.GetExceptionsAsString(), false);
            }
        }
示例#3
0
        public async Task ConvertDocumentAsync <TLanguageConversion>(string documentFilePath, Span selected, CancellationToken cancellationToken) where TLanguageConversion : ILanguageConversion, new()
        {
            try {
                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);
                }
            }
        }