private static PackageQueryResult Query(ContextName context, string nuGetSite, IList <string> packageIds, PackageStability stability, PackageQueryOrder queryOrder, int?page) { if (context == null) { throw new ArgumentNullException("context"); } if (nuGetSite == null) { throw new ArgumentNullException("nuGetSite"); } var service = new FeedContext_x0060_1(new Uri(nuGetSite)); IQueryable <V2FeedPackage> query = service.Packages .IncludeTotalCount() .Where(p => p.IsAbsoluteLatestVersion && p.IsLatestVersion ); if (packageIds != null) { if (packageIds.Count == 0) { throw new ArgumentOutOfRangeException("packageIds"); } // The feed doesn't support contains. Because of this, we're // building the ||'s of all ID's here dynamically. var idProperty = typeof(V2FeedPackage).GetProperty("Id"); var parameterExpression = Expression.Parameter(typeof(V2FeedPackage), "p"); Expression predicate = null; foreach (string id in packageIds) { var thisPredicate = Expression.Equal( Expression.Property(parameterExpression, idProperty), Expression.Constant(id) ); predicate = predicate == null ? thisPredicate : Expression.OrElse(predicate, thisPredicate); } query = query.Where(Expression.Lambda <Func <V2FeedPackage, bool> >( predicate, new[] { parameterExpression } )); } else { string prefix = context.Name + ".Package."; query = query.Where(p => p.Id.StartsWith(prefix) || p.Id.StartsWith("NetIde.Package.") ); } if (stability == PackageStability.StableOnly) { query = query.Where(p => !p.IsPrerelease); } switch (queryOrder) { case PackageQueryOrder.MostDownloads: query = query.OrderByDescending(p => p.DownloadCount); break; case PackageQueryOrder.PublishedDate: query = query.OrderByDescending(p => p.Published); break; case PackageQueryOrder.NameAscending: query = query.OrderBy(p => p.Title); break; case PackageQueryOrder.NameDescending: query = query.OrderByDescending(p => p.Title); break; } if (page.HasValue) { if (page.Value > 0) { query = query.Skip(page.Value * PageCount); } query = query.Take(PageCount); } var response = (QueryOperationResponse <V2FeedPackage>)((DataServiceQuery <V2FeedPackage>)query).Execute(); using (var contextKey = PackageRegistry.OpenRegistryRoot(false, context)) { return(new PackageQueryResult( response.TotalCount, page.GetValueOrDefault(0), (int)((response.TotalCount / PageCount) + 1), response.Select(p => Deserialize(p, context, contextKey, nuGetSite)).ToArray() )); } }
public static PackageQueryResult Query(ContextName context, string nuGetSite, PackageStability stability, PackageQueryOrder queryOrder, int page) { return Query(context, nuGetSite, null, stability, queryOrder, page); }
public static PackageQueryResult Query(ContextName context, string nuGetSite, PackageStability stability, PackageQueryOrder queryOrder, int page) { return(Query(context, nuGetSite, null, stability, queryOrder, page)); }
private static PackageQueryResult Query(ContextName context, string nuGetSite, IList<string> packageIds, PackageStability stability, PackageQueryOrder queryOrder, int? page) { if (context == null) throw new ArgumentNullException("context"); if (nuGetSite == null) throw new ArgumentNullException("nuGetSite"); var service = new FeedContext_x0060_1(new Uri(nuGetSite)); IQueryable<V2FeedPackage> query = service.Packages .IncludeTotalCount() .Where(p => p.IsAbsoluteLatestVersion && p.IsLatestVersion ); if (packageIds != null) { if (packageIds.Count == 0) throw new ArgumentOutOfRangeException("packageIds"); // The feed doesn't support contains. Because of this, we're // building the ||'s of all ID's here dynamically. var idProperty = typeof(V2FeedPackage).GetProperty("Id"); var parameterExpression = Expression.Parameter(typeof(V2FeedPackage), "p"); Expression predicate = null; foreach (string id in packageIds) { var thisPredicate = Expression.Equal( Expression.Property(parameterExpression, idProperty), Expression.Constant(id) ); predicate = predicate == null ? thisPredicate : Expression.OrElse(predicate, thisPredicate); } query = query.Where(Expression.Lambda<Func<V2FeedPackage, bool>>( predicate, new[] { parameterExpression } )); } else { string prefix = context.Name + ".Package."; query = query.Where(p => p.Id.StartsWith(prefix) || p.Id.StartsWith("NetIde.Package.") ); } if (stability == PackageStability.StableOnly) query = query.Where(p => !p.IsPrerelease); switch (queryOrder) { case PackageQueryOrder.MostDownloads: query = query.OrderByDescending(p => p.DownloadCount); break; case PackageQueryOrder.PublishedDate: query = query.OrderByDescending(p => p.Published); break; case PackageQueryOrder.NameAscending: query = query.OrderBy(p => p.Title); break; case PackageQueryOrder.NameDescending: query = query.OrderByDescending(p => p.Title); break; } if (page.HasValue) { if (page.Value > 0) query = query.Skip(page.Value * PageCount); query = query.Take(PageCount); } var response = (QueryOperationResponse<V2FeedPackage>)((DataServiceQuery<V2FeedPackage>)query).Execute(); using (var contextKey = PackageRegistry.OpenRegistryRoot(false, context)) { return new PackageQueryResult( response.TotalCount, page.GetValueOrDefault(0), (int)((response.TotalCount / PageCount) + 1), response.Select(p => Deserialize(p, context, contextKey, nuGetSite)).ToArray() ); } }