示例#1
0
        public void DownloadPackage(string fastPath, string location, PackageSourceListRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (!ValidatePackageManagementVersion(request))
            {
                return;
            }

            request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, string.Format(CultureInfo.InvariantCulture, "DownloadPackage' - fastReference='{0}', location='{1}'", fastPath, location));

            var package = request.GetPackageByFastPath(fastPath);

            if (package == null)
            {
                request.WriteError(ErrorCategory.InvalidData, fastPath, Resources.Messages.FailedToGetPackageObject, Constants.ProviderName, fastPath);
                return;
            }

            switch (package.Type.ToLowerInvariant())
            {
            case Constants.MediaType.MsiPackage:
                //No-op as the msi provider does not support save-package
                break;

            case Constants.MediaType.MsuPackage:
                //No-op as the msu provider does not support save-package
                break;

            case Constants.MediaType.AppxPackage:
                //TODO for future whenever needed to support appx packages
                break;

            case Constants.MediaType.NuGetPackage:
                NupkgInstaller.DownloadNuGetPackage(fastPath, location, request);
                break;

            case Constants.MediaType.ZipPackage:
                //TODO
                ZipPackageInstaller.DownloadZipPackage(fastPath, location, request);
                break;

            case Constants.MediaType.ExePackage:
                //TODO
                ExePackageInstaller.DownloadExePackage(fastPath, location, request);
                break;

            case Constants.MediaType.PsArtifacts:
                //TODO
                break;

            default:
                request.WriteError(ErrorCategory.InvalidData, fastPath, Resources.Messages.UnknownMediaType, package.Name, package.Source, package.Type);
                return;
            }
        }
示例#2
0
        /// <summary>
        /// Uninstalls a package
        /// </summary>
        /// <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>
        public void UninstallPackage(string fastPackageReference, PackageSourceListRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (!ValidatePackageManagementVersion(request))
            {
                return;
            }

            request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, fastPackageReference);

            var package = request.GetFastReferenceComplex(fastPackageReference);

            if (package == null)
            {
                request.WriteError(ErrorCategory.InvalidData, fastPackageReference, Resources.Messages.FailedToGetPackageObject, Constants.ProviderName, fastPackageReference);
                return;
            }

            switch (package.Type.ToLowerInvariant())
            {
            case Constants.MediaType.AppxPackage:
                //TODO for the future
                break;

            case Constants.MediaType.ExePackage:
                ExePackageInstaller.UninstallExePackage(fastPackageReference, request);
                break;

            case Constants.MediaType.MsiPackage:

                UnInstallMsiPackage(request, fastPackageReference, package);
                break;

            case Constants.MediaType.ZipPackage:
                ZipPackageInstaller.UnInstallZipPackage(request, fastPackageReference);
                break;

            case Constants.MediaType.NuGetPackage:
                NupkgInstaller.UninstallNuGetPackage(package, fastPackageReference, request, _fastPackReftable);
                break;

            case Constants.MediaType.PsArtifacts:
                PowerShellArtifactInstaller.UninstallPowershellArtifacts(package, fastPackageReference, request, _fastPackReftable);
                break;

            default:
                request.WriteError(ErrorCategory.InvalidData, fastPackageReference, Resources.Messages.UnknownMediaType, package.Name, package.Source, package.Type);
                break;
            }
        }
示例#3
0
        internal static void InstallProviderFromInstaller(PackageJson package, string fastPath, PackageSourceListRequest request)
        {
            request.Debug(Resources.Messages.DebugInfoCallMethod, Constants.ProviderName, string.Format(CultureInfo.InvariantCulture, "InstallProviderFromInstaller' - name='{0}'", package.Name));

            //install any dependency packages
            InstallDependencies(package, request);

            switch (package.Type.ToLowerInvariant())
            {
            case Constants.MediaType.MsiPackage:
            case Constants.MediaType.MsuPackage:
#if CORECLR
                request.WriteError(ErrorCategory.InvalidOperation, package.Type, Resources.Messages.UnsupportedPowerShellEnvironment, Constants.ProviderName, "Install-Package", package.Type);
#else
                InstallPackageFile(package, fastPath, request);
#endif
                break;

            case Constants.MediaType.AppxPackage:
                //TODO for future whenever needed to support appx packages
                break;

            case Constants.MediaType.NuGetPackage:
                NupkgInstaller.InstallNuGetPackage(package, fastPath, request);
                break;

            case Constants.MediaType.ZipPackage:
                ZipPackageInstaller.InstallZipPackage(package, fastPath, request);
                break;

            case Constants.MediaType.ExePackage:
#if CORECLR
                request.WriteError(ErrorCategory.InvalidOperation, package.Type, Resources.Messages.UnsupportedPowerShellEnvironment, Constants.ProviderName, "Install-Package", package.Type);
#else
                ExePackageInstaller.InstallExePackage(package, fastPath, request);
#endif
                break;

            case Constants.MediaType.PsArtifacts:
                PowerShellArtifactInstaller.InstallPowershellArtifacts(package, fastPath, request);
                break;

            default:
                request.WriteError(ErrorCategory.InvalidData, fastPath, Resources.Messages.UnknownMediaType, package.Name, package.Source, package.Type);
                break;
            }
            return;
        }
示例#4
0
        public void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, PackageSourceListRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (!ValidatePackageManagementVersion(request))
            {
                return;
            }

            request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, string.Format(CultureInfo.InvariantCulture, "GetInstalledPackages' - name='{0}', requiredVersion='{1}',minimumVersion='{2}', maximumVersion='{3}'", name, requiredVersion, minimumVersion, maximumVersion));

            IEnumerable <PackageJson> packagesDefinedInJsonSpec;

            if (string.IsNullOrWhiteSpace(name) || WildcardPattern.ContainsWildcardCharacters(name))
            {
                // In the case of the package name is null or contains wildcards, error out if a user puts version info
                if (!string.IsNullOrWhiteSpace(requiredVersion) || !string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrWhiteSpace(maximumVersion))
                {
                    request.Warning(Resources.Messages.WildCardCharsAreNotSupported, name);
                    return;
                }
                packagesDefinedInJsonSpec = request.GetPackages(name).ToArray();
            }
            else
            {
                //return all installed
                packagesDefinedInJsonSpec = request.GetPackages(name, requiredVersion, minimumVersion, maximumVersion).ToArray();
            }
            _fastPackReftable.Clear();

            if (!packagesDefinedInJsonSpec.Any())
            {
                request.Verbose(Resources.Messages.NoPackageFound, Constants.ProviderName);
                return;
            }

            foreach (var package in packagesDefinedInJsonSpec)
            {
                switch (package.Type.ToLowerInvariant())
                {
                case Constants.MediaType.AppxPackage:
                    //TODO for future
                    break;

                case Constants.MediaType.PsArtifacts:
                    PowerShellArtifactInstaller.GeInstalledPowershellArtifacts(package, requiredVersion, minimumVersion, maximumVersion, _fastPackReftable, request);
                    break;

                case Constants.MediaType.ExePackage:
                    //program provider can handle get-package git for git.exe
                    ExePackageInstaller.GetInstalledExePackages(package, requiredVersion, minimumVersion, minimumVersion, request);
                    break;

                case Constants.MediaType.MsiPackage:
                    //msi provider can handle get-package node.js for node.js.msi
                    GetMsiInstalledPackage(name, package, requiredVersion, minimumVersion, maximumVersion, request);
                    break;

                case Constants.MediaType.ZipPackage:
                    ZipPackageInstaller.GetInstalledZipPackage(package, request);
                    break;

                case Constants.MediaType.NuGetPackage:
                    NupkgInstaller.GeInstalledNuGetPackages(package, requiredVersion, minimumVersion, maximumVersion, _fastPackReftable, request);
                    break;
                } //switch
            }
        }