当前位置: 首页>>代码示例>>C#>>正文


C# SourceRepository.Search方法代码示例

本文整理汇总了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;
        }
开发者ID:sistoimenov,项目名称:NuGet2,代码行数:34,代码来源:PowerShellPackage.cs

示例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;
        }
开发者ID:sistoimenov,项目名称:NuGet2,代码行数:41,代码来源:PowerShellPackage.cs


注:本文中的SourceRepository.Search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。