/// <summary> /// </summary> /// <param name="name"></param> /// <param name="requiredVersion"></param> /// <param name="minimumVersion"></param> /// <param name="maximumVersion"></param> /// <param name="id"></param> /// <param name="request"></param> /// <returns></returns> public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, NuGetRequest request) { // Nice-to-have put a debug message in that tells what's going on. request.Debug("Calling '{0}::FindPackage' '{1}','{2}','{3}','{4}','{5}'", PackageProviderName, name, requiredVersion, minimumVersion, maximumVersion, id); requiredVersion = requiredVersion.FixVersion(); if (!string.IsNullOrEmpty(requiredVersion)) { if (request.FindByCanonicalId && requiredVersion.IndexOfAny("()[],".ToCharArray()) == -1) { // when resolving packages via a canonical id, treat a lone version (ie 1.0 -> 1.0 <= x) string as a nuget version range: minimumVersion = requiredVersion; maximumVersion = null; requiredVersion = null; } else { minimumVersion = null; maximumVersion = null; } } else { minimumVersion = minimumVersion.FixVersion(); maximumVersion = maximumVersion.FixVersion(); } if (!IsValidVersionRange(minimumVersion, maximumVersion)) { request.Error(ErrorCategory.InvalidArgument, minimumVersion + maximumVersion, Constants.Messages.InvalidVersionRange, minimumVersion, maximumVersion); return; } // get the package by ID first. // if there are any packages, yield and return if (!string.IsNullOrWhiteSpace(name)) { if (request.YieldPackages(request.GetPackageById(name, requiredVersion, minimumVersion, maximumVersion), name) || request.FoundPackageById) { // if we actaully found some by that id, but didn't make it past the filter, we're done. return; } } // have we been cancelled? if (request.IsCanceled) { return; } // Try searching for matches and returning those. request.YieldPackages(request.SearchForPackages(name, requiredVersion, minimumVersion, maximumVersion), name); request.Debug("Finished '{0}::FindPackage' '{1}','{2}','{3}','{4}','{5}'", PackageProviderName, name, requiredVersion, minimumVersion, maximumVersion, id); }
public bool SearchPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, bool minInclusive, bool maxInclusive, int id, NuGetRequest request) { try { // If there are any packages, yield and return if (request.YieldPackages(request.GetPackageById(name, request, requiredVersion, minimumVersion, maximumVersion, minInclusive, maxInclusive), name)) { return(true); } // Check if the name contains wildcards. If not, return. This matches the behavior as "Get-module xje" if (!String.IsNullOrWhiteSpace(name) && !WildcardPattern.ContainsWildcardCharacters(name)) { return(false); } // 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(Constants.Messages.MissingRequiredParameter, "name"); return(false); } // Have we been cancelled? if (request.IsCanceled) { request.Debug(Resources.Messages.RequestCanceled, PackageProviderName, "FindPackage"); return(false); } // A user does not provide the package full Name at all Or used wildcard in the name. Let's try searching the entire repository for matches. if (request.YieldPackages(request.SearchForPackages(name), name)) { return(true); } } catch (Exception ex) { ex.Dump(request); } return(false); }
/// <summary> /// Searches package sources given name and version information /// /// Package information must be returned using <c>request.YieldPackage(...)</c> function. /// </summary> /// <param name="name">a name or partial name of the package(s) requested</param> /// <param name="requiredVersion">A specific version of the package. Null or empty if the user did not specify</param> /// <param name="minimumVersion">A minimum version of the package. Null or empty if the user did not specify</param> /// <param name="maximumVersion">A maximum version of the package. Null or empty if the user did not specify</param> /// <param name="id">if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>, the core is calling this multiple times to do a batch search request. The operation can be delayed until <c>CompleteFind(...)</c> is called</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 FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, NuGetRequest request) { if (request == null) { throw new ArgumentNullException("request"); } // true if we want to include the max and min version bool minInclusive = true; bool maxInclusive = true; // If finding by canonical id, then the version follows dependency version requirement if (request.GetOptionValue("FindByCanonicalId").IsTrue()) { // Use the dependency version if no min and max is supplied if (String.IsNullOrWhiteSpace(maximumVersion) && String.IsNullOrWhiteSpace(minimumVersion)) { DependencyVersion depVers = DependencyVersion.ParseDependencyVersion(requiredVersion); maximumVersion = depVers.MaxVersion.ToStringSafe(); minimumVersion = depVers.MinVersion.ToStringSafe(); minInclusive = depVers.IsMinInclusive; maxInclusive = depVers.IsMaxInclusive; // set required version if we have both min max as the same value. if (depVers.MaxVersion != null && depVers.MinVersion != null && depVers.MaxVersion == depVers.MinVersion && minInclusive && maxInclusive) { requiredVersion = maximumVersion; } else { requiredVersion = null; } } } request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, string.Format(CultureInfo.InvariantCulture, "FindPackage' - name='{0}', requiredVersion='{1}',minimumVersion='{2}', maximumVersion='{3}'", name, requiredVersion, minimumVersion, maximumVersion)); NormalizeVersion(request, ref requiredVersion, ref minimumVersion, ref maximumVersion); try { // If there are any packages, yield and return if (request.YieldPackages(request.GetPackageById(name, request, requiredVersion, minimumVersion, maximumVersion, minInclusive, maxInclusive), name)) { return; } // Check if the name contains wildcards. If not, return. This matches the behavior as "Get-module xje" if (!String.IsNullOrWhiteSpace(name) && !WildcardPattern.ContainsWildcardCharacters(name)) { return; } // 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(Constants.Messages.MissingRequiredParameter, "name"); return; } // Have we been cancelled? if (request.IsCanceled) { request.Debug(Resources.Messages.RequestCanceled, PackageProviderName, "FindPackage"); return; } // A user does not provide the package full Name at all Or used wildcard in the name. Let's try searching the entire repository for matches. request.YieldPackages(request.SearchForPackages(name), name); } catch (Exception ex) { ex.Dump(request); } }