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(); } } } } }
private IEnumerable <ProjectItem> AddNewLicenseHeaderDefinitionFilesToProjects(List <Project> projectsWithoutLicenseHeader, IDefaultLicenseHeaderPage page) { List <ProjectItem> newLicenseHeaders = new List <ProjectItem>(); foreach (Project project in projectsWithoutLicenseHeader) { if (projectsWithoutLicenseHeader.Contains(project)) { newLicenseHeaders.Add(LicenseHeader.AddLicenseHeaderDefinitionFile(project, page)); } } return(newLicenseHeaders); }
private void AddNewLicenseHeaderDefinitionFileToProjectCallback(object sender, EventArgs e) { var page = (DefaultLicenseHeaderPage)GetDialogPage(typeof(DefaultLicenseHeaderPage)); var solutionItem = GetSolutionExplorerItem(); var project = solutionItem as Project; if (project == null) { var projectItem = solutionItem as ProjectItem; if (projectItem != null) { LicenseHeader.AddLicenseHeaderDefinitionFile(projectItem, page); } } if (project != null) { var licenseHeaderDefinitionFile = LicenseHeader.AddHeaderDefinitionFile(project, page); licenseHeaderDefinitionFile.Open(Constants.vsViewKindCode).Activate(); } }
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); } }