Beispiel #1
0
        public async Task <ReportingResult> WriteAnalysisReportsAsync(
            IEnumerable <string> assemblyPaths,
            IFileWriter reportWriter,
            bool includeJson)
        {
            await _outputWindow.ShowWindowAsync().ConfigureAwait(false);

            await _optionsViewModel.UpdateAsync().ConfigureAwait(false);

            var reportDirectory = _optionsViewModel.OutputDirectory;
            var outputFormats   = _optionsViewModel.Formats.Where(f => f.IsSelected).Select(f => f.DisplayName);
            var reportFileName  = _optionsViewModel.DefaultOutputName;

            var analysisOptions = await GetApiPortOptions(assemblyPaths, outputFormats, Path.Combine(reportDirectory, reportFileName)).ConfigureAwait(false);

            var issuesBefore = _reporter.Issues.Count;

            var result = await _client.WriteAnalysisReportsAsync(analysisOptions, includeJson).ConfigureAwait(false);

            if (!result.Paths.Any())
            {
                var issues = _reporter.Issues.ToArray();

                await _threadingService.SwitchToMainThreadAsync();

                for (int i = issuesBefore; i < issues.Length; i++)
                {
                    _outputWindow.WriteLine(LocalizedStrings.ListItem, issues[i]);
                }
            }

            await _viewer.ViewAsync(result.Paths).ConfigureAwait(false);

            return(result.Result);
        }
        public async Task DisplaySourceItemsAsync(IEnumerable <ISourceMappedItem> items, ICollection <CalculatedProject> projects)
        {
            await _threadingService.SwitchToMainThreadAsync();

            _errorList.Tasks.Clear();
            _errorList.Refresh();
            _errorList.SuspendRefresh();

            var projectWithOutputMappings = new ConcurrentDictionary <string, IVsHierarchy>();

            foreach (var calculatedProject in projects)
            {
                var project = calculatedProject.Project;
                var outputs = calculatedProject.OutputFiles;

                if (outputs == null)
                {
                    continue;
                }

                var hierarchy = calculatedProject.VsHierarchy;

                foreach (var output in outputs)
                {
                    projectWithOutputMappings.AddOrUpdate(output, hierarchy, (existingKey, existingValue) => hierarchy);
                }
            }

            await _threadingService.SwitchToMainThreadAsync();

            try
            {
                var defaultHierarchy = projects.First().VsHierarchy;

                foreach (var item in items)
                {
                    if (!_fileSystem.FileExists(item.Path))
                    {
                        continue;
                    }

                    if (!projectWithOutputMappings.TryGetValue(item.Assembly, out IVsHierarchy hierarchy))
                    {
                        hierarchy = defaultHierarchy;
                    }

                    var errorWindowTask = item.GetErrorWindowTask(hierarchy);
                    var result          = _errorList.Tasks.Add(errorWindowTask);
                }
            }
            finally
            {
                _errorList.ResumeRefresh();
            }

            // Outside the finally because it will obscure errors reported on the output window
            _errorList.BringToFront();
        }
Beispiel #3
0
        /// <summary>
        /// Gets the VSHierarchy using COM calls to the package service.
        /// </summary>
        public async Task <IVsHierarchy> GetVsHierarchyAsync(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            await _threadingService.SwitchToMainThreadAsync();

            var solution = VisualStudio.Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            if (solution == null)
            {
                return(null);
            }

            IVsHierarchy hierarchy;

            solution.GetProjectOfUniqueName(project.FullName, out hierarchy);

            return(hierarchy);
        }