/// <summary>
        /// Add a project to the cache.
        /// </summary>
        /// <param name="project">project to add to the cache.</param>
        /// <returns>The project name of the added project.</returns>
        public EnvDTEProjectName AddProject(EnvDTEProject project, VSNuGetProjectFactory factory)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // Create the nuget project first, if this throws we bail out, and not change the cache
            var nuGetProject = factory.CreateNuGetProject(project);

            // First create a project name from the project
            var EnvDTEProjectName = new EnvDTEProjectName(project);

            // Do nothing if we already have an entry
            if (_envDTEProjectCache.ContainsKey(EnvDTEProjectName))
            {
                return(EnvDTEProjectName);
            }

            AddShortName(EnvDTEProjectName);

            _projectNamesCache[EnvDTEProjectName.CustomUniqueName] = EnvDTEProjectName;
            _projectNamesCache[EnvDTEProjectName.UniqueName]       = EnvDTEProjectName;
            _projectNamesCache[EnvDTEProjectName.FullName]         = EnvDTEProjectName;

            // Add the entry mapping project name to the actual project
            _envDTEProjectCache[EnvDTEProjectName] = project;

            _nuGetProjectCache[EnvDTEProjectName] = nuGetProject;

            return(EnvDTEProjectName);
        }
示例#2
0
 /// <summary>
 /// Removes a project from the project name dictionary.
 /// </summary>
 private void RemoveProjectName(EnvDTEProjectName envDTEProjectName)
 {
     _projectNamesCache.Remove(envDTEProjectName.CustomUniqueName);
     _projectNamesCache.Remove(envDTEProjectName.UniqueName);
     _projectNamesCache.Remove(envDTEProjectName.FullName);
     _envDTEProjectCache.Remove(envDTEProjectName);
     _nuGetProjectCache.Remove(envDTEProjectName);
 }
示例#3
0
        /// <summary>
        /// Adds an entry to the short name cache returning any conflicting project name.
        /// </summary>
        /// <returns>The first conflicting short name.</returns>
        private void AddShortName(EnvDTEProjectName EnvDTEProjectName)
        {
            HashSet <EnvDTEProjectName> projectNames;

            if (!_shortNameCache.TryGetValue(EnvDTEProjectName.ShortName, out projectNames))
            {
                projectNames = new HashSet <EnvDTEProjectName>();
                _shortNameCache.Add(EnvDTEProjectName.ShortName, projectNames);
            }

            projectNames.Add(EnvDTEProjectName);
        }
示例#4
0
        /// <summary>
        /// Removes a project from the short name cache.
        /// </summary>
        /// <param name="envDTEProjectName">The short name of the project.</param>
        private void RemoveShortName(EnvDTEProjectName envDTEProjectName)
        {
            HashSet <EnvDTEProjectName> projectNames;

            if (_shortNameCache.TryGetValue(envDTEProjectName.ShortName, out projectNames))
            {
                projectNames.Remove(envDTEProjectName);

                // Remove the item from the dictionary if we've removed the last project
                if (projectNames.Count == 0)
                {
                    _shortNameCache.Remove(envDTEProjectName.ShortName);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Tries to find a project by short name. Returns the project name if and only if it is non-ambiguous.
        /// </summary>
        public bool TryGetProjectNameByShortName(string name, out EnvDTEProjectName EnvDTEProjectName)
        {
            EnvDTEProjectName = null;

            HashSet <EnvDTEProjectName> projectNames;

            if (_shortNameCache.TryGetValue(name, out projectNames))
            {
                // Get the item at the front of the queue
                EnvDTEProjectName = projectNames.Count == 1 ? projectNames.Single() : null;

                // Only return true if the short name is unambiguous
                return(EnvDTEProjectName != null);
            }

            return(false);
        }
示例#6
0
        private void AddEnvDTEProjectToCache(EnvDTEProject envDTEProject)
        {
            if (!EnvDTEProjectUtility.IsSupported(envDTEProject))
            {
                return;
            }

            EnvDTEProjectName oldEnvDTEProjectName;

            _nuGetAndEnvDTEProjectCache.TryGetProjectNameByShortName(EnvDTEProjectUtility.GetName(envDTEProject), out oldEnvDTEProjectName);

            EnvDTEProjectName newEnvDTEProjectName = _nuGetAndEnvDTEProjectCache.AddProject(envDTEProject, GetProjectFactory());

            if (String.IsNullOrEmpty(DefaultNuGetProjectName) ||
                newEnvDTEProjectName.ShortName.Equals(DefaultNuGetProjectName, StringComparison.OrdinalIgnoreCase))
            {
                DefaultNuGetProjectName = oldEnvDTEProjectName != null ?
                                          oldEnvDTEProjectName.CustomUniqueName :
                                          newEnvDTEProjectName.ShortName;
            }
        }
示例#7
0
        /// <summary>
        /// Adds a project to the project cache. If the project already exists in the cache, this
        /// this operation does nothing.
        /// </summary>
        /// <param name="projectName">The project name.</param>
        /// <param name="project">The VS project.</param>
        /// <param name="nuGetProject">The NuGet project.</param>
        /// <returns>
        /// Returns true if the project was newly added to the cache. Returns false if the project
        /// was already in the cache.
        /// </returns>
        public bool AddProject(EnvDTEProjectName projectName, EnvDTEProject project, NuGetProject nuGetProject)
        {
            // Do nothing if we already have an entry
            if (_envDTEProjectCache.ContainsKey(projectName))
            {
                return(false);
            }

            // Add the project to the cache.
            AddShortName(projectName);

            _projectNamesCache[projectName.CustomUniqueName] = projectName;
            _projectNamesCache[projectName.UniqueName]       = projectName;
            _projectNamesCache[projectName.FullName]         = projectName;

            _nuGetProjectCache[projectName] = nuGetProject;

            // Add the entry mapping project name to the actual project
            _envDTEProjectCache[projectName] = project;

            return(true);
        }
示例#8
0
        private void AddEnvDTEProjectToCache(EnvDTEProject envDTEProject)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!EnvDTEProjectUtility.IsSupported(envDTEProject))
            {
                return;
            }

            EnvDTEProjectName oldEnvDTEProjectName;

            _nuGetAndEnvDTEProjectCache.TryGetProjectNameByShortName(EnvDTEProjectUtility.GetName(envDTEProject), out oldEnvDTEProjectName);

            // Create the NuGet project first. If this throws we bail out and do not change the cache.
            var nuGetProject = GetProjectFactory().CreateNuGetProject(envDTEProject);

            // Then create the project name from the project.
            var newEnvDTEProjectName = new EnvDTEProjectName(envDTEProject);

            // Finally, try to add the project to the cache.
            var added = _nuGetAndEnvDTEProjectCache.AddProject(newEnvDTEProjectName, envDTEProject, nuGetProject);

            if (added)
            {
                // Emit project specific telemetry as we are adding the project to the cache.
                // This ensures we do not emit the events over and over while the solution is
                // open.
                NuGetProjectTelemetryService.Instance.EmitNuGetProject(envDTEProject, nuGetProject);
            }

            if (string.IsNullOrEmpty(DefaultNuGetProjectName) ||
                newEnvDTEProjectName.ShortName.Equals(DefaultNuGetProjectName, StringComparison.OrdinalIgnoreCase))
            {
                DefaultNuGetProjectName = oldEnvDTEProjectName != null ?
                                          oldEnvDTEProjectName.CustomUniqueName :
                                          newEnvDTEProjectName.ShortName;
            }
        }
示例#9
0
        /// <summary>
        /// Add a project to the cache.
        /// </summary>
        /// <param name="project">project to add to the cache.</param>
        /// <returns>The project name of the added project.</returns>
        public EnvDTEProjectName AddProject(EnvDTEProject project, VSNuGetProjectFactory factory)
        {
            // First create a project name from the project
            var EnvDTEProjectName = new EnvDTEProjectName(project);

            // Do nothing if we already have an entry
            if (_envDTEProjectCache.ContainsKey(EnvDTEProjectName))
            {
                return(EnvDTEProjectName);
            }

            AddShortName(EnvDTEProjectName);

            _projectNamesCache[EnvDTEProjectName.CustomUniqueName] = EnvDTEProjectName;
            _projectNamesCache[EnvDTEProjectName.UniqueName]       = EnvDTEProjectName;
            _projectNamesCache[EnvDTEProjectName.FullName]         = EnvDTEProjectName;

            // Add the entry mapping project name to the actual project
            _envDTEProjectCache[EnvDTEProjectName] = project;
            _nuGetProjectCache[EnvDTEProjectName]  = factory.CreateNuGetProject(project);

            return(EnvDTEProjectName);
        }
示例#10
0
 /// <summary>
 /// Finds a project name by short name, unique name or custom unique name.
 /// </summary>
 /// <param name="name">name of the project</param>
 /// <param name="EnvDTEProjectName">project name instance</param>
 /// <returns>true if the project name with the specified name is found.</returns>
 public bool TryGetNuGetProjectName(string name, out EnvDTEProjectName EnvDTEProjectName)
 {
     return(_projectNamesCache.TryGetValue(name, out EnvDTEProjectName) ||
            TryGetProjectNameByShortName(name, out EnvDTEProjectName));
 }