public static void AddExistingLicenseHeaderDefinitionFile(ILicenseHeaderExtension serviceProvider) { ThreadHelper.ThrowIfNotOnUIThread(); var project = serviceProvider.GetSolutionExplorerItem() as Project; var projectItem = serviceProvider.GetSolutionExplorerItem() as ProjectItem; string fileName; if (project != null) { fileName = project.FileName; } else if (projectItem != null) { fileName = projectItem.Name; } else { return; } ProjectItems projectItems = null; if (project != null) { projectItems = project.ProjectItems; } else if (projectItem != null) { projectItems = projectItem.ProjectItems; } ExistingLicenseHeaderDefinitionFileAdder.AddDefinitionFileToOneProject(fileName, projectItems); }
private static async Task HandleAddLicenseHeaderToAllFilesInProjectResultAsync( CancellationToken cancellationToken, ILicenseHeaderExtension serviceProvider, object obj, AddLicenseHeaderToAllFilesResult addResult, BaseUpdateViewModel baseUpdateViewModel) { await serviceProvider.JoinableTaskFactory.SwitchToMainThreadAsync(); var project = obj as Project; var projectItem = obj as ProjectItem; if (project == null && projectItem == null) { return; } var currentProject = project; if (projectItem != null) { currentProject = projectItem.ContainingProject; } if (addResult.NoHeaderFound) { // No license header found... var solutionSearcher = new AllSolutionProjectsSearcher(); var projects = solutionSearcher.GetAllProjects(serviceProvider.Dte2.Solution); if (projects.Any(projectInSolution => LicenseHeaderFinder.GetHeaderDefinitionForProjectWithoutFallback(projectInSolution) != null)) { baseUpdateViewModel.ProcessedFilesCountCurrentProject = 0; // If another project has a license header, offer to add a link to the existing one. if (MessageBoxHelper.AskYesNo(Resources.Question_AddExistingDefinitionFileToProject.ReplaceNewLines())) { ExistingLicenseHeaderDefinitionFileAdder.AddDefinitionFileToOneProject(currentProject.FileName, currentProject.ProjectItems); await AddLicenseHeaderToAllFilesAsync(cancellationToken, serviceProvider, baseUpdateViewModel); } } else { // If no project has a license header, offer to add one for the solution. if (MessageBoxHelper.AskYesNo(Resources.Question_AddNewLicenseHeaderDefinitionForSolution.ReplaceNewLines())) { AddNewSolutionLicenseHeaderDefinitionFileCommand.Instance.Invoke(serviceProvider.Dte2.Solution); } } } }