Пример #1
0
        protected bool?AskRemoveDependency(
            IPackage package,
            IList <IPackageRepository> localRepositories,
            IList <FrameworkName> targetFrameworks)
        {
            Debug.Assert(localRepositories.Count == targetFrameworks.Count);

            var allOperations = new List <PackageOperation>();

            for (int i = 0; i < localRepositories.Count; i++)
            {
                var uninstallWalker = new UninstallWalker(
                    localRepositories[i],
                    new DependentsWalker(localRepositories[i], targetFrameworks[i]),
                    targetFrameworks[i],
                    logger: NullLogger.Instance,
                    removeDependencies: true,
                    forceRemove: false)
                {
                    ThrowOnConflicts = false
                };
                var operations = uninstallWalker.ResolveOperations(package);
                allOperations.AddRange(operations);
            }

            allOperations = allOperations.Reduce().ToList();

            var uninstallPackageNames = (from o in allOperations
                                         where o.Action == PackageAction.Uninstall && !PackageEqualityComparer.IdAndVersion.Equals(o.Package, package)
                                         select o.Package)
                                        .Distinct(PackageEqualityComparer.IdAndVersion)
                                        .Select(p => p.ToString())
                                        .ToList();

            bool?removeDependencies = false;

            if (uninstallPackageNames.Count > 0)
            {
                // show each dependency package on one line
                String packageNames = String.Join(Environment.NewLine, uninstallPackageNames);
                String message      = String.Format(CultureInfo.CurrentCulture, Resources.Dialog_RemoveDependencyMessage, package)
                                      + Environment.NewLine
                                      + Environment.NewLine
                                      + packageNames;

                removeDependencies = _userNotifierServices.ShowRemoveDependenciesWindow(message);
            }

            return(removeDependencies);
        }
Пример #2
0
        protected bool?AskRemoveDependencyAndCheckUninstallPSScript(
            IPackage package,
            IList <IPackageRepository> localRepositories,
            IList <FrameworkName> targetFrameworks)
        {
            Debug.Assert(localRepositories.Count == targetFrameworks.Count);

            var allOperations = new List <PackageOperation>();

            for (int i = 0; i < localRepositories.Count; i++)
            {
                var uninstallWalker = new UninstallWalker(
                    localRepositories[i],
                    new DependentsWalker(localRepositories[i], targetFrameworks[i]),
                    targetFrameworks[i],
                    logger: NullLogger.Instance,
                    removeDependencies: true,
                    forceRemove: false)
                {
                    ThrowOnConflicts = false
                };
                var operations = uninstallWalker.ResolveOperations(package);
                allOperations.AddRange(operations);
            }

            allOperations = allOperations.Reduce().ToList();

            var uninstallPackageNames = (from o in allOperations
                                         where o.Action == PackageAction.Uninstall && !PackageEqualityComparer.IdAndVersion.Equals(o.Package, package)
                                         select o.Package)
                                        .Distinct(PackageEqualityComparer.IdAndVersion)
                                        .Select(p => p.ToString())
                                        .ToList();

            bool?removeDependencies = false;

            if (uninstallPackageNames.Count > 0)
            {
                // show each dependency package on one line
                String packageNames = String.Join(Environment.NewLine, uninstallPackageNames);
                String message      = String.Format(CultureInfo.CurrentCulture, Resources.Dialog_RemoveDependencyMessage, package)
                                      + Environment.NewLine
                                      + Environment.NewLine
                                      + packageNames;

                removeDependencies = _userNotifierServices.ShowRemoveDependenciesWindow(message);
            }

            if (removeDependencies == null)
            {
                return(removeDependencies);
            }

            bool hasScriptPackages;

            if (removeDependencies == true)
            {
                // if user wants to remove dependencies, we need to check all of them for PS scripts
                var scriptPackages = from o in allOperations
                                     where o.Package.HasPowerShellScript()
                                     select o.Package;
                hasScriptPackages = scriptPackages.Any();
            }
            else
            {
                // otherwise, just check the to-be-uninstalled package
                hasScriptPackages = package.HasPowerShellScript(new string[] { PowerShellScripts.Uninstall });
            }

            if (hasScriptPackages)
            {
                if (!RegistryHelper.CheckIfPowerShell2Installed())
                {
                    throw new InvalidOperationException(Resources.Dialog_PackageHasPSScript);
                }
            }

            return(removeDependencies);
        }