Пример #1
0
        /// <summary>
        /// Uninstalls a package
        /// </summary>
        /// <param name="package">package defined in the PackageSourceList</param>
        /// <param name="fastPackageReference"></param>
        /// <param name="request">An object passed in from the PackageManagement that contains functions that can be used to interact with its Provider</param>
        /// <param name="fastPackReftable"></param>
        internal static void UninstallNuGetPackage(PackageJson package, string fastPackageReference, PackageSourceListRequest request, Dictionary <string, SoftwareIdentity> fastPackReftable)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var destination = package.Destination;

            // PSL will call NuGet to uninstall the package when: 1) a user explictly specifies -providerName psl; or
            // 2) the psl.json file contains the defintion of Destination.
            // Otherwise, NuGet will handle the uninstall-package
            //
            string userSpecifiedProvider    = request.GetOptionValue("ProviderName") ?? request.GetOptionValue("Provider");
            string providerNameFromPipeline = request.GetProviderNameFromFastPathComplex(fastPackageReference);

            if ((string.IsNullOrWhiteSpace(userSpecifiedProvider) || !Constants.ProviderName.EqualsIgnoreCase(userSpecifiedProvider) &&
                 (string.IsNullOrWhiteSpace(providerNameFromPipeline) || !Constants.ProviderName.EqualsIgnoreCase(providerNameFromPipeline))) && string.IsNullOrWhiteSpace(destination))
            {
                request.Verbose(Resources.Messages.UninstallPackageNotSupported, Constants.ProviderName, package.Name, Constants.ProviderNames.NuGet);
                return;
            }

            request.Debug(Resources.Messages.DebugInfoCallMethod, Constants.ProviderName, "Calling UninstallNuGetPackage");

            var unInstallRequest = PackageSourceListRequest.ExtendRequest(
                new Dictionary <string, string[]>
            {
                { "Destination", new[] { destination } }
            }, null, request);

            var provider = PackageSourceListRequest.FindProvider(request, package.Type, request, true);

            if (provider != null)
            {
                request.Debug("{0}: Using the provider '{1} to uninstall the package '{2}'", Constants.ProviderName, provider.Name, package.Name);

                if (!fastPackReftable.ContainsKey(fastPackageReference))
                {
                    request.WriteError(ErrorCategory.InvalidData, fastPackageReference, Resources.Messages.FailedToGetPackageObject, Constants.ProviderName, fastPackageReference);
                    return;
                }

                var p = fastPackReftable[fastPackageReference];

                //calling NuGet for uninstall
                var installing = provider.UninstallPackage(p, unInstallRequest);

                foreach (var i in installing)
                {
                    request.YieldSoftwareIdentity(i.FastPackageReference, i.Name, i.Version, i.VersionScheme, i.Summary, i.Source, i.SearchKey, i.FullPath, i.PackageFilename);

                    if (request.IsCanceled)
                    {
                        installing.Cancel();
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Uninstalls a package
        /// </summary>
        /// <param name="package">package defined in the PackageSourceList</param>
        /// <param name="fastPackageReference"></param>
        /// <param name="request">An object passed in from the PackageManagement that contains functions that can be used to interact with its Provider</param>
        /// <param name="fastPackReftable"></param>
        internal static void UninstallPowershellArtifacts(PackageJson package, string fastPackageReference, PackageSourceListRequest request, Dictionary <string, SoftwareIdentity> fastPackReftable)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            // If a user explicitly specifies -providerName psl, e.g., uninstall-package -providername psl -name xjea,
            // PSL will call PowerShellGet to uninstall the package.
            // Otherwise, it is expected that PowerShellGet will handle the uninstall-package and PSL won't
            // participate in the uninstall operation, e.g., uninstall-package xjea
            string userSpecifiedProvider    = request.GetOptionValue("ProviderName") ?? request.GetOptionValue("Provider");
            string providerNameFromPipeline = request.GetProviderNameFromFastPathComplex(fastPackageReference);

            if ((string.IsNullOrWhiteSpace(userSpecifiedProvider) || !Constants.ProviderName.EqualsIgnoreCase(userSpecifiedProvider)) &&
                string.IsNullOrWhiteSpace(providerNameFromPipeline) || !Constants.ProviderName.EqualsIgnoreCase(providerNameFromPipeline))
            {
                request.Verbose(Resources.Messages.UninstallPackageNotSupported, Constants.ProviderName, package.Name, Constants.ProviderNames.PowerShellGet);
                return;
            }

            request.Debug(Resources.Messages.DebugInfoCallMethod, Constants.ProviderName, "Calling UninstallPowershellArtifacts");

            var provider = PackageSourceListRequest.FindProvider(request, package.Type, request, true);

            if (provider != null)
            {
                request.Debug("{0}: Using the provider '{1} to uninstall the package '{2}'", Constants.ProviderName, provider.Name, package.Name);

                if (!fastPackReftable.ContainsKey(fastPackageReference))
                {
                    request.WriteError(Internal.ErrorCategory.InvalidData, fastPackageReference, Resources.Messages.FailedToGetPackageObject, Constants.ProviderName, fastPackageReference);
                    return;
                }

                var p = fastPackReftable[fastPackageReference];

                //calling NuGet for uninstall
                var installing = provider.UninstallPackage(p, request);

                foreach (var i in installing)
                {
                    request.YieldSoftwareIdentity(i.FastPackageReference, i.Name, i.Version, i.VersionScheme, i.Summary, i.Source, i.SearchKey, i.FullPath, i.PackageFilename);

                    if (request.IsCanceled)
                    {
                        installing.Cancel();
                    }
                }
            }
        }