コード例 #1
0
        /// <summary>
        ///   Shows a message box that asks if a new License Header Definition File should be added to the active project.
        /// </summary>
        /// <param name="activeProject">The project where the definition file will be inserted.</param>
        /// <param name="pageModel">The page model where the license header definition text is stored.</param>
        /// <returns>True if a new License Header Definition file should be added to the current project, otherwise false.</returns>
        public static bool ShowQuestionForAddingLicenseHeaderFile(Project activeProject, IDefaultLicenseHeaderPageModel pageModel)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var message = string.Format(Resources.Error_NoHeaderDefinition, activeProject.Name).ReplaceNewLines();

            if (!MessageBoxHelper.AskYesNo(message, Resources.Error))
            {
                return(false);
            }
            var licenseHeaderDefinitionFile = AddHeaderDefinitionFile(activeProject, pageModel);

            licenseHeaderDefinitionFile.Open(Constants.vsViewKindCode).Activate();
            return(true);
        }
コード例 #2
0
        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);
                    }
                }
            }
        }