Beispiel #1
0
 private void AddProjectToSolution(CxViewerAction.Entities.Project outputProject, ProjectItems projectItems)
 {
     foreach (EnvDTE.ProjectItem solutionProject in projectItems)
     {
         try
         {
             if (solutionProject.SubProject == null)
             {
                 continue;
             }
             if (!string.IsNullOrEmpty(solutionProject.SubProject.FullName))
             {
                 outputProject.ProjectPaths.Add(new Entities.Project(solutionProject.SubProject.Name, new FileInfo(solutionProject.SubProject.FullName).DirectoryName));
             }
             else // can be virtual folder
             {
                 if (solutionProject.SubProject.ProjectItems == null)
                 {
                     continue;
                 }
                 AddProjectToSolution(outputProject, solutionProject.SubProject.ProjectItems);
             }
         }
         catch (Exception ex)
         {
             Logger.Create().Error(ex.ToString());
         }
     }
 }
Beispiel #2
0
        private void AddProjectToSolution(CxViewerAction.Entities.Project outputProject, Projects projects)
        {
            foreach (EnvDTE.Project solutionProject in projects)
            {
                try
                {
                    if (!string.IsNullOrEmpty(solutionProject.FullName))
                    {
                        string projectFullPath = solutionProject.FullName;

                        // For version 2013 we have a bug where project.FullName returns http://localhost:XXXX
                        // The following line returns the project full path for all project kinds.
                        // for versions prior to 2013 for web projects, project.FullName return the project loaction with '/' in the end. Our algorithm is based on that behaviour.
                        // in order to maintain this behaviour, we always trim '//' '\' from fullPAth, and append "//". This way the rest of the code would execute as usual.
                        if (solutionProject.Kind == vsProjectKindWeb) //if project is web
                        {
                            string webProjectPath = solutionProject.Properties.Item("FullPath").Value as string;
                            webProjectPath  = webProjectPath.TrimEnd(new[] { '\\', '/' });
                            projectFullPath = webProjectPath + "//";
                            FileInfo fileInfo = new FileInfo(projectFullPath);
                            projectFullPath = fileInfo.FullName;
                        }

                        outputProject.ProjectPaths.Add(new Entities.Project(solutionProject.Name, new FileInfo(projectFullPath).DirectoryName));
                    }
                    else // can be virtual folder
                    {
                        AddProjectToSolution(outputProject, solutionProject.ProjectItems);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Create().Error(ex.ToString());
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get project path for current selected project in solution explorer
        /// </summary>
        /// <returns></returns>
        public Entities.Project GetSelectedProject()
        {
            string projectName, projectPath;
            Array  projects = (Array)_applicationObject.ActiveSolutionProjects;

            List <string> folderPathList = new List <string>();
            List <string> filePathList   = new List <string>();;

            //Context menu are displayed on project item in solution explorer
            if (_applicationObject.SelectedItems != null)
            {
                foreach (SelectedItem selectedItem in _applicationObject.SelectedItems)
                {
                    if (selectedItem.ProjectItem != null)
                    {
                        if (selectedItem.ProjectItem.Kind == EnvDTEConstants.vsProjectItemKindPhysicalFolder) // folder
                        {
                            folderPathList.Add(selectedItem.ProjectItem.Properties.Item("FullPath").Value.ToString());
                        }
                        else if (selectedItem.ProjectItem.Kind == EnvDTEConstants.vsProjectItemKindPhysicalFile) // item
                        {
                            filePathList.Add(selectedItem.ProjectItem.Properties.Item("FullPath").Value.ToString());
                        }
                    }
                }
            }
            string projectFullPath = string.Empty;

            try
            {
                if (projects.Length == 0)
                {
                    //Context menu are displayed on solution item in solution explorer

                    Solution solution = _applicationObject.Solution;
                    if (String.IsNullOrEmpty(solution.FileName))
                    {
                        return(null);
                    }
                    FileInfo fileInfo = new FileInfo(solution.FileName);

                    Entities.Project outputProject = new Entities.Project(fileInfo.Name, fileInfo.DirectoryName, filePathList, folderPathList);

                    AddProjectToSolution(outputProject, solution.Projects);


                    return(outputProject);
                }
                else
                {
                    EnvDTE.Project project = ((EnvDTE.Project)projects.GetValue(0));
                    projectFullPath = project.FullName;

                    // For versions earlier than 2013 we have a bug where project.FullName returns http://localhost:XXXX
                    // The following line returns the project full path for all project kinds.
                    // for versions prior to 2013 for web projects, project.FullName return the project loaction with '/' in the end. Our algorithm is based on that behaviour.
                    // in order to maintain this behaviour, we always trim '//' '\' from fullPAth, and append "//". This way the rest of the code would execute as usual.
                    if (project.Kind == vsProjectKindWeb) //if project is web
                    {
                        string webProjectPath = project.Properties.Item("FullPath").Value as string;
                        webProjectPath  = webProjectPath.TrimEnd(new[] { '\\', '/' });
                        projectFullPath = webProjectPath + "//";
                    }

                    FileInfo fileInfo = new FileInfo(projectFullPath);

                    projectName = Path.GetFileName(project.Name.TrimEnd(new[] { '\\', '/' }));
                    projectPath = fileInfo.Directory.FullName;

                    return(new Entities.Project(projectName, projectPath, filePathList, folderPathList));
                }
            }
            catch (ArgumentException ae)
            {
                Logger.Create().Error(ae.ToString());
                if (false == string.IsNullOrEmpty(projectFullPath))
                {
                    Logger.Create().Error("projectFullPath = " + projectFullPath);
                }
            }
            catch (Exception ex)
            {
                Logger.Create().Error(ex.ToString());
            }
            return(null);
        }