public Task <IPackageVersionSearchResult> GetPackageVersionsAsync(string id, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { return(Task.Run(() => { string packagePath = Path.Combine(_feed, id.ToLowerInvariant()); if (!_fileSystem.DirectoryExists(packagePath)) { return PackageVersionSearchResult.Failure; } try { List <string> versions = new List <string>(); foreach (string directory in _fileSystem.EnumerateDirectories(packagePath, "*", SearchOption.TopDirectoryOnly)) { string version = SemanticVersion.Parse(_fileSystem.GetDirectoryNameOnly(directory))?.ToString(); if (version != null) { versions.Add(version); } } return new PackageVersionSearchResult(versions, FeedKind.Local); } catch { return PackageVersionSearchResult.Failure; } }, cancellationToken)); }
public Task <IPackageNameSearchResult> GetPackageNamesAsync(string prefix, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { return(Task.Run(() => { try { NuGetFramework targetFramework = NuGetFramework.Parse(queryConfiguration.CompatibiltyTarget); List <IPackageInfo> infos = new List <IPackageInfo>(); foreach (string path in _fileSystem.EnumerateDirectories(_feed, $"*{prefix}*", SearchOption.TopDirectoryOnly).Where(x => x.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) > -1)) { if (cancellationToken.IsCancellationRequested) { return null; } if (infos.Count >= queryConfiguration.MaxResults) { break; } foreach (string verDir in _fileSystem.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly)) { if (cancellationToken.IsCancellationRequested) { return null; } if (verDir == null || SemanticVersion.Parse(verDir) == null) { continue; } string nuspec = _fileSystem.EnumerateFiles(verDir, "*.nuspec", SearchOption.TopDirectoryOnly).FirstOrDefault(); if (nuspec != null) { IPackageInfo info = NuSpecReader.Read(nuspec, FeedKind.Local); if (info != null && NuGetPackageMatcher.IsMatch(targetFramework, verDir, info, queryConfiguration, _fileSystem)) { infos.Add(info); if (infos.Count >= queryConfiguration.MaxResults) { break; } } } } } return new PackageNameSearchResult(infos.Select(x => x.Id).ToList(), FeedKind.Local); } catch { return PackageNameSearchResult.Failure; } }, cancellationToken)); }
public static bool IsMatch(string dir, IPackageInfo info, IPackageQueryConfiguration queryConfiguration, IFileSystem fileSystem) { if (!queryConfiguration.IncludePreRelease) { SemanticVersion ver = SemanticVersion.Parse(info.Version); if (!string.IsNullOrEmpty(ver?.PrereleaseVersion)) { return(false); } } return(true); }
public Task <IPackageInfo> GetPackageInfoAsync(string id, string version, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { return(Task.Run(() => { if (version != null) { string nuspec = Path.Combine(_feed, id, version, $"{id}.nuspec"); if (_fileSystem.FileExists(nuspec)) { return Task.FromResult(NuSpecReader.Read(nuspec, FeedKind.Local)); } else { return Task.FromResult <IPackageInfo>(null); } } else { string package = Path.Combine(_feed, id); string dir = _fileSystem.EnumerateDirectories(package).OrderByDescending(x => SemanticVersion.Parse(_fileSystem.GetDirectoryName(x))).FirstOrDefault(); if (dir == null) { return Task.FromResult <IPackageInfo>(null); } string nuspec = Path.Combine(dir, $"{id}.nuspec"); if (_fileSystem.FileExists(nuspec)) { return Task.FromResult(NuSpecReader.Read(nuspec, FeedKind.Local)); } else { return Task.FromResult <IPackageInfo>(null); } } }, cancellationToken)); }
private IPackageFeedSearchJob <Tuple <string, FeedKind> > SearchPackageNamesInternal(string prefix, string tfm, IPackageQueryConfiguration config) { List <Tuple <string, Task <IReadOnlyList <Tuple <string, FeedKind> > > > > searchTasks = new List <Tuple <string, Task <IReadOnlyList <Tuple <string, FeedKind> > > > >(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; foreach (string feedSource in _feedRegistry.ConfiguredFeeds) { IPackageFeed feed = _factorySelector.GetFeed(feedSource); if (feed != null) { searchTasks.Add(new Tuple <string, Task <IReadOnlyList <Tuple <string, FeedKind> > > >(feed.DisplayName, feed.GetPackageNamesAsync(prefix, config, cancellationToken).ContinueWith(TransformToPackageInfo))); } } return(new PackageFeedSearchJob <Tuple <string, FeedKind> >(searchTasks, cancellationTokenSource)); }
public async Task <IPackageVersionSearchResult> GetPackageVersionsAsync(string id, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { IReadOnlyList <string> results = new List <string>(); string frameworkQuery = !string.IsNullOrEmpty(queryConfiguration.CompatibiltyTarget) ? $"&supportedFramework={queryConfiguration.CompatibiltyTarget}" : ""; const string autoCompleteServiceTypeIdentifier = "SearchAutocompleteService"; List <string> serviceEndpoints = await DiscoverEndpointsAsync(_feed, autoCompleteServiceTypeIdentifier, cancellationToken).ConfigureAwait(false); Func <string, string> queryFunc = x => $"{x}?id={id}{frameworkQuery}&take={queryConfiguration.MaxResults}&prerelease={queryConfiguration.IncludePreRelease}"; JObject document = await ExecuteAutocompleteServiceQueryAsync(serviceEndpoints, queryFunc, cancellationToken).ConfigureAwait(false); try { results = GetDataFromNuGetV3CompatibleQueryResult(document); } catch { return(PackageVersionSearchResult.Failure); } return(new PackageVersionSearchResult(results, _kind)); }
public async Task <IPackageInfo> GetPackageInfoAsync(string packageId, string version, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { if (packageId == null) { return(null); } string packageDisplayMetadataUriTemplateIdentifier = "PackageDisplayMetadataUriTemplate/3.0.0-rc"; List <string> packageQuickInfoAddresses = await DiscoverEndpointsAsync(_feed, packageDisplayMetadataUriTemplateIdentifier, cancellationToken).ConfigureAwait(false); if (packageQuickInfoAddresses == null || packageQuickInfoAddresses.Count == 0) { return(null); } string packageQuickInfoAddress = packageQuickInfoAddresses[0]; string location = packageQuickInfoAddress.Replace("{id-lower}", packageId.ToLowerInvariant()); JObject responseJson; try { responseJson = await _webRequestFactory.GetJsonAsync(location, cancellationToken).ConfigureAwait(false) as JObject; } catch { return(null); } if (responseJson != null && responseJson.TryGetValue("items", out JToken topLevelItemsParseItem)) { JArray topLevelItemsArray = topLevelItemsParseItem as JArray; JObject packageResultsContainer = topLevelItemsArray?.FirstOrDefault() as JObject; JToken packageResultsItemsParseItem; if (packageResultsContainer != null && packageResultsContainer.TryGetValue("items", out packageResultsItemsParseItem)) { JArray packageResultsItems = packageResultsItemsParseItem as JArray; if (packageResultsItemsParseItem == null) { return(null); } string id, authors, description, licenseUrl, projectUrl, iconUrl; SemanticVersion bestSemanticVersion = null; PackageInfo packageInfo = null; foreach (JToken element in packageResultsItems) { JObject packageContainer = element as JObject; JToken catalogEntryParseItem; if (packageContainer != null && packageContainer.TryGetValue("catalogEntry", out catalogEntryParseItem)) { JObject catalogEntry = catalogEntryParseItem as JObject; if (catalogEntry != null) { string ver = catalogEntry["version"]?.ToString(); if (ver == null) { continue; } SemanticVersion currentVersion = SemanticVersion.Parse(ver); if (version != null) { if (string.Equals(version, catalogEntry["version"]?.ToString(), StringComparison.OrdinalIgnoreCase)) { id = catalogEntry["id"]?.ToString(); authors = catalogEntry["authors"]?.ToString(); description = catalogEntry["description"]?.ToString(); projectUrl = catalogEntry["projectUrl"]?.ToString(); licenseUrl = catalogEntry["licenseUrl"]?.ToString(); iconUrl = catalogEntry["iconUrl"]?.ToString(); packageInfo = new PackageInfo(id, version, authors, description, licenseUrl, projectUrl, iconUrl, _kind); return(packageInfo); } } else { if (currentVersion.CompareTo(bestSemanticVersion) > 0) { id = catalogEntry["id"]?.ToString(); authors = catalogEntry["authors"]?.ToString(); description = catalogEntry["description"]?.ToString(); projectUrl = catalogEntry["projectUrl"]?.ToString(); licenseUrl = catalogEntry["licenseUrl"]?.ToString(); iconUrl = catalogEntry["iconUrl"]?.ToString(); packageInfo = new PackageInfo(id, ver, authors, description, licenseUrl, projectUrl, iconUrl, _kind); bestSemanticVersion = currentVersion; } } } } } return(packageInfo); } } return(null); }
public Task <IPackageVersionSearchResult> GetPackageVersionsAsync(string prefix, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { return(Task.Run(() => { try { List <string> versions = new List <string>(); bool anyFound = false; foreach (string path in _fileSystem.EnumerateDirectories(_feed).Where(x => x.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) > -1)) { if (cancellationToken.IsCancellationRequested) { return PackageVersionSearchResult.Cancelled; } string nuspec = _fileSystem.EnumerateFiles(path, "*.nuspec", SearchOption.TopDirectoryOnly).FirstOrDefault(); if (nuspec != null) { anyFound = true; IPackageInfo info = NuSpecReader.Read(nuspec, FeedKind.Local); if (info != null && string.Equals(info.Id, prefix, StringComparison.OrdinalIgnoreCase)) { versions.Add(info.Version); } } } if (anyFound) { return new PackageVersionSearchResult(versions, FeedKind.Local); } return PackageVersionSearchResult.Failure; } catch { return PackageVersionSearchResult.Failure; } }, cancellationToken)); }
public async Task <IPackageInfo> GetPackageInfoAsync(string packageId, string version, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { if (packageId == null) { return(null); } var serviceEndpoint = $"{_feed}/Packages(Id='{packageId}',Version='{version}')"; Func <string, string> queryFunc = x => $"{x}"; XDocument document = await ExecuteAutocompleteServiceQueryAsync(serviceEndpoint, queryFunc, cancellationToken).ConfigureAwait(false); if (document != null) { var el = document.Root; var id = GetPropertyValue(document, el, "Id"); var title = GetPropertyValue(document, el, "Title"); var authors = GetPropertyValue(document, el, "Authors"); var summary = GetPropertyValue(document, el, "Summary"); var description = GetPropertyValue(document, el, "Description"); var projectUrl = GetPropertyValue(document, el, "ProjectUrl"); var licenseUrl = GetPropertyValue(document, el, "LicenseUrl"); var iconUrl = GetPropertyValue(document, el, "IconUrl"); var tags = GetPropertyValue(document, el, "Tags"); var packageInfo = new PackageInfo(id, version, title, authors, summary, description, licenseUrl, projectUrl, iconUrl, tags, _kind); return(packageInfo); } return(null); }
public async Task <IPackageNameSearchResult> GetPackageNamesAsync(string prefix, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(PackageNameSearchResult.Failure); } IReadOnlyList <string> results = new List <string>(); string frameworkQuery = !string.IsNullOrEmpty(queryConfiguration.CompatibiltyTarget) ? $"&targetFramework={queryConfiguration.CompatibiltyTarget}" : ""; var serviceEndpoint = $"{_feed}/Search()"; Func <string, string> queryFunc = x => $"{x}?searchTerm='{prefix}'{frameworkQuery}&includePrerelease={queryConfiguration.IncludePreRelease}&semVerLevel=2.0.0"; XDocument document = await ExecuteAutocompleteServiceQueryAsync(serviceEndpoint, queryFunc, cancellationToken).ConfigureAwait(false); if (document != null) { try { results = GetPackageNamesFromNuGetV2CompatibleQueryResult(document); return(new PackageNameSearchResult(results, _kind)); } catch { } } return(PackageNameSearchResult.Failure); }
public async Task <IPackageVersionSearchResult> GetPackageVersionsAsync(string id, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { IReadOnlyList <string> results = new List <string>(); var serviceEndpoint = $"{_feed}/FindPackagesById()"; Func <string, string> queryFunc = x => $"{x}?id='{id}'"; XDocument document = await ExecuteAutocompleteServiceQueryAsync(serviceEndpoint, queryFunc, cancellationToken).ConfigureAwait(false); try { results = GetPackageVersionsFromNuGetV2CompatibleQueryResult(id, document); } catch { return(PackageVersionSearchResult.Failure); } return(new PackageVersionSearchResult(results, _kind)); }
public static bool IsMatch(NuGetFramework targetFramework, string dir, IPackageInfo info, IPackageQueryConfiguration queryConfiguration, IFileSystem fileSystem) { if (!queryConfiguration.IncludePreRelease) { SemanticVersion ver = SemanticVersion.Parse(info.Version); if (!string.IsNullOrEmpty(ver?.PrereleaseVersion)) { return(false); } } string libPath = Path.Combine(dir, "lib"); string buildPath = Path.Combine(dir, "build"); return((fileSystem.DirectoryExists(libPath) && fileSystem.EnumerateDirectories(libPath, "*", SearchOption.TopDirectoryOnly).Any(x => DefaultCompatibilityProvider.Instance.IsCompatible(targetFramework, NuGetFramework.ParseFolder(fileSystem.GetDirectoryName(x))))) || (fileSystem.DirectoryExists(buildPath) && fileSystem.EnumerateDirectories(buildPath, "*", SearchOption.TopDirectoryOnly).Any(x => DefaultCompatibilityProvider.Instance.IsCompatible(targetFramework, NuGetFramework.ParseFolder(fileSystem.GetDirectoryName(x)))))); }