public static IEnumerable <Project> ShowProjectSelectorWindow( this IUserNotifierServices userNotifierServices, string instructionText, Predicate <Project> checkedStateSelector) { return(userNotifierServices.ShowProjectSelectorWindow( instructionText, package: null, checkedStateSelector: checkedStateSelector, enabledStateSelector: ignore => true)); }
protected override bool ExecuteCore(PackageItem item) { _activePackageManager = GetActivePackageManager(); using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Update, item.Id, item.Version)) { ShowProgressWindow(); IList <Project> selectedProjectsList; bool isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity); if (isProjectLevel) { HideProgressWindow(); var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow( Resources.Dialog_UpdatesSolutionInstruction, item.PackageIdentity, // Selector function to return the initial checkbox state for a Project. // We check a project if it has the current package installed by Id, but not version project => { var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository; return(localRepository.Exists(item.Id) && IsVersionConstraintSatisfied(item, localRepository)); }, project => { var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository; // for the Updates solution dialog, we only enable a project if it has an old version of // the package installed. return(localRepository.Exists(item.Id) && !localRepository.Exists(item.Id, item.PackageIdentity.Version) && IsVersionConstraintSatisfied(item, localRepository)); } ); if (selectedProjects == null) { // user presses Cancel button on the Solution dialog return(false); } selectedProjectsList = selectedProjects.ToList(); if (selectedProjectsList.Count == 0) { return(false); } ShowProgressWindow(); } else { // solution package. just update into the solution selectedProjectsList = new Project[0]; } IList <PackageOperation> operations; bool acceptLicense = isProjectLevel ? ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, selectedProjectsList, out operations) : ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, targetFramework: null, operations: out operations); if (!acceptLicense) { return(false); } if (!isProjectLevel && operations.Any()) { // When dealing with solution level packages, only the set of actions specified under operations are executed. // In such a case, no operation to uninstall the current package is specified. We'll identify the package that is being updated and // explicitly add a uninstall operation. var packageToUpdate = _activePackageManager.LocalRepository.FindPackage(item.Id); if (packageToUpdate != null) { operations.Insert(0, new PackageOperation(packageToUpdate, PackageAction.Uninstall)); } } try { RegisterPackageOperationEvents(_activePackageManager, null); _activePackageManager.UpdatePackage( selectedProjectsList, item.PackageIdentity, operations, updateDependencies: true, allowPrereleaseVersions: IncludePrerelease, logger: this, eventListener: this); } finally { UnregisterPackageOperationEvents(_activePackageManager, null); } return(true); } }
protected override bool ExecuteCore(PackageItem item) { _activePackageManager = GetActivePackageManager(); using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Install)) { IList <Project> selectedProjectsList; ShowProgressWindow(); bool isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity); if (isProjectLevel) { HideProgressWindow(); var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow( Resources.Dialog_OnlineSolutionInstruction, item.PackageIdentity, DetermineProjectCheckState, ignored => true); if (selectedProjects == null) { // user presses Cancel button on the Solution dialog return(false); } selectedProjectsList = selectedProjects.ToList(); if (selectedProjectsList.Count == 0) { return(false); } // save the checked state of projects so that we can restore them the next time SaveProjectCheckStates(selectedProjectsList); } else { // solution package. just install into the solution selectedProjectsList = new Project[0]; } IList <PackageOperation> operations; bool acceptLicense = isProjectLevel ? CheckPSScriptAndShowLicenseAgreement(item, selectedProjectsList, _activePackageManager, out operations) : CheckPSScriptAndShowLicenseAgreement(item, _activePackageManager, out operations); if (!acceptLicense) { return(false); } try { RegisterPackageOperationEvents(_activePackageManager, null); _activePackageManager.InstallPackage( selectedProjectsList, item.PackageIdentity, operations, ignoreDependencies: false, allowPrereleaseVersions: IncludePrerelease, logger: this, eventListener: this); } finally { UnregisterPackageOperationEvents(_activePackageManager, null); } return(true); } }
protected override bool ExecuteCore(PackageItem item) { _activePackageManager = GetActivePackageManager(); using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Update, item.Id, item.Version)) { ShowProgressWindow(); IList <Project> selectedProjectsList; bool isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity); if (isProjectLevel) { HideProgressWindow(); var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow( Resources.Dialog_UpdatesSolutionInstruction, item.PackageIdentity, // Selector function to return the initial checkbox state for a Project. // We check a project if it has the current package installed by Id, but not version project => { var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository; return(localRepository.Exists(item.Id) && IsVersionConstraintSatisfied(item, localRepository)); }, project => { var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository; // for the Updates solution dialog, we only enable a project if it has an old version of // the package installed. return(localRepository.Exists(item.Id) && !localRepository.Exists(item.Id, item.PackageIdentity.Version) && IsVersionConstraintSatisfied(item, localRepository)); } ); if (selectedProjects == null) { // user presses Cancel button on the Solution dialog return(false); } selectedProjectsList = selectedProjects.ToList(); if (selectedProjectsList.Count == 0) { return(false); } ShowProgressWindow(); } else { // solution package. just install into the active project. selectedProjectsList = new Project[] { _solutionManager.DefaultProject }; } // resolve operations var actionsByProject = ResolveActionsByProjectForInstall( item.PackageIdentity, _activePackageManager, selectedProjectsList); // ask for license agreement var allActions = new List <Resolver.PackageAction>(); foreach (var actions in actionsByProject.Values) { allActions.AddRange(actions); } bool acceptLicense = ShowLicenseAgreement(allActions); if (!acceptLicense) { return(false); } var actionExecutor = new Resolver.ActionExecutor(); actionExecutor.Logger = this; actionExecutor.PackageOperationEventListener = this; actionExecutor.CatchProjectOperationException = true; // execute operations by project foreach (var actionsForOneProject in actionsByProject) { var projectManager = actionsForOneProject.Key; var project = ((VsProjectSystem)(projectManager.Project)).Project; try { RegisterPackageOperationEvents(_activePackageManager, projectManager); actionExecutor.Execute(actionsForOneProject.Value); } catch (Exception ex) { AddFailedProject(project, ex); } finally { UnregisterPackageOperationEvents(_activePackageManager, projectManager); } } return(true); } }
protected override bool ExecuteCore(PackageItem item) { IPackage package = item.PackageIdentity; // treat solution-level packages specially if (!PackageManager.IsProjectLevel(package)) { return(UninstallSolutionPackage(package)); } // display the Manage dialog to allow user to pick projects to install/uninstall IEnumerable <Project> selectedProjects = _userNotifierServices.ShowProjectSelectorWindow( Resources.Dialog_InstalledSolutionInstruction, item.PackageIdentity, // Selector function to return the initial checkbox state for a Project. // We check a project by default if it has the current package installed. project => PackageManager.GetProjectManager(project).IsInstalled(package), ignored => true); if (selectedProjects == null) { // user presses Cancel button on the Solution dialog return(false); } // bug #1181: Use HashSet<unique name> instead of HashSet<Project>. // in some rare cases, the project instance returned by GetProjects() may be different // than the ones in selectedProjectSet. var selectedProjectsSet = new HashSet <string>( selectedProjects.Select(p => p.GetUniqueName()), StringComparer.OrdinalIgnoreCase); // now determine if user has actually made any change to the checkboxes IList <Project> allProjects = _solutionManager.GetProjects().ToList(); bool hasInstallWork = allProjects.Any(p => selectedProjectsSet.Contains(p.GetUniqueName()) && !IsPackageInstalledInProject(p, package)); bool hasUninstallWork = allProjects.Any(p => !selectedProjectsSet.Contains(p.GetUniqueName()) && IsPackageInstalledInProject(p, package)); if (!hasInstallWork && !hasUninstallWork) { // nothing to do, so return return(false); } var uninstallRepositories = new List <IPackageRepository>(); var uninstallFrameworks = new List <FrameworkName>(); var uninstallProjects = new List <Project>(); bool?removeDepedencies = false; if (hasUninstallWork) { // Starting in 2.0, each project can have a different set of dependencies (because of different target frameworks). // To keep the UI simple, we aggregate all the dependencies from all uninstall projects // and ask if user wants to uninstall them all. foreach (Project project in allProjects) { // check if user wants to uninstall the package in this project if (!selectedProjectsSet.Contains(project.GetUniqueName())) { uninstallProjects.Add(project); uninstallRepositories.Add(PackageManager.GetProjectManager(project).LocalRepository); uninstallFrameworks.Add(project.GetTargetFrameworkName()); } } removeDepedencies = AskRemoveDependency(package, uninstallRepositories, uninstallFrameworks); if (removeDepedencies == null) { // user cancels the operation. return(false); } } ShowProgressWindow(); // now install the packages that are checked // Bug 1357: It's crucial that we perform all installs before uninstalls // to avoid the package file being deleted before an install. if (hasInstallWork) { bool successful = InstallPackageIntoProjects(package, allProjects, selectedProjectsSet); if (!successful) { return(false); } } // now uninstall the packages that are unchecked for (int i = 0; i < uninstallProjects.Count; ++i) { try { CheckDependentPackages(package, uninstallRepositories[i], uninstallFrameworks[i]); UninstallPackageFromProject(uninstallProjects[i], item, (bool)removeDepedencies); } catch (Exception ex) { AddFailedProject(uninstallProjects[i], ex); } } HideProgressWindow(); return(true); }
protected override bool ExecuteCore(PackageItem item) { _activePackageManager = GetActivePackageManager(); using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Install, item.Id, item.Version)) { IList <Project> selectedProjectsList; ShowProgressWindow(); bool isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity); if (isProjectLevel) { HideProgressWindow(); var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow( Resources.Dialog_OnlineSolutionInstruction, item.PackageIdentity, DetermineProjectCheckState, ignored => true); if (selectedProjects == null) { // user presses Cancel button on the Solution dialog return(false); } selectedProjectsList = selectedProjects.ToList(); if (selectedProjectsList.Count == 0) { return(false); } // save the checked state of projects so that we can restore them the next time SaveProjectCheckStates(selectedProjectsList); ShowProgressWindow(); } else { // solution package. just install into the active project. selectedProjectsList = new Project[] { _solutionManager.DefaultProject }; } // resolve operations var actions = ResolveActionsForInstall( item.PackageIdentity, _activePackageManager, selectedProjectsList); bool acceptLicense = ShowLicenseAgreement(actions); if (!acceptLicense) { return(false); } // execute operations try { RegisterPackageOperationEvents(_activePackageManager, null); var userOperationExecutor = new Resolver.ActionExecutor() { Logger = this, PackageOperationEventListener = this }; userOperationExecutor.Execute(actions); } finally { UnregisterPackageOperationEvents(_activePackageManager, null); } return(true); } }