public override async Task DoWorkAsync(CancellationToken cancellationToken, BaseUpdateViewModel viewModel, Solution solution)
        {
            if (solution == null)
            {
                return;
            }

            if (!(viewModel is SolutionUpdateViewModel updateViewModel))
            {
                throw new ArgumentException($"Argument {nameof(viewModel)} must be of type {nameof(SolutionUpdateViewModel)}");
            }

            await _licenseHeaderExtension.JoinableTaskFactory.SwitchToMainThreadAsync();

            var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher();
            var projectsInSolution          = allSolutionProjectsSearcher.GetAllProjects(solution);

            updateViewModel.ProcessedProjectCount = 0;
            updateViewModel.ProjectCount          = projectsInSolution.Count;
            var removeAllLicenseHeadersCommand = new RemoveLicenseHeaderFromAllFilesInProjectHelper(cancellationToken, _licenseHeaderExtension, updateViewModel);

            foreach (var project in projectsInSolution)
            {
                await removeAllLicenseHeadersCommand.ExecuteAsync(project);
                await IncrementProjectCountAsync(updateViewModel).ConfigureAwait(true);
            }
        }
        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);
        }
Пример #3
0
        public async Task TestGetAllProjects_FindsNestedProject()
        {
            await VisualStudioTestContext.SwitchToMainThread();

            var solution = MockRepository.GenerateStub <Solution>();

            var legitProject1           = MockRepository.GenerateStub <Project>();
            var solutionFolder          = MockRepository.GenerateStub <Project>();
            var projectInSolutionFolder = MockRepository.GenerateStub <Project>();

            var 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();
            var returnedProjects            = allSolutionProjectsSearcher.GetAllProjects(solution);


            Assert.Contains(projectInSolutionFolder, returnedProjects.ToList());
        }
Пример #4
0
        public async Task TestGetAllProjects_ReturnsOnlyProjects()
        {
            await VisualStudioTestContext.SwitchToMainThread();

            var solution = MockRepository.GenerateStub <Solution>();

            var legitProject1  = MockRepository.GenerateStub <Project>();
            var solutionFolder = MockRepository.GenerateStub <Project>();

            var 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();
            var returnedProjects            = allSolutionProjectsSearcher.GetAllProjects(solution);


            Assert.That(legitProject1, Is.EqualTo(returnedProjects.First()));
        }
        public void Execute(Solution solution)
        {
            if (solution == null)
            {
                return;
            }

            IDictionary <string, string[]> solutionHeaderDefinitions = LicenseHeaderFinder.GetHeaderDefinitionForSolution(solution);

            var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher();
            var projectsInSolution          = allSolutionProjectsSearcher.GetAllProjects(solution);

            var projectsWithoutLicenseHeaderFile = projectsInSolution
                                                   .Where(project => LicenseHeaderFinder.GetHeaderDefinitionForProjectWithoutFallback(project) == null)
                                                   .ToList();

            var projectsWithLicenseHeaderFile = projectsInSolution
                                                .Where(project => LicenseHeaderFinder.GetHeaderDefinitionForProjectWithoutFallback(project) != null)
                                                .ToList();

            if (solutionHeaderDefinitions != null || !projectsWithoutLicenseHeaderFile.Any())
            {
                // Every project is covered either by a solution or project level license header defintion, go ahead and add them.
                AddLicenseHeaderToProjects(projectsInSolution);
            }
            else
            {
                // Some projects are not covered by a header.

                bool someProjectsHaveDefinition = projectsWithLicenseHeaderFile.Count > 0;
                if (someProjectsHaveDefinition)
                {
                    // Some projects have a header. Ask the user if they want to add an existing header to the uncovered projects.
                    if (DefinitionFilesShouldBeAdded(projectsWithoutLicenseHeaderFile))
                    {
                        new AddExistingLicenseHeaderDefinitionFileToProjectCommand().AddDefinitionFileToMultipleProjects(projectsWithoutLicenseHeaderFile);
                    }

                    AddLicenseHeaderToProjects(projectsInSolution);
                }
                else
                {
                    // No projects have definition. Ask the user if they want to add a solution level header definition.
                    if (MessageBoxHelper.DoYouWant(Resources.Question_AddNewLicenseHeaderDefinitionForSolution))
                    {
                        AddNewSolutionLicenseHeaderDefinitionFileCommand.Instance.Execute(solution);

                        if (!MessageBoxHelper.DoYouWant(Resources.Question_StopForConfiguringDefinitionFilesSingleFile))
                        {
                            // They want to go ahead and apply without editing.
                            AddLicenseHeaderToProjects(projectsInSolution);
                        }
                    }
                }
            }
        }
        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 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);
                    }
                }
            }
        }
Пример #8
0
        private void HandleAddLicenseHeaderToAllFilesInProjectReturn(
            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 solutionSearcher = new AllSolutionProjectsSearcher();
                var projects         = solutionSearcher.GetAllProjects(_dte.Solution);

                if (projects.Any(projectInSolution => LicenseHeaderFinder.GetHeaderDefinitionForProjectWithoutFallback(projectInSolution) != null))
                {
                    // If another projet has a license header, offer to add a link to the existing one.
                    if (MessageBoxHelper.DoYouWant(Resources.Question_AddExistingDefinitionFileToProject))
                    {
                        new AddExistingLicenseHeaderDefinitionFileToProjectCommand().AddDefinitionFileToOneProject(
                            currentProject.FileName,
                            currentProject.ProjectItems);

                        AddLicenseHeadersToAllFilesInProjectCallback((object)project ?? projectItem, null);
                    }
                }
                else
                {
                    // If no project has a license header, offer to add one for the solution.
                    if (MessageBoxHelper.DoYouWant(Resources.Question_AddNewLicenseHeaderDefinitionForSolution))
                    {
                        AddNewSolutionLicenseHeaderDefinitionFileCallback(this, new EventArgs());
                    }
                }
            }
        }
        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);
        }
Пример #10
0
        public async Task TestGetAllProjects_ShouldReturnListOfProjects()
        {
            await VisualStudioTestContext.SwitchToMainThread();

            var solution = MockRepository.GenerateStub <Solution>();

            var legitProject1 = MockRepository.GenerateStub <Project>();
            var legitProject2 = MockRepository.GenerateStub <Project>();

            var projectList = new List <Project> {
                legitProject1, legitProject2
            };

            solution.Stub(x => x.GetEnumerator()).Return(projectList.GetEnumerator());


            var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher();
            var returnedProjects            = allSolutionProjectsSearcher.GetAllProjects(solution);


            Assert.That(returnedProjects.Count, Is.EqualTo(2));
        }
        public void Execute(Solution solution)
        {
            if (solution == null)
            {
                return;
            }

            var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher();
            var projectsInSolution          = allSolutionProjectsSearcher.GetAllProjects(solution);

            int progressCount = 1;
            int projectCount  = projectsInSolution.Count;
            var removeAllLicenseHeadersCommand = new RemoveLicenseHeaderFromAllFilesInProjectCommand(_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 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);
            }
        }
Пример #14
0
        public override async Task DoWorkAsync(CancellationToken cancellationToken, BaseUpdateViewModel viewModel, Solution solution, Window window)
        {
            if (solution == null)
            {
                return;
            }

            if (!(viewModel is SolutionUpdateViewModel updateViewModel))
            {
                throw new ArgumentException($"Argument {nameof(viewModel)} must be of type {nameof(SolutionUpdateViewModel)}");
            }

            await _licenseHeaderExtension.JoinableTaskFactory.SwitchToMainThreadAsync();

            var solutionHeaderDefinitions = LicenseHeaderFinder.GetHeaderDefinitionForSolution(solution);

            var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher();
            var projectsInSolution          = allSolutionProjectsSearcher.GetAllProjects(solution);

            var projectsWithoutLicenseHeaderFile = projectsInSolution
                                                   .Where(project => LicenseHeaderFinder.GetHeaderDefinitionForProjectWithoutFallback(project) == null)
                                                   .ToList();

            var projectsWithLicenseHeaderFile = projectsInSolution
                                                .Where(project => LicenseHeaderFinder.GetHeaderDefinitionForProjectWithoutFallback(project) != null)
                                                .ToList();

            if (solutionHeaderDefinitions != null || !projectsWithoutLicenseHeaderFile.Any())
            {
                // Every project is covered either by a solution or project level license header definition, go ahead and add them.
                await AddLicenseHeaderToProjectsAsync(cancellationToken, projectsInSolution, updateViewModel);
            }
            else
            {
                // Some projects are not covered by a header.

                var someProjectsHaveDefinition = projectsWithLicenseHeaderFile.Count > 0;
                if (someProjectsHaveDefinition)
                {
                    // Some projects have a header. Ask the user if they want to add an existing header to the uncovered projects.
                    if (await DefinitionFilesShouldBeAddedAsync(projectsWithoutLicenseHeaderFile, window))
                    {
                        ExistingLicenseHeaderDefinitionFileAdder.AddDefinitionFileToMultipleProjects(projectsWithoutLicenseHeaderFile);
                    }

                    await AddLicenseHeaderToProjectsAsync(cancellationToken, projectsInSolution, updateViewModel);
                }
                else
                {
                    // No projects have definition. Ask the user if they want to add a solution level header definition.
                    if (await MessageBoxHelper.AskYesNoAsync(window, Resources.Question_AddNewLicenseHeaderDefinitionForSolution.ReplaceNewLines()).ConfigureAwait(true))
                    {
                        AddNewSolutionLicenseHeaderDefinitionFileCommand.Instance.Invoke(solution);

                        // They want to go ahead and apply without editing.
                        if (!await MessageBoxHelper.AskYesNoAsync(window, Resources.Question_StopForConfiguringDefinitionFilesSingleFile).ConfigureAwait(true))
                        {
                            await AddLicenseHeaderToProjectsAsync(cancellationToken, projectsInSolution, updateViewModel);
                        }
                    }
                }
            }
        }
        public Page_ChooseTheProjects(Context context)
        {
            InitializeComponent();

            _context = context;

            // Clear the list of projects:
            _context.AllProjects.Clear();
            _context.CandidateProjectsToMigrate.Clear();

            // Check if we are running inside VS:
            if (_context.Solution != null)
            {
                // Get the list of projects:
                List <EnvDTE.Project> allProjects = AllSolutionProjectsSearcher.GetAllProjects(_context.Solution);

                // Process the list of projects:
                foreach (EnvDTE.Project project in allProjects)
                {
                    // Get project information (path, type, etc.):
                    string fullPathOfCSProj;
                    Context.ProjectType       projectType;
                    Context.ProjectOutputType projectOutputType;
                    GetProjectInformation(project, context.Solution, out fullPathOfCSProj, out projectType, out projectOutputType);

                    // Create a new model for the project:
                    var projectModel = new Context.ProjectModel()
                    {
                        Name                    = project.Name,
                        FullPathOfCSProj        = fullPathOfCSProj,
                        ProjectLoadedWithEnvDTE = project,
                        IsSelected              = false,
                        DestinationName         = AppendCSHTML5ToProjectName(project.Name),
                        DestinationProjectType  = "CSHTML5",
                        ProjectType             = projectType,
                        ProjectOutputType       = projectOutputType
                    };

                    // Add the project:
                    _context.AllProjects.Add(projectModel);

                    // If the project is of type "Silverlight" and the other information is ok, it is a valid candidate for the migration:
                    if (projectType == Context.ProjectType.Silverlight &&
                        projectOutputType != Context.ProjectOutputType.Unknown)
                    {
                        _context.CandidateProjectsToMigrate.Add(projectModel);
                    }
                }

                // Diplay the candidate projects:
                ProjectsDataGrid.ItemsSource = _context.CandidateProjectsToMigrate;
            }
            else
            {
                ProjectsDataGrid.ItemsSource = new List <Context.ProjectModel> {
                    new Context.ProjectModel()
                    {
                        Name = "Test1"
                    },
                    new Context.ProjectModel()
                    {
                        Name = "Test2"
                    }
                };
            }
        }