private IEnumerable <string> GetCandidateUrls(string packageId, SemanticVersion version, string baseUrl) { if (version != null) { // Ideally we want to try the version string first given to us by the user, but... string[] versions = version.GetComparableVersionStrings().ToArray(); foreach (string candidateVersion in versions) { yield return(GetPackageVersionUrl(packageId, candidateVersion, baseUrl)); } } else { yield return(String.Format(Constants.NuGetRegistrationUrlTemplatePackage, baseUrl, baseUrl.EndsWith("/") ? String.Empty : "/", packageId.ToLowerInvariant())); } }
public override bool Exists(string packageId, SemanticVersion version) { if (version != null) { // optimization: if we find the .nuspec file at "id.version"\"id.version".nuspec or // the .nupkg file at "id.version"\"id.version".nupkg, consider it exists bool hasPackageDirectory = version.GetComparableVersionStrings() .Select(v => packageId + "." + v) .Any(path => FileSystem.FileExists(Path.Combine(path, path + Constants.PackageExtension)) || FileSystem.FileExists(Path.Combine(path, path + Constants.ManifestExtension))); if (hasPackageDirectory) { return true; } } return FindPackage(packageId, version) != null; }
/// <summary> /// Find-Package /// </summary> /// <param name="packageId">package Id</param> /// <param name="version">package version</param> /// <param name="request"></param> /// <returns></returns> public IPackage FindPackage(string packageId, SemanticVersion version, NuGetRequest request) { if (string.IsNullOrWhiteSpace(packageId)) { return(null); } request.Debug(Messages.DebugInfoCallMethod3, "HttpClientPackageRepository", "FindPackage", packageId); var query = packageId.MakeFindPackageByIdQuery(_nugetFindPackageIdQueryFormat); var packages = NuGetClient.FindPackage(query, request); //Usually versions has a limited number, ToArray should be ok. var versions = version.GetComparableVersionStrings().ToArray(); //Will only enumerate packages once return(packages.FirstOrDefault(package => packageId.Equals(package.Id, StringComparison.OrdinalIgnoreCase) && versions.Contains(package.Version, StringComparer.OrdinalIgnoreCase))); }
/// <summary> /// Find-Package /// </summary> /// <param name="packageId">package Id</param> /// <param name="version">package version</param> /// <param name="request"></param> /// <returns></returns> public IPackage FindPackage(string packageId, SemanticVersion version, NuGetRequest request) { if (string.IsNullOrWhiteSpace(packageId)) { return null; } request.Debug(Messages.DebugInfoCallMethod3, "HttpClientPackageRepository", "FindPackage", packageId); var query = packageId.MakeFindPackageByIdQuery(_nugetFindPackageIdQueryFormat); var packages = NuGetClient.FindPackage(query, request); //Usually versions has a limited number, ToArray should be ok. var versions = version.GetComparableVersionStrings().ToArray(); //Will only enumerate packages once return packages.FirstOrDefault(package => packageId.Equals(package.Id, StringComparison.OrdinalIgnoreCase) && versions.Contains(package.Version,StringComparer.OrdinalIgnoreCase)); }
public IPackage FindPackage(string packageId, SemanticVersion version) { IQueryable<DataServicePackage> query = Context.CreateQuery<DataServicePackage>(PackageServiceEntitySetName).AsQueryable(); foreach (string versionString in version.GetComparableVersionStrings()) { try { var packages = query.Where(p => p.Id == packageId && p.Version == versionString).ToArray(); Debug.Assert(packages == null || packages.Length <= 1); if (packages.Length != 0) { return packages[0]; } } catch (DataServiceQueryException) { // DataServiceQuery exception will occur when the (id, version) // combination doesn't exist. } } return null; }
public bool Exists(string packageId, SemanticVersion version) { IQueryable<DataServicePackage> query = Context.CreateQuery<DataServicePackage>(PackageServiceEntitySetName).AsQueryable(); foreach (string versionString in version.GetComparableVersionStrings()) { try { var packages = query.Where(p => p.Id == packageId && p.Version == versionString) .Select(p => p.Id) // since we only want to check for existence, no need to get all attributes .ToArray(); if (packages.Length == 1) { return true; } } catch (DataServiceQueryException) { // DataServiceQuery exception will occur when the (id, version) // combination doesn't exist. } } return false; }