Example #1
0
        private void EnsureNuGetAndEnvDTEProjectCache()
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            if (!_nuGetAndEnvDTEProjectCache.IsInitialized && IsSolutionOpen)
            {
                var factory = GetProjectFactory();

                try
                {
                    var supportedProjects = EnvDTESolutionUtility.GetAllEnvDTEProjects(_dte)
                                            .Where(project => EnvDTEProjectUtility.IsSupported(project));

                    _nuGetAndEnvDTEProjectCache.Initialize(supportedProjects, factory);
                    SetDefaultProjectName();
                }
                catch
                {
                    _nuGetAndEnvDTEProjectCache.Clear();
                    DefaultNuGetProjectName = null;

                    throw;
                }
            }
        }
Example #2
0
        private async Task EnsureNuGetAndVsProjectAdapterCacheAsync()
        {
            await _initLock.ExecuteNuGetOperationAsync(async() =>
            {
                await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                if (!_cacheInitialized && await IsSolutionOpenAsync())
                {
                    try
                    {
                        var dte = await _asyncServiceProvider.GetDTEAsync();

                        var supportedProjects = new List <Project>();
                        foreach (Project project in await EnvDTESolutionUtility.GetAllEnvDTEProjectsAsync(dte))
                        {
                            if (await EnvDTEProjectUtility.IsSupportedAsync(project))
                            {
                                supportedProjects.Add(project);
                            }
                        }

                        foreach (var project in supportedProjects)
                        {
                            try
                            {
                                var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(project);
                                await AddVsProjectAdapterToCacheAsync(vsProjectAdapter);
                            }
                            catch (Exception e)
                            {
                                // Ignore failed projects.
                                _logger.LogWarning($"The project {project.Name} failed to initialize as a NuGet project.");
                                _logger.LogError(e.ToString());
                            }

                            // Consider that the cache is initialized only when there are any projects to add.
                            _cacheInitialized = true;
                        }

                        await SetDefaultProjectNameAsync();
                    }
                    catch
                    {
                        _projectSystemCache.Clear();
                        _cacheInitialized       = false;
                        DefaultNuGetProjectName = null;

                        throw;
                    }
                }
            }, CancellationToken.None);
        }
        public async Task <bool> DoesNuGetSupportsAnyProjectAsync()
        {
            // Do NOT initialize VSSolutionManager through this API (by calling EnsureInitializeAsync)
            // This is a fast check implemented specifically for right click context menu to be
            // quick and does not involve initializing VSSolutionManager. Otherwise it will create
            // hang issues for right click on solution.
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            // first check with DTE, and if we find any supported project, then return immediately.
            var dte = _serviceProvider.GetDTE();

            var isSupported = EnvDTESolutionUtility.GetAllEnvDTEProjects(dte)
                              .Where(EnvDTEProjectUtility.IsSupported)
                              .Any();

            return(isSupported);
        }
        public async Task <bool> DoesNuGetSupportsAnyProjectAsync()
        {
            // Do NOT initialize VSSolutionManager through this API (by calling EnsureInitializeAsync)
            // This is a fast check implemented specifically for right click context menu to be
            // quick and does not involve initializing VSSolutionManager. Otherwise it will create
            // hang issues for right click on solution.
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            // first check with DTE, and if we find any supported project, then return immediately.
            var dte = _serviceProvider.GetDTE();

            var isSupported = EnvDTESolutionUtility.GetAllEnvDTEProjects(dte)
                              .Where(EnvDTEProjectUtility.IsSupported)
                              .Any();

            if (isSupported)
            {
                return(true);
            }

            var deferredProjects = await GetDeferredProjectsAsync();

            foreach (var project in deferredProjects)
            {
                try
                {
                    var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForDeferredProjectAsync(project);

                    if (vsProjectAdapter.IsSupported)
                    {
                        // as soon as we find a supported project, we returns without checking for all the projects.
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    // Ignore failed projects.
                    _logger.LogWarning($"The project {project} failed to initialize as a NuGet project.");
                    _logger.LogError(e.ToString());
                }
            }

            return(false);
        }
Example #5
0
        private void EnsureNuGetAndEnvDTEProjectCache()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!_nuGetAndEnvDTEProjectCache.IsInitialized && IsSolutionOpen)
            {
                try
                {
                    var supportedProjects = EnvDTESolutionUtility.GetAllEnvDTEProjects(_dte)
                                            .Where(project => EnvDTEProjectUtility.IsSupported(project));

                    foreach (var project in supportedProjects)
                    {
                        try
                        {
                            AddEnvDTEProjectToCache(project);
                        }
                        catch (Exception ex)
                        {
                            // Ignore failed projects.
                            ActivityLog.LogWarning(
                                ExceptionHelper.LogEntrySource,
                                $"The project {project.Name} failed to initialize as a NuGet project.");

                            ExceptionHelper.WriteToActivityLog(ex);
                        }

                        // Consider that the cache is initialized only when there are any projects to add.
                        _nuGetAndEnvDTEProjectCache.IsInitialized = true;
                    }

                    SetDefaultProjectName();
                }
                catch
                {
                    _nuGetAndEnvDTEProjectCache.Clear();
                    DefaultNuGetProjectName = null;

                    throw;
                }
            }
        }
Example #6
0
        private void EnsureNuGetAndEnvDTEProjectCache()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!_cacheInitialized && IsSolutionOpen)
            {
                try
                {
                    var dte = _serviceProvider.GetDTE();
                    var supportedProjects = EnvDTESolutionUtility.GetAllEnvDTEProjects(dte)
                                            .Where(project => EnvDTEProjectUtility.IsSupported(project));

                    foreach (var project in supportedProjects)
                    {
                        try
                        {
                            AddEnvDTEProjectToCache(project);
                        }
                        catch (Exception e)
                        {
                            // Ignore failed projects.
                            _logger.LogWarning($"The project {project.Name} failed to initialize as a NuGet project.");
                            _logger.LogError(e.ToString());
                        }

                        // Consider that the cache is initialized only when there are any projects to add.
                        _cacheInitialized = true;
                    }

                    SetDefaultProjectName();
                }
                catch
                {
                    _projectSystemCache.Clear();
                    _cacheInitialized       = false;
                    DefaultNuGetProjectName = null;

                    throw;
                }
            }
        }
Example #7
0
        public async Task <bool> DoesNuGetSupportsAnyProjectAsync()
        {
            // Do NOT initialize VSSolutionManager through this API (by calling EnsureInitializeAsync)
            // This is a fast check implemented specifically for right click context menu to be
            // quick and does not involve initializing VSSolutionManager. Otherwise it will make
            // the UI stop responding for right click on solution.
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            // first check with DTE, and if we find any supported project, then return immediately.
            var dte = await _asyncServiceProvider.GetDTEAsync();

            var isSupported = false;

            foreach (Project project in await EnvDTESolutionUtility.GetAllEnvDTEProjectsAsync(dte))
            {
                isSupported = true;
                break;
            }

            return(isSupported);
        }
Example #8
0
        private async Task EnsureNuGetAndVsProjectAdapterCacheAsync()
        {
            await _initLock.ExecuteNuGetOperationAsync(async() =>
            {
                await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                IVsSolution ivsSolution = await _asyncVSSolution.GetValueAsync();
                if (!_cacheInitialized && IsSolutionOpenFromVSSolution(ivsSolution))
                {
                    try
                    {
                        if (await _featureFlagService.IsFeatureEnabledAsync(NuGetFeatureFlagConstants.NuGetSolutionCacheInitilization))
                        {
                            foreach (var hierarchy in VsHierarchyUtility.GetAllLoadedProjects(ivsSolution))
                            {
                                try
                                {
                                    var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(hierarchy);
                                    await AddVsProjectAdapterToCacheAsync(vsProjectAdapter);
                                }
                                catch (Exception e)
                                {
                                    // Ignore failed projects.
                                    _logger.LogWarning($"The project {VsHierarchyUtility.GetProjectPath(hierarchy)} failed to initialize as a NuGet project.");
                                    _logger.LogError(e.ToString());
                                }

                                // Consider that the cache is initialized only when there are any projects to add.
                                _cacheInitialized = true;
                            }
                        }
                        else
                        {
                            var dte = await _dte.GetValueAsync();

                            foreach (var project in await EnvDTESolutionUtility.GetAllEnvDTEProjectsAsync(dte))
                            {
                                try
                                {
                                    var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(project);
                                    await AddVsProjectAdapterToCacheAsync(vsProjectAdapter);
                                }
                                catch (Exception e)
                                {
                                    // Ignore failed projects.
                                    _logger.LogWarning($"The project {project.Name} failed to initialize as a NuGet project.");
                                    _logger.LogError(e.ToString());
                                }

                                // Consider that the cache is initialized only when there are any projects to add.
                                _cacheInitialized = true;
                            }
                        }

                        await SetDefaultProjectNameAsync();
                    }
                    catch
                    {
                        _projectSystemCache.Clear();
                        _cacheInitialized       = false;
                        DefaultNuGetProjectName = null;

                        throw;
                    }
                }
            }, CancellationToken.None);
        }
Example #9
0
        private async Task EnsureNuGetAndVsProjectAdapterCacheAsync()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!_cacheInitialized && IsSolutionOpen)
            {
                try
                {
                    var deferedProjects = GetDeferredProjects();

                    foreach (var project in deferedProjects)
                    {
                        try
                        {
                            var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForDeferredProjectAsync(project);

                            AddVsProjectAdapterToCache(vsProjectAdapter);
                        }
                        catch (Exception e)
                        {
                            // Ignore failed projects.
                            _logger.LogWarning($"The project {project} failed to initialize as a NuGet project.");
                            _logger.LogError(e.ToString());
                        }

                        // Consider that the cache is initialized only when there are any projects to add.
                        _cacheInitialized = true;
                    }

                    var dte = _serviceProvider.GetDTE();

                    var supportedProjects = EnvDTESolutionUtility
                                            .GetAllEnvDTEProjects(dte)
                                            .Where(EnvDTEProjectUtility.IsSupported);

                    foreach (var project in supportedProjects)
                    {
                        try
                        {
                            var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(project);

                            AddVsProjectAdapterToCache(vsProjectAdapter);
                        }
                        catch (Exception e)
                        {
                            // Ignore failed projects.
                            _logger.LogWarning($"The project {project.Name} failed to initialize as a NuGet project.");
                            _logger.LogError(e.ToString());
                        }

                        // Consider that the cache is initialized only when there are any projects to add.
                        _cacheInitialized = true;
                    }

                    SetDefaultProjectName();
                }
                catch
                {
                    _projectSystemCache.Clear();
                    _cacheInitialized       = false;
                    DefaultNuGetProjectName = null;

                    throw;
                }
            }
        }