/// <summary> /// Creates a new <see cref="ServiceClient"/> from the specified description and repository /// </summary> /// <param name="service">A <see cref="ServiceDescription"/> object that describes the target service</param> /// <param name="repository">The <see cref="NuGetRepository"/> object that contains the service</param> public ServiceClient(ServiceDescription service, NuGetRepository repository) { Guard.NotNull(service, "service"); Guard.NotNull(repository, "repository"); Service = service; Repository = repository; }
public static async Task <DataServicePackageRepository> CreateV2FeedClient(this NuGetRepository self, CancellationToken cancellationToken) { // Get the V2Feed service definition var v2FeedClient = await self.CreateClient("v2feed"); cancellationToken.ThrowIfCancellationRequested(); // Use the URL to create a DataServicePackageRepository using an adaptor IHttpClient return(new DataServicePackageRepository(v2FeedClient.Service.RootUrl)); }
private static async Task Test1_ApiV3ServiceDisco(NuGetRepository repo) { var desc = await repo.GetRepositoryDescription(); Console.WriteLine("Version: " + desc.Version.ToString()); Console.WriteLine("Mirrors: " + String.Join(", ", desc.Mirrors.Select(u => u.ToString()))); Console.WriteLine("Services:"); foreach (var service in desc.Services) { Console.WriteLine("* " + service.Name + " " + service.RootUrl.ToString()); } }
private static async Task Test2_ApiV2FeedAdaptor(NuGetRepository repo) { // Get the v2 client var packageRepo = await repo.CreateV2FeedClient(); // List the top 10 packages var packages = packageRepo.Search("", Enumerable.Empty<string>(), allowPrereleaseVersions: true).Take(10).ToList(); Console.WriteLine("Top 10 Packages on {0}:", repo.Url); foreach (var package in packages) { Console.WriteLine("* " + package.Id + " " + package.Version.ToString()); } }
private static async Task AsyncMain(string[] args) { string url = "https://api.nuget.org"; if (args.Length > 0) { url = args[0]; } // Setting up the client var repo = new NuGetRepository(new Uri(url), new ColoredConsoleTraceSink()); // 1. Connecting and getting the repository description Console.WriteLine("*** TEST ONE ***"); await Test1_ApiV3ServiceDisco(repo); // 2. Using the V2 Feed through the V3 Client Console.WriteLine("*** TEST TWO ***"); await Test2_ApiV2FeedAdaptor(repo); }
public static Task <DataServicePackageRepository> CreateV2FeedClient(this NuGetRepository self) { return(CreateV2FeedClient(self, CancellationToken.None)); }