Esempio n. 1
0
        /// <summary>
        /// Processes individual project.
        /// </summary>
        /// <returns>Whether project's been processed or not.</returns>
        private bool ProcessProject(Project project, ICollection <ProjectModel> model, ProcessorFlags flags, CodeModelFilterFlags filter)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var process  = true;
            var language = string.Empty;

            // Safety check & language retrieval
            try
            {
                var items = project.ProjectItems;
                if ((items != null) && (items.Count > 0))
                {
                    if (_shellProjectService.IsCodeModelProject(project))
                    {
                        language = _shellProjectService.GetProjectLanguage(project);
                        if (string.IsNullOrEmpty(language))
                        {
                            process = false;
                        }
                    }
                    else
                    {
                        language = _shellProjectService.GetNoCodeModelProjectLanguage(project);
                        if (string.IsNullOrEmpty(language))
                        {
                            process = false;
                        }
                    }
                }
            }
            catch (NotImplementedException)             // This is an acceptable condition - keep on going
            {
                process = false;
                _log.LogMessage($"Project '{project?.Name}' doesn't implement code model");
            }
            catch (Exception ex)             // But this is a legit problem - keep on going anyways
            {
                process = false;
                _log.LogMessage("Failed to retrieve project code model / language", ex);
            }

            string projectFullName = string.Empty;

            if (process)
            {
                _shellProjectService.GetProjectPath(project, out string projectPath, out projectFullName);
                if ((string.IsNullOrEmpty(projectPath) || string.IsNullOrEmpty(projectFullName)) && _shellProjectService.IsProject(project))
                {
                    process = false;
                    _log.LogMessage($"Project '{project?.Name}' path is not available");
                }
            }

            if (process)
            {
                var projectModel = new ProjectModel
                {
                    Project      = project,
                    Name         = project.Name,
                    FriendlyName = _shellProjectService.GetFriendlyProjectName(project),
                    FileName     = projectFullName,
                    Language     = _languageService.GetLanguage(language)
                };

                if (flags.HasFlag(ProcessorFlags.IncludeFiles))
                {
                    var files = _projectProcessor.GetFiles(project, flags, filter);
                    if (files != null)
                    {
                        projectModel.Files.AddRange(files);
                        files.ForEach(f => f.Project = projectModel);
                    }
                }

                model.Add(projectModel);
            }

            return(process);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns project's language.
        /// </summary>
        /// <param name="project">Project. Untyped extensibility link (name matches the actual type).</param>
        /// <param name="isWebProject">Whether it's a web project.</param>
        /// <returns>Language.</returns>
        public LanguageSettings GetCurrentLanguage(object project, out bool isWebProject)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            isWebProject = false;

            if (project == null)
            {
                return(LanguageSettings.UnknownLanguage);
            }

            var dteProject = project as Project;

            if (dteProject == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            try
            {
                var projectName = dteProject.Name;
                if (projectName != null)
                {
                    if (!string.IsNullOrEmpty(projectName))
                    {
                        _log.LogMessage($"Check '{projectName}' project language");
                    }
                    else
                    {
                        _log.LogMessage("Check unnamed project language");
                    }
                }

                var languageSet = LanguageSettings.UnknownLanguage;
                var language    = _shellProjectService.GetProjectLanguage(project);
                if (language != null)
                {
                    if (language == string.Empty)
                    {
                        language = _shellProjectService.GetNoCodeModelProjectLanguage(project);
                    }

                    if (!string.IsNullOrEmpty(language))
                    {
                        languageSet = _languageService.GetLanguage(language);

                        if (languageSet?.Type != LanguageType.Unknown)
                        {
                            // C++ doesn't expose project type
                            if (languageSet.Type != LanguageType.CPP)
                            {
                                isWebProject = _shellProjectService.IsWebProject(project);
                            }
                        }
                    }
                }

                _log.LogMessage($"'{projectName}' project language is {languageSet?.FriendlyName}");
                return(languageSet);
            }
            catch (NotImplementedException)             // This is an acceptable condition
            {
                _log.LogMessage("Project doesn't implement code model");
                return(LanguageSettings.UnknownLanguage);
            }
            catch (Exception ex)             // But this is a legit problem - raise an exception
            {
                _log.LogMessage("Failed to check project language", ex);
                throw;
            }
        }