public void Execute(Solution solution) { if (solution == null) return; var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher(); var projectsInSolution = allSolutionProjectsSearcher.GetAllProjects(solution); var projectsWithoutLicenseHeaderFile = CheckForLicenseHeaderFileInProjects (projectsInSolution); if (projectsInSolution.Count == 1 && projectsWithoutLicenseHeaderFile.Count == 1) { //There is exactly one Project in the Solution and it has no Definition File //--> Offer to add a new one and ask if they want to stop the update process to configure them if (MessageBoxHelper.DoYouWant(Resources.Question_AddNewLicenseHeaderDefinitionFileSingleProject)) { var licenseHeader = LicenseHeader.AddLicenseHeaderDefinitionFile(projectsInSolution.First(), _licenseHeaderPage); if (!MessageBoxHelper.DoYouWant(Resources.Question_StopForConfiguringDefinitionFilesSingleFile)) AddLicenseHeaderToProjects(projectsInSolution); else if (licenseHeader != null) licenseHeader.Open(Constants.vsViewKindCode).Activate(); } } else if (projectsWithoutLicenseHeaderFile.Count == projectsInSolution.Count) { //There are multiple Projects in the Solution but none of them has a Definition File //--> Offer to add new ones to everyone of them and ask if they want to stop the update process to configure them if (MessageBoxHelper.DoYouWant(Resources.Question_AddNewLicenseHeaderDefinitionFileMultipleProjects)) { var newLicenseHeaders = AddNewLicenseHeaderDefinitionFilesToProjects(projectsWithoutLicenseHeaderFile, _licenseHeaderPage); if (!MessageBoxHelper.DoYouWant(Resources.Question_StopForConfiguringDefinitionFilesMultipleFiles)) AddLicenseHeaderToProjects(projectsInSolution); else if (newLicenseHeaders.Count() <= Resources.Constant_MaxNumberOfProjectItemsWhereOpeningDefinitionFilesInEditor) { foreach (var licenseHeader in newLicenseHeaders) { licenseHeader.Open(Constants.vsViewKindCode).Activate(); } } } else { MessageBoxHelper.Information(Resources.Information_NoDefinitionFileStopUpdating); } } else if (projectsWithoutLicenseHeaderFile.Any()) { //There are projects with and without Definition File --> Ask if we should add an existing License Header File to them and then add License Headers if (DefinitionFilesShouldBeAdded(projectsWithoutLicenseHeaderFile)) new AddExistingLicenseHeaderDefinitionFileCommand().AddDefinitionFileToMultipleProjects(projectsWithoutLicenseHeaderFile); AddLicenseHeaderToProjects(projectsInSolution); } else { //There are no Projects without Definition File --> Add License Headers AddLicenseHeaderToProjects(projectsInSolution); } }
public void Execute(Solution solution) { var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher(); var projectsInSolution = allSolutionProjectsSearcher.GetAllProjects(solution); var projectsWithoutLicenseHeaderFile = CheckForLicenseHeaderFileInProjects (projectsInSolution); if (DefinitionFilesShouldBeAdded(projectsWithoutLicenseHeaderFile)) AddMissingLicenseHeaderFiles(projectsWithoutLicenseHeaderFile, licenseHeaderPage); AddLicenseHeaderToProjects(projectsInSolution); }
public void TestGetAllProjects_ShouldReturnListOfProjects() { Solution solution = MockRepository.GenerateStub<Solution>(); Project legitProject1 = MockRepository.GenerateStub<Project>(); Project legitProject2 = MockRepository.GenerateStub<Project>(); List<Project> projectList = new List<Project> {legitProject1, legitProject2}; solution.Stub(x => x.GetEnumerator()).Return(projectList.GetEnumerator()); var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher(); List<Project> returnedProjects = allSolutionProjectsSearcher.GetAllProjects(solution); Assert.AreEqual(2, returnedProjects.Count); }
public void Execute(Solution solution) { var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher(); var projectsInSolution = allSolutionProjectsSearcher.GetAllProjects(solution); int progressCount = 1; int projectCount = projectsInSolution.Count; var removeAllLicenseHeadersCommand = new RemoveLicenseHeaderFromAllFilesCommand(licenseReplacer); foreach (Project project in projectsInSolution) { statusBar.SetText(string.Format(Resources.UpdateSolution, progressCount, projectCount)); removeAllLicenseHeadersCommand.Execute(project); progressCount++; } statusBar.SetText(string.Empty); }
public void TestGetAllProjects_DoesOnlyReturnProjects() { Solution solution = MockRepository.GenerateStub<Solution>(); Project legitProject1 = MockRepository.GenerateStub<Project> (); Project solutionFolder = MockRepository.GenerateStub<Project> (); List<Project> projectList = new List<Project>{legitProject1, solutionFolder}; solutionFolder.Stub(x => x.Kind).Return(ProjectKinds.vsProjectKindSolutionFolder); solutionFolder.Stub(x => x.ProjectItems.Count).Return(0); solution.Stub(x => x.GetEnumerator()).Return(projectList.GetEnumerator()); var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher(); List<Project> returnedProjects = allSolutionProjectsSearcher.GetAllProjects(solution); Assert.AreEqual(legitProject1, returnedProjects.First()); }
public void TestGetAllProjects_FindsNestedProject() { Solution solution = MockRepository.GenerateStub<Solution>(); Project legitProject1 = MockRepository.GenerateStub<Project>(); Project solutionFolder = MockRepository.GenerateStub<Project>(); Project projectInSolutionFolder = MockRepository.GenerateStub<Project>(); List<Project> projectList = new List<Project> {legitProject1, solutionFolder}; solutionFolder.Stub(x => x.Kind).Return(ProjectKinds.vsProjectKindSolutionFolder); solutionFolder.Stub(x => x.ProjectItems.Count).Return(1); solutionFolder.Stub(x => x.ProjectItems.Item(1).SubProject).Return(projectInSolutionFolder); solution.Stub(x => x.GetEnumerator()).Return(projectList.GetEnumerator()); var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher(); List<Project> returnedProjects = allSolutionProjectsSearcher.GetAllProjects(solution); Assert.Contains(projectInSolutionFolder, returnedProjects); }
private void HandleAddLicenseHeaderToAllFilesReturn(object obj, AddLicenseHeaderToAllFilesReturn addLicenseHeaderToAllFilesReturn) { var project = obj as Project; var projectItem = obj as ProjectItem; if (project == null && projectItem == null) return; Project currentProject = project; if (projectItem != null) { currentProject = projectItem.ContainingProject; } if (addLicenseHeaderToAllFilesReturn.NoHeaderFound) { //No license header found... var page = (DefaultLicenseHeaderPage) GetDialogPage(typeof (DefaultLicenseHeaderPage)); var solutionSearcher = new AllSolutionProjectsSearcher(); var projects = solutionSearcher.GetAllProjects(_dte.Solution); //If there is a licenseheader in the Solution if(projects.Any(projectInSolution => LicenseHeaderFinder.GetHeader(projectInSolution) != null)) { if (MessageBoxHelper.DoYouWant(Resources.Question_AddExistingDefinitionFileToProject)) { new AddExistingLicenseHeaderDefinitionFileCommand().AddDefinitionFileToOneProject(currentProject.FileName, currentProject.ProjectItems); AddLicenseHeadersToAllFilesCallback((object) project ?? projectItem, null); } } else { if (MessageBoxHelper.DoYouWant(Resources.Question_AddNewLicenseHeaderDefinitionFileSingleProject)) { var licenseHeader = LicenseHeader.AddLicenseHeaderDefinitionFile(currentProject, DefaultLicenseHeaderPage); if (!MessageBoxHelper.DoYouWant(Resources.Question_StopForConfiguringDefinitionFilesSingleFile)) AddLicenseHeadersToAllFilesCallback((object) project ?? projectItem, null); else if (licenseHeader != null) licenseHeader.Open(Constants.vsViewKindCode).Activate(); } } } }