本文整理汇总了C#中SourceRepository.Search方法的典型用法代码示例。如果您正苦于以下问题:C# SourceRepository.Search方法的具体用法?C# SourceRepository.Search怎么用?C# SourceRepository.Search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceRepository
的用法示例。
在下文中一共展示了SourceRepository.Search方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPackageVersions
/// <summary>
/// Get all versions of packages that match the search term of packageId.
/// </summary>
/// <param name="repo"></param>
/// <param name="packageId"></param>
/// <param name="names"></param>
/// <param name="allowPrerelease"></param>
/// <param name="skip"></param>
/// <param name="take"></param>
/// <returns></returns>
public static IEnumerable<JObject> GetPackageVersions(SourceRepository repo, string packageId, IEnumerable<FrameworkName> names, bool allowPrerelease, int skip, int take)
{
// Specify the search filter for prerelease and target framework
SearchFilter filter = new SearchFilter();
filter.IncludePrerelease = allowPrerelease;
filter.SupportedFrameworks = names.Select(n => VersionUtility.GetShortFrameworkName(n));
IEnumerable<JObject> searchResults = Enumerable.Empty<JObject>();
try
{
Task<IEnumerable<JObject>> task = repo.Search(packageId, filter, skip, take, cancellationToken: CancellationToken.None);
searchResults = task.Result;
}
catch (Exception)
{
if (searchResults.IsEmpty())
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
NuGetResources.UnknownPackage, packageId));
}
}
return searchResults;
}
示例2: GetJObjectForPackageId
/// <summary>
/// Get JObject of a specific package with packageId
/// </summary>
/// <param name="repo"></param>
/// <param name="packageId"></param>
/// <param name="names"></param>
/// <param name="allowPrerelease"></param>
/// <param name="skip"></param>
/// <param name="take"></param>
/// <returns></returns>
public static JObject GetJObjectForPackageId(SourceRepository repo, string packageId, IEnumerable<FrameworkName> names, bool allowPrerelease, int skip, int take)
{
if (packageId == null)
{
throw new ArgumentNullException();
}
// Specify the search filter for prerelease and target framework
SearchFilter filter = new SearchFilter();
filter.IncludePrerelease = allowPrerelease;
filter.SupportedFrameworks = names.Select(n => VersionUtility.GetShortFrameworkName(n));
JObject package = null;
try
{
Task<IEnumerable<JObject>> task = repo.Search(packageId, filter, skip, take, cancellationToken: CancellationToken.None);
IEnumerable<JObject> packages = task.Result;
// Get the package with the specific Id.
package = packages.Where(p => string.Equals(p.Value<string>(Properties.PackageId), packageId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
}
catch (Exception)
{
if (package == null)
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
NuGetResources.UnknownPackage, packageId));
}
}
return package;
}