/// <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);
}
}