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 } }
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 } }
public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, PackageSourceListRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (!ValidatePackageManagementVersion(request)) { return; } request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, string.Format(CultureInfo.InvariantCulture, "FindPackage' - name='{0}', requiredVersion='{1}',minimumVersion='{2}', maximumVersion='{3}'", name, requiredVersion, minimumVersion, maximumVersion)); // no package name or the name with wildcard 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; } var packages = request.GetPackages(name); if (request.GetOptionValue("AllVersions").IsTrue()) { // if version is specified then name can not be empty or with wildcard. in this case the cmdlet has been errored out already. // here we just return all packages we can find if (request.FilterOnVersion(packages, requiredVersion, minimumVersion, maximumVersion, minInclusive: true, maxInclusive: true, latest: false).OrderBy(p => p.Name).Any(p => !request.YieldFromSwidtag(p, p.Name))) { return; } return; } //return the latest version if (packages.GroupBy(p => p.Name) .Select(each => each.OrderByDescending(pp => pp.Version).FirstOrDefault()).OrderBy(p => p.Name).Any(item => !request.YieldFromSwidtag(item, item.Name))) { return; } } else { // a user specifies name // asked for a specific version? if (!string.IsNullOrWhiteSpace(requiredVersion)) { request.YieldFromSwidtag(request.GetPackage(name, requiredVersion), name); return; } var allVersion = request.GetOptionValue("AllVersions").IsTrue(); // asked for a version range? if (!string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrEmpty(maximumVersion) || allVersion) { var packages = request.GetPackagesWithinVersionRange(name, minimumVersion, maximumVersion); if (allVersion) { if (packages.Any(p => !request.YieldFromSwidtag(p, name))) { return; } } else { if (request.YieldFromSwidtag(packages.FirstOrDefault(), name)) { return; } } return; } // just return by name request.YieldFromSwidtag(request.GetPackage(name), name); } }
public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, PackageSourceListRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (!ValidatePackageManagementVersion(request)) { return; } request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, string.Format(CultureInfo.InvariantCulture, "FindPackage' - name='{0}', requiredVersion='{1}',minimumVersion='{2}', maximumVersion='{3}'", name, requiredVersion, minimumVersion, maximumVersion)); // no package name or the name with wildcard 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; } var packages = request.GetPackages(name); if (request.GetOptionValue("AllVersions").IsTrue()) { // if version is specified then name can not be empty or with wildcard. in this case the cmdlet has been errored out already. // here we just return all packages we can find if (request.FilterOnVersion(packages, requiredVersion, minimumVersion, maximumVersion, minInclusive: true, maxInclusive: true, latest: false).OrderBy(p => p.Name).Any(p => !request.YieldFromSwidtag(p, p.Name))) { return; } return; } //return the latest version if (packages.GroupBy(p => p.Name) .Select(each => each.OrderByDescending(pp => pp.Version).FirstOrDefault()).OrderBy(p=>p.Name).Any( item =>!request.YieldFromSwidtag(item, item.Name))) { return; } } else { // a user specifies name // asked for a specific version? if (!string.IsNullOrWhiteSpace(requiredVersion)) { request.YieldFromSwidtag(request.GetPackage(name, requiredVersion), name); return; } var allVersion = request.GetOptionValue("AllVersions").IsTrue(); // asked for a version range? if (!string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrEmpty(maximumVersion) || allVersion) { var packages = request.GetPackagesWithinVersionRange(name, minimumVersion, maximumVersion); if (allVersion) { if (packages.Any(p => !request.YieldFromSwidtag(p, name))) { return; } } else { if (request.YieldFromSwidtag(packages.FirstOrDefault(), name)) { return; } } return; } // just return by name request.YieldFromSwidtag(request.GetPackage(name), name); } }