public async Task ProjectDependenciesTestAsync() { var configuration = "Debug"; var objDirectoryName = "obj"; var packageReferences = new PackageReference[] { new ("StackExchange.Redis", "2.2.4"), }; var project = new Project(packageReferences, LibraryReferences: null, GenerateSwaggerDoc: false, AddSwaggerUI: false); var bootstrapper = new BasicBootstrapper("TestProject", addSwagger: false, addSwaggerUI: false); var tempPath = Path.GetTempPath(); var nuGetClient = new NuGetClient(project, configuration, tempPath); var packageAssemblies = await nuGetClient .RestoreProjectDependenciesAsync() .ConfigureAwait(false); var packagePath = Path.Combine(tempPath, objDirectoryName, configuration); var packageAssembliesFileName = Path.Combine(packagePath, "packageAssemblies.json"); Assert.True(File.Exists(packageAssembliesFileName), $"{packageAssembliesFileName} not found"); var files = packageAssemblies.SelectMany(pa => pa.PackageFiles); foreach (var file in files) { var filePath = Path.Combine(tempPath, file); Assert.True(File.Exists(filePath), $"{filePath} not found"); } }
public App() : base("Nugs") { _client = new NuGetClient("https://api.nuget.org/v3/index.json"); _items = null; Width = Dim.Fill(); Height = Dim.Fill(); _search = new Label("Search: ") { X = 3, Y = 1 }; _searchText = new TextField("") { X = Pos.Right(_search), Y = Pos.Top(_search), Width = 40, }; _searchText.Changed += SearchText_Changed; _searchList = new ListView(new string[0]) { X = Pos.Left(_search), Y = Pos.Top(_search) + 3, Width = Dim.Fill(), }; Add(_search, _searchText, _searchList); FocusLast(); }
public void NuGetClient_Packages_PackageMetadata() { NuGetClient ngc = new NuGetClient(); IEnumerable <IPackageSearchMetadata> package_metadata = null; package_metadata = ngc.GetPackageMetadataAsync ( "Xamarin.AndroidX.Core" ).Result; #if MSTEST Assert.IsNotNull(package_metadata); #elif NUNIT Assert.NotNull(package_metadata); #elif XUNIT Assert.NotNull(package_metadata); #endif Console.WriteLine($"Package metadata..."); foreach (IPackageSearchMetadata pm in package_metadata) { Console.WriteLine($"----------------------------------------------------------"); Console.WriteLine($"Title : {pm.Title}"); Console.WriteLine($"Summary : {pm.Summary}"); Console.WriteLine($"Tags : {pm.Tags}"); } return; }
public void NuGetClient_Packages_PackageVersions() { NuGetClient ngc = new NuGetClient(); IEnumerable <NuGetVersion> package_versions = ngc.GetPackageVersionsAsync ( "Xamarin.AndroidX.Core" ).Result; #if MSTEST Assert.IsNotNull(package_versions); #elif NUNIT Assert.NotNull(package_versions); #elif XUNIT Assert.NotNull(package_versions); #endif Console.WriteLine($"Package metadata..."); foreach (NuGetVersion v in package_versions) { Console.WriteLine($"----------------------------------------------------------"); Console.WriteLine($"Version : {v.Version}"); Console.WriteLine($"Summary : {v.OriginalVersion}"); } return; }
public static async Task <int> GetAsync(string packageId, bool prerelease, CancellationToken cancellationToken) { using var client = new NuGetClient(); int downloads = await client.GetAsync(packageId, prerelease, cancellationToken); return(downloads); }
public async Task GetLatestPackageVersion_NonExistingPackage_ReturnsNull() { var client = new NuGetClient(); var versions = await client.GetPackageVersions("If.ClaimsForms.Bot.Models"); Assert.IsNull(versions); }
public async Task GetLatestPackageVersion_BotModelsPackage_ReturnsLatestVersion() { var client = new NuGetClient(); var versions = await client.GetPackageVersions("Newtonsoft.Json"); Assert.IsNotNull(versions); }
private bool InstallSinglePackage(PackageItem pkgItem, NuGetRequest request, ProgressTracker progressTracker) { bool packageWasInstalled = false; PackageItem packageToBeInstalled; request.Debug(Messages.DebugInfoCallMethod, "NuGetFilesFeed3", "InstallSinglePackage"); try { if (pkgItem == null || pkgItem.PackageSource == null || pkgItem.PackageSource.Repository == null) { return(false); } // If the source location exists as a directory then we try to get the file location and provide to the packagelocal if (Directory.Exists(pkgItem.PackageSource.Location)) { var fileLocation = pkgItem.PackageSource.Repository.FindPackage(new NuGetSearchContext() { PackageInfo = new PackageEntryInfo(pkgItem.Id), RequiredVersion = new Provider.Utility.SemanticVersion(pkgItem.Version) }, request).FullFilePath; packageToBeInstalled = NuGetClient.InstallPackageLocal(pkgItem.Id, pkgItem.Version, request, pkgItem.PackageSource, fileLocation, progressTracker); } else { string httpquery = MakeDownloadUri(pkgItem); // wait for the result from installpackage packageToBeInstalled = NuGetClient.InstallPackage(pkgItem.Id, pkgItem.Version, request, pkgItem.PackageSource, httpquery, pkgItem.Package.PackageHash, pkgItem.Package.PackageHashAlgorithm, progressTracker); } // Package is installed successfully if (packageToBeInstalled != null) { // if this is a http repository, return metadata from online if (!pkgItem.PackageSource.Repository.IsFile) { request.YieldPackage(pkgItem, packageToBeInstalled.PackageSource.Name, packageToBeInstalled.FullPath); } else { request.YieldPackage(packageToBeInstalled, packageToBeInstalled.PackageSource.Name, packageToBeInstalled.FullPath); } packageWasInstalled = true; } return(packageWasInstalled); } finally { request.Debug(Messages.DebugInfoReturnCall, "NuGetFilesFeed3", "InstallSinglePackage"); } }
/// <summary> /// Find-Package bases on the given package Id /// </summary> /// <param name="packageId">Package Id</param> /// <param name="request"></param> /// <returns></returns> public IEnumerable <IPackage> FindPackagesById(string packageId, NuGetRequest request) { request.Debug(Messages.DebugInfoCallMethod3, "HttpClientPackageRepository", "FindPackagesById", packageId); var query = packageId.MakeFindPackageByIdQuery(_nugetFindPackageIdQueryFormat); //request.Verbose(query.ToString()); return(NuGetClient.FindPackage(query, request)); }
public static Task <bool> UploadSymbolsPackageAsync( this NuGetClient client, string packageId, string version, string apiKey, ISymbolStorageService storageService, CancellationToken cancellationToken = default) { return(client.UploadSymbolsPackageAsync(packageId, NuGetVersion.Parse(version), apiKey, storageService, cancellationToken)); }
public async Task Autocomplete() { // Search for packages whose names' start with "Newt". NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json"); IReadOnlyList <string> packageIds = await client.AutocompleteAsync("Newt"); foreach (string packageId in packageIds) { Console.WriteLine($"Found package ID '{packageId}'"); } }
public BaGetClientIntegrationTests(ITestOutputHelper output) { _app = new BaGetApplication(output); var serviceIndexUrl = new Uri(_app.Server.BaseAddress, "v3/index.json"); _httpClient = _app.CreateClient(); _clientFactory = new NuGetClientFactory(_httpClient, serviceIndexUrl.AbsoluteUri); _client = new NuGetClient(_clientFactory); _packageStream = TestResources.GetResourceStream(TestResources.Package); }
public async Task DownloadPackage() { // Downloads a package file (.nupkg) var client = new NuGetClient("https://api.nuget.org/v3/index.json"); var packageId = "Newtonsoft.Json"; var packageVersion = new NuGetVersion("12.0.1"); using (var packageStream = await client.GetPackageStreamAsync(packageId, packageVersion)) { Console.WriteLine($"Downloaded package {packageId} {packageVersion}"); } }
public BaGetClientIntegrationTests( BaGetWebApplicationFactory factory, ITestOutputHelper output) { _factory = factory.WithOutput(output); var serviceIndexUrl = new Uri(_factory.Server.BaseAddress, "v3/index.json"); var httpClient = _factory.CreateDefaultClient(); _clientFactory = new NuGetClientFactory(httpClient, serviceIndexUrl.AbsoluteUri); _client = new NuGetClient(_clientFactory); }
/// <summary> /// Uninstalls a package /// </summary> /// <param name="fastPackageReference"></param> /// <param name="request">An object passed in from the PackageManagement that contains functions that can be used to interact with its Provider</param> public void UninstallPackage(string fastPackageReference, NuGetRequest request) { if (request == null) { throw new ArgumentNullException("request"); } request.Debug(Resources.Messages.DebugInfoCallMethod3, PackageProviderName, "UninstallPackage", fastPackageReference); var pkg = request.GetPackageByFastpath(fastPackageReference); NuGetClient.UninstallPackage(request, pkg); }
public void Test_Versions() { NuGetClient nc = new NuGetClient(); var versions = nc.GetPackageVersionsAsync("Xamarin.AndroidX.Activity").Result; foreach (NuGetVersion version in versions) { Console.WriteLine($"Found version {version}"); } return; }
public override bool IsAvailable(RequestWrapper request) { foreach (NuGetServiceInfo endpoint in this.Endpoints) { Stream s = NuGetClient.DownloadDataToStream(endpoint.Url, request); if (s != null) { return(true); } } return(false); }
public async Task DownloadPackageManifest() { // Downloads a package manifest (.nuspec) NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json"); string packageId = "Newtonsoft.Json"; NuGetVersion packageVersion = new NuGetVersion("12.0.1"); using (Stream manifestStream = await client.GetPackageManifestStreamAsync(packageId, packageVersion)) { Console.WriteLine($"Downloaded package {packageId} {packageVersion}'s nuspec"); } }
public ProtocolFixture() { var httpClient = new HttpClient(new TestDataHttpMessageHandler()); NuGetClientFactory = new NuGetClientFactory(httpClient, TestData.ServiceIndexUrl); NuGetClient = new NuGetClient(NuGetClientFactory); ServiceIndexClient = new RawServiceIndexClient(httpClient, TestData.ServiceIndexUrl); ContentClient = new RawPackageContentClient(httpClient, TestData.PackageContentUrl); MetadataClient = new RawPackageMetadataClient(httpClient, TestData.PackageMetadataUrl); SearchClient = new RawSearchClient(httpClient, TestData.SearchUrl); AutocompleteClient = new RawAutocompleteClient(httpClient, TestData.AutocompleteUrl); CatalogClient = new RawCatalogClient(httpClient, TestData.CatalogIndexUrl); }
public async Task GetPackageMetadata() { // Find the metadata for a single version of a package. var client = new NuGetClient("https://api.nuget.org/v3/index.json"); var packageId = "Newtonsoft.Json"; var packageVersion = new NuGetVersion("12.0.1"); var registrationItem = await client.GetPackageMetadataAsync(packageId, packageVersion); Console.WriteLine($"Listed: {registrationItem.PackageMetadata.Listed}"); Console.WriteLine($"Tags: {registrationItem.PackageMetadata.Tags}"); Console.WriteLine($"Description: {registrationItem.PackageMetadata.Description}"); }
public bool InstallPackage(PublicObjectView packageView, RequestWrapper request) { try { request.Debug(Messages.DebugInfoCallMethod, "NuGetFilesFeed3", "InstallPackage"); PackageItem package = packageView.GetValue <PackageItem>(); request.Debug(Messages.DebugInfoCallMethod3, "NuGetFilesFeed3", "InstallPackage", package.FastPath); return(NuGetClient.InstallOrDownloadPackageHelper(package, request.Request, Constants.Install, (packageItem, progressTracker) => this.InstallSinglePackage(packageItem, request.Request, progressTracker))); } finally { request.Debug(Messages.DebugInfoReturnCall, "NuGetFilesFeed3", "InstallPackage"); } }
public XNuGetClient( HttpClient sharedHttpClient, SecretKeyStore secretKeyStore, ArtifactCenter artifact, IEnvLocalFeedProvider localFeedProvider, FileSystem fs, Initializer initializer) : base(initializer) { _nuGetClient = new NuGetClient(sharedHttpClient, secretKeyStore); localFeedProvider.Register(new EnvLocalFeedProviderNuGetHandler()); fs.ServiceContainer.Add(_nuGetClient); artifact.Register(_nuGetClient); initializer.Services.Add(this); }
public bool DownloadPackage(PublicObjectView packageView, string destination, RequestWrapper request) { try { request.Debug(Messages.DebugInfoCallMethod3, "NuGetLocalPackageFeed", "DownloadPackage", destination); PackageItem package = packageView.GetValue <PackageItem>(); // TODO: For now this has to require NuGetRequest, due to its usage of stuff like request.GetOptionValue and request.YieldPackage return(NuGetClient.InstallOrDownloadPackageHelper(package, request.Request, Constants.Install, (packageItem, progressTracker) => NuGetClient.DownloadSinglePackage(packageItem, request.Request, destination, progressTracker))); } finally { request.Debug(Messages.DebugInfoReturnCall, "NuGetLocalPackageFeed", "DownloadPackage"); } }
public async Task ListVersions() { // Find all versions of a package (including unlisted versions). var client = new NuGetClient("https://api.nuget.org/v3/index.json"); var packageVersions = await client.ListPackageVersions("Newtonsoft.Json", includeUnlisted : true); if (!packageVersions.Any()) { Console.WriteLine($"Package 'Newtonsoft.Json' does not exist"); return; } Console.WriteLine($"Found {packageVersions.Count} versions"); }
public async Task Autocomplete() { // Search for packages whose names' start with "Newt". NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json"); AutocompleteResponse response = await client.AutocompleteAsync("Newt"); Console.WriteLine($"Found {response.TotalHits} results"); var index = 1; foreach (string packageId in response.Data) { Console.WriteLine($"Found package ID #{index}: '{packageId}'"); index++; } }
public async Task ShouldSearch(string packageId, bool?preRelease) { // Arrange var skipLatestStable = true; var skipLatestPreRelease = true; var nugetClient = new NuGetClient(this.logger, new NuGetClientConfiguration()); // Act var searchResult = await nugetClient.SearchAsync(packageId, preRelease, skipLatestStable, skipLatestPreRelease); // Assert testOutputHelper.WriteLine(ObjectDumper.Dump(searchResult, dumpOptions)); searchResult.Should().NotBeNull(); searchResult.Data.Should().HaveCountGreaterThan(0); }
public void NuGetClient_Packages_Search() { NuGetClient.HttpClient = Tests.CommonShared.Http.Client; NuGetClient ngc = new NuGetClient(); IEnumerable <IPackageSearchMetadata> search = null; search = ngc.SearchPackagesByKeywordAsync ( "androidx", new global::NuGet.Protocol.Core.Types.SearchFilter ( includePrerelease: true ), skip: 0, take: 100, psm => { return ( psm.Description.Contains("car") || psm.Description.Contains("androidx.car") ); } ).Result; #if MSTEST Assert.IsNotNull(search); #elif NUNIT Assert.NotNull(search); #elif XUNIT Assert.NotNull(search); #endif Console.WriteLine($"Packages found..."); foreach (IPackageSearchMetadata pm in search) { Console.WriteLine($"----------------------------------------------------------"); Console.WriteLine($"Title : {pm.Title}"); Console.WriteLine($"Summary : {pm.Summary}"); Console.WriteLine($"Tags : {pm.Tags}"); } return; }
public async Task Exists() { // Check if a package exists. NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json"); if (!await client.ExistsAsync("newtonsoft.json")) { Console.WriteLine("Package 'newtonsoft.json' does not exist!"); } var packageVersion = NuGetVersion.Parse("12.0.1"); if (!await client.ExistsAsync("newtonsoft.json", packageVersion)) { Console.WriteLine("Package 'newtonsoft.json' version '12.0.1' does not exist!"); } }
public static async Task <bool> UploadSymbolsPackageAsync( this NuGetClient client, string packageId, NuGetVersion version, string apiKey, ISymbolStorageService storageService, CancellationToken cancellationToken = default) { using var stream = await storageService.GetSymbolsAsync(packageId, version, cancellationToken); if (stream == Stream.Null || cancellationToken.IsCancellationRequested) { return(false); } return(await client.UploadSymbolsPackageAsync(packageId, version, apiKey, stream, cancellationToken)); }
private static INuGetResourceCollection GetResourcesImpl(string baseUrl, RequestWrapper request) { INuGetResourceCollection res = null; HttpClient client = request.GetClientWithHeaders(); HttpResponseMessage response = PathUtility.GetHttpResponse(client, baseUrl, (() => request.IsCanceled()), ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg)); if (!response.IsSuccessStatusCode) { throw new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed); } string content = new StreamReader(NuGetClient.DownloadDataToStream(baseUrl, request)).ReadToEnd(); // If the response starts with the magic XML header, it's v2 if (content.StartsWith(Constants.XmlStartContent)) { res = NuGetResourceCollection2.Make(baseUrl); } else { try { dynamic root = DynamicJsonParser.Parse(content); string version = root.version; if (version != null && version.StartsWith("3.")) { // v3 feed res = NuGetResourceCollection3.Make(root, baseUrl, request); } } catch (Exception ex) { Exception discoveryException = new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed, ex); throw discoveryException; } } if (res == null) { // Couldn't figure out what this is throw new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed); } return(res); }