diff --git a/src/BaGet.Aws/Configuration/S3StorageOptions.cs b/src/BaGet.Aws/Configuration/S3StorageOptions.cs index dfde314ff..fa2eb1b24 100644 --- a/src/BaGet.Aws/Configuration/S3StorageOptions.cs +++ b/src/BaGet.Aws/Configuration/S3StorageOptions.cs @@ -1,5 +1,5 @@ using System.ComponentModel.DataAnnotations; -using BaGet.Core.Validation; +using BaGet.Core; namespace BaGet.Aws.Configuration { diff --git a/src/BaGet.Aws/S3StorageService.cs b/src/BaGet.Aws/S3StorageService.cs index 07e131f90..c95e1bbbe 100644 --- a/src/BaGet.Aws/S3StorageService.cs +++ b/src/BaGet.Aws/S3StorageService.cs @@ -5,7 +5,7 @@ using Amazon.S3; using Amazon.S3.Model; using BaGet.Aws.Configuration; -using BaGet.Core.Storage; +using BaGet.Core; using Microsoft.Extensions.Options; namespace BaGet.Aws diff --git a/src/BaGet.Azure/BlobStorageService.cs b/src/BaGet.Azure/BlobStorageService.cs index f75aaab8b..4c18fd1f9 100644 --- a/src/BaGet.Azure/BlobStorageService.cs +++ b/src/BaGet.Azure/BlobStorageService.cs @@ -3,8 +3,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Extensions; -using BaGet.Core.Storage; +using BaGet.Core; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Blob; diff --git a/src/BaGet.Azure/Configuration/AzureSearchOptions.cs b/src/BaGet.Azure/Configuration/AzureSearchOptions.cs index 1ba788de2..4f63b9433 100644 --- a/src/BaGet.Azure/Configuration/AzureSearchOptions.cs +++ b/src/BaGet.Azure/Configuration/AzureSearchOptions.cs @@ -1,8 +1,9 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; +using BaGet.Core; namespace BaGet.Azure.Configuration { - public class AzureSearchOptions : Core.Configuration.SearchOptions + public class AzureSearchOptions : SearchOptions { [Required] public string AccountName { get; set; } diff --git a/src/BaGet.Azure/Search/AzureSearchService.cs b/src/BaGet.Azure/Search/AzureSearchService.cs index 12e18ef94..fe3cc8016 100644 --- a/src/BaGet.Azure/Search/AzureSearchService.cs +++ b/src/BaGet.Azure/Search/AzureSearchService.cs @@ -5,9 +5,6 @@ using System.Threading; using System.Threading.Tasks; using BaGet.Core; -using BaGet.Core.Entities; -using BaGet.Core.Indexing; -using BaGet.Core.Search; using BaGet.Protocol.Models; using Microsoft.Azure.Search; using NuGet.Versioning; @@ -17,7 +14,7 @@ namespace BaGet.Azure.Search using QueryType = Microsoft.Azure.Search.Models.QueryType; using SearchParameters = Microsoft.Azure.Search.Models.SearchParameters; - public class AzureSearchService : IBaGetSearchResource + public class AzureSearchService : ISearchService { private readonly BatchIndexer _indexer; private readonly SearchIndexClient _searchClient; diff --git a/src/BaGet.Azure/Search/BatchIndexer.cs b/src/BaGet.Azure/Search/BatchIndexer.cs index 85beb72de..139b9baa1 100644 --- a/src/BaGet.Azure/Search/BatchIndexer.cs +++ b/src/BaGet.Azure/Search/BatchIndexer.cs @@ -3,8 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using BaGet.Core.Entities; -using BaGet.Core.Metadata; +using BaGet.Core; using Microsoft.Azure.Search; using Microsoft.Azure.Search.Models; using Microsoft.Extensions.Logging; diff --git a/src/BaGet.Core.Server/Controllers/PackageContentController.cs b/src/BaGet.Core.Server/Controllers/PackageContentController.cs index dc917a24c..adf7a38ae 100644 --- a/src/BaGet.Core.Server/Controllers/PackageContentController.cs +++ b/src/BaGet.Core.Server/Controllers/PackageContentController.cs @@ -14,9 +14,9 @@ namespace BaGet.Controllers /// public class PackageContentController : Controller { - private readonly IBaGetPackageContentService _content; + private readonly IPackageContentService _content; - public PackageContentController(IBaGetPackageContentService content) + public PackageContentController(IPackageContentService content) { _content = content ?? throw new ArgumentNullException(nameof(content)); } diff --git a/src/BaGet.Core.Server/Controllers/PackageMetadataController.cs b/src/BaGet.Core.Server/Controllers/PackageMetadataController.cs index a6fa8840e..87c3ac65f 100644 --- a/src/BaGet.Core.Server/Controllers/PackageMetadataController.cs +++ b/src/BaGet.Core.Server/Controllers/PackageMetadataController.cs @@ -1,7 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Metadata; +using BaGet.Core; using BaGet.Protocol.Models; using Microsoft.AspNetCore.Mvc; using NuGet.Versioning; @@ -14,9 +14,9 @@ namespace BaGet.Controllers /// public class PackageMetadataController : Controller { - private readonly IBaGetPackageMetadataService _metadata; + private readonly IPackageMetadataService _metadata; - public PackageMetadataController(IBaGetPackageMetadataService metadata) + public PackageMetadataController(IPackageMetadataService metadata) { _metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); } diff --git a/src/BaGet.Core.Server/Controllers/PackagePublishController.cs b/src/BaGet.Core.Server/Controllers/PackagePublishController.cs index f6f3817cc..7cdcf1eb5 100644 --- a/src/BaGet.Core.Server/Controllers/PackagePublishController.cs +++ b/src/BaGet.Core.Server/Controllers/PackagePublishController.cs @@ -1,10 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Authentication; -using BaGet.Core.Configuration; -using BaGet.Core.Indexing; -using BaGet.Core.Metadata; +using BaGet.Core; using BaGet.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; diff --git a/src/BaGet.Core.Server/Controllers/SearchController.cs b/src/BaGet.Core.Server/Controllers/SearchController.cs index bfc8cd1f3..5b8db0903 100644 --- a/src/BaGet.Core.Server/Controllers/SearchController.cs +++ b/src/BaGet.Core.Server/Controllers/SearchController.cs @@ -1,7 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Search; +using BaGet.Core; using BaGet.Protocol.Models; using Microsoft.AspNetCore.Mvc; @@ -9,9 +9,9 @@ namespace BaGet.Controllers { public class SearchController : Controller { - private readonly IBaGetSearchResource _searchService; + private readonly ISearchService _searchService; - public SearchController(IBaGetSearchResource searchService) + public SearchController(ISearchService searchService) { _searchService = searchService ?? throw new ArgumentNullException(nameof(searchService)); } diff --git a/src/BaGet.Core.Server/Controllers/ServiceIndexController.cs b/src/BaGet.Core.Server/Controllers/ServiceIndexController.cs index 4d8ab0c0f..5101e91b2 100644 --- a/src/BaGet.Core.Server/Controllers/ServiceIndexController.cs +++ b/src/BaGet.Core.Server/Controllers/ServiceIndexController.cs @@ -1,7 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.ServiceIndex; +using BaGet.Core; using BaGet.Protocol.Models; using Microsoft.AspNetCore.Mvc; @@ -12,9 +12,9 @@ namespace BaGet.Controllers /// public class ServiceIndexController : Controller { - private readonly IBaGetServiceIndex _serviceIndex; + private readonly IServiceIndexService _serviceIndex; - public ServiceIndexController(IBaGetServiceIndex serviceIndex) + public ServiceIndexController(IServiceIndexService serviceIndex) { _serviceIndex = serviceIndex ?? throw new ArgumentNullException(nameof(serviceIndex)); } diff --git a/src/BaGet.Core.Server/Controllers/SymbolController.cs b/src/BaGet.Core.Server/Controllers/SymbolController.cs index 2ac99eb1f..060908640 100644 --- a/src/BaGet.Core.Server/Controllers/SymbolController.cs +++ b/src/BaGet.Core.Server/Controllers/SymbolController.cs @@ -1,10 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Authentication; -using BaGet.Core.Configuration; -using BaGet.Core.Indexing; -using BaGet.Core.Storage; +using BaGet.Core; using BaGet.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; diff --git a/src/BaGet.Core.Server/Extensions/HttpRequestExtensions.cs b/src/BaGet.Core.Server/Extensions/HttpRequestExtensions.cs index 8fcdcd40d..efb02d876 100644 --- a/src/BaGet.Core.Server/Extensions/HttpRequestExtensions.cs +++ b/src/BaGet.Core.Server/Extensions/HttpRequestExtensions.cs @@ -1,7 +1,7 @@ -using System.IO; +using System.IO; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Extensions; +using BaGet.Core; using Microsoft.AspNetCore.Http; namespace BaGet.Extensions diff --git a/src/BaGet.Core/Authentication/ApiKeyAuthenticationService.cs b/src/BaGet.Core/Authentication/ApiKeyAuthenticationService.cs index d1bff5327..adea32723 100644 --- a/src/BaGet.Core/Authentication/ApiKeyAuthenticationService.cs +++ b/src/BaGet.Core/Authentication/ApiKeyAuthenticationService.cs @@ -1,9 +1,8 @@ using System; using System.Threading.Tasks; -using BaGet.Core.Configuration; using Microsoft.Extensions.Options; -namespace BaGet.Core.Authentication +namespace BaGet.Core { public class ApiKeyAuthenticationService : IAuthenticationService { diff --git a/src/BaGet.Core/Authentication/IAuthenticationService.cs b/src/BaGet.Core/Authentication/IAuthenticationService.cs index a4d4a4e2a..d828e6d3c 100644 --- a/src/BaGet.Core/Authentication/IAuthenticationService.cs +++ b/src/BaGet.Core/Authentication/IAuthenticationService.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace BaGet.Core.Authentication +namespace BaGet.Core { public interface IAuthenticationService { diff --git a/src/BaGet.Core/Configuration/BaGetOptions.cs b/src/BaGet.Core/Configuration/BaGetOptions.cs index 0a29ae37a..f3ec6096a 100644 --- a/src/BaGet.Core/Configuration/BaGetOptions.cs +++ b/src/BaGet.Core/Configuration/BaGetOptions.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace BaGet.Core.Configuration +namespace BaGet.Core { public class BaGetOptions { diff --git a/src/BaGet.Core/Configuration/DatabaseOptions.cs b/src/BaGet.Core/Configuration/DatabaseOptions.cs index 8faaa1366..b2e46321b 100644 --- a/src/BaGet.Core/Configuration/DatabaseOptions.cs +++ b/src/BaGet.Core/Configuration/DatabaseOptions.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace BaGet.Core.Configuration +namespace BaGet.Core { public class DatabaseOptions { diff --git a/src/BaGet.Core/Configuration/FileSystemStorageOptions.cs b/src/BaGet.Core/Configuration/FileSystemStorageOptions.cs index cec852b1b..bf899c8de 100644 --- a/src/BaGet.Core/Configuration/FileSystemStorageOptions.cs +++ b/src/BaGet.Core/Configuration/FileSystemStorageOptions.cs @@ -3,7 +3,7 @@ using System.IO; using System.Linq; -namespace BaGet.Core.Configuration +namespace BaGet.Core { public class FileSystemStorageOptions : StorageOptions, IValidatableObject { diff --git a/src/BaGet.Core/Configuration/MirrorOptions.cs b/src/BaGet.Core/Configuration/MirrorOptions.cs index 096aef020..f5bb29467 100644 --- a/src/BaGet.Core/Configuration/MirrorOptions.cs +++ b/src/BaGet.Core/Configuration/MirrorOptions.cs @@ -1,8 +1,8 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -namespace BaGet.Core.Configuration +namespace BaGet.Core { public class MirrorOptions : IValidatableObject { diff --git a/src/BaGet.Core/Configuration/PackageDeletionBehavior.cs b/src/BaGet.Core/Configuration/PackageDeletionBehavior.cs index f6c6d2270..01c68d7ff 100644 --- a/src/BaGet.Core/Configuration/PackageDeletionBehavior.cs +++ b/src/BaGet.Core/Configuration/PackageDeletionBehavior.cs @@ -1,4 +1,4 @@ -namespace BaGet.Core.Configuration +namespace BaGet.Core { /// /// How BaGet should interpret package deletion requests. diff --git a/src/BaGet.Core/Configuration/SearchOptions.cs b/src/BaGet.Core/Configuration/SearchOptions.cs index 80c903c80..884710fec 100644 --- a/src/BaGet.Core/Configuration/SearchOptions.cs +++ b/src/BaGet.Core/Configuration/SearchOptions.cs @@ -1,4 +1,4 @@ -namespace BaGet.Core.Configuration +namespace BaGet.Core { public class SearchOptions { diff --git a/src/BaGet.Core/Configuration/StorageOptions.cs b/src/BaGet.Core/Configuration/StorageOptions.cs index 779a9cd86..2fe299981 100644 --- a/src/BaGet.Core/Configuration/StorageOptions.cs +++ b/src/BaGet.Core/Configuration/StorageOptions.cs @@ -1,4 +1,4 @@ -namespace BaGet.Core.Configuration +namespace BaGet.Core { public class StorageOptions { diff --git a/src/BaGet.Core/Content/DatabasePackageContentService.cs b/src/BaGet.Core/Content/DatabasePackageContentService.cs index 0af164d35..d72b42bb3 100644 --- a/src/BaGet.Core/Content/DatabasePackageContentService.cs +++ b/src/BaGet.Core/Content/DatabasePackageContentService.cs @@ -3,10 +3,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Metadata; -using BaGet.Core.Mirror; -using BaGet.Core.Storage; -using BaGet.Protocol; using BaGet.Protocol.Models; using NuGet.Versioning; @@ -17,20 +13,25 @@ namespace BaGet.Core.Content /// Tracks state in a database () and stores packages /// using . /// - public class DatabasePackageContentService : IBaGetPackageContentService + public class DatabasePackageContentService : IPackageContentService { private readonly IMirrorService _mirror; private readonly IPackageService _packages; private readonly IPackageStorageService _storage; - public DatabasePackageContentService(IMirrorService mirror, IPackageService packages, IPackageStorageService storage) + public DatabasePackageContentService( + IMirrorService mirror, + IPackageService packages, + IPackageStorageService storage) { _mirror = mirror ?? throw new ArgumentNullException(nameof(mirror)); _packages = packages ?? throw new ArgumentNullException(nameof(packages)); _storage = storage ?? throw new ArgumentNullException(nameof(storage)); } - public async Task GetPackageVersionsOrNullAsync(string id, CancellationToken cancellationToken = default) + public async Task GetPackageVersionsOrNullAsync( + string id, + CancellationToken cancellationToken = default) { // First, attempt to find all package versions using the upstream source. var versions = await _mirror.FindPackageVersionsOrNullAsync(id, cancellationToken); diff --git a/src/BaGet.Core/Content/IBaGetPackageContentService.cs b/src/BaGet.Core/Content/IBaGetPackageContentService.cs deleted file mode 100644 index fbd38f153..000000000 --- a/src/BaGet.Core/Content/IBaGetPackageContentService.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using BaGet.Protocol; -using NuGet.Versioning; - -namespace BaGet.Core.Content -{ - /// - /// BaGet's extensions to the NuGet Package Content resource. These additions - /// are not part of the official protocol. - /// - public interface IBaGetPackageContentService : IPackageContentResource - { - /// - /// Download a package's readme, or null if the package or readme does not exist. - /// - /// The package id. - /// The package's version. - /// A token to cancel the task. - /// - /// The package's readme stream, or null if the package or readme does not exist. The stream may not be seekable. - /// - Task GetPackageReadmeStreamOrNullAsync(string id, NuGetVersion version, CancellationToken cancellationToken = default); - } -} diff --git a/src/BaGet.Core/Content/IPackageContentService.cs b/src/BaGet.Core/Content/IPackageContentService.cs new file mode 100644 index 000000000..6ad554dc2 --- /dev/null +++ b/src/BaGet.Core/Content/IPackageContentService.cs @@ -0,0 +1,71 @@ +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using BaGet.Protocol.Models; +using NuGet.Versioning; + +namespace BaGet.Core.Content +{ + /// + /// The Package Content resource, used to download NuGet packages and to fetch other metadata. + /// + /// See: https://docs.microsoft.com/en-us/nuget/api/package-base-address-resource + /// + public interface IPackageContentService + { + /// + /// Get a package's versions, or null if the package does not exist. + /// See: https://docs.microsoft.com/en-us/nuget/api/package-base-address-resource#enumerate-package-versions + /// + /// The package ID. + /// A token to cancel the task. + /// The package's versions, or null if the package does not exist. + Task GetPackageVersionsOrNullAsync( + string packageId, + CancellationToken cancellationToken = default); + + /// + /// Download a package, or null if the package does not exist. + /// See: https://docs.microsoft.com/en-us/nuget/api/package-base-address-resource#download-package-content-nupkg + /// + /// The package ID. + /// The package's version. + /// A token to cancel the task. + /// + /// The package's content stream, or null if the package does not exist. The stream may not be seekable. + /// + Task GetPackageContentStreamOrNullAsync( + string packageId, + NuGetVersion packageVersion, + CancellationToken cancellationToken = default); + + /// + /// Download a package's manifest (nuspec), or null if the package does not exist. + /// See: https://docs.microsoft.com/en-us/nuget/api/package-base-address-resource#download-package-manifest-nuspec + /// + /// The package id. + /// The package's version. + /// A token to cancel the task. + /// + /// The package's manifest stream, or null if the package does not exist. The stream may not be seekable. + /// + Task GetPackageManifestStreamOrNullAsync( + string packageId, + NuGetVersion packageVersion, + CancellationToken cancellationToken = default); + + /// + /// Download a package's readme, or null if the package or readme does not exist. + /// + /// The package id. + /// The package's version. + /// A token to cancel the task. + /// + /// The package's readme stream, or null if the package or readme does not exist. The stream may not be seekable. + /// + Task GetPackageReadmeStreamOrNullAsync( + string id, + NuGetVersion version, + CancellationToken cancellationToken = default); + } +} diff --git a/src/BaGet.Core/Entities/AbstractContext.cs b/src/BaGet.Core/Entities/AbstractContext.cs index 06cf599e4..f2a00b629 100644 --- a/src/BaGet.Core/Entities/AbstractContext.cs +++ b/src/BaGet.Core/Entities/AbstractContext.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace BaGet.Core.Entities +namespace BaGet.Core { public abstract class AbstractContext : DbContext, IContext where TContext : DbContext { diff --git a/src/BaGet.Core/Entities/Converters/StringArrayToJsonConverter.cs b/src/BaGet.Core/Entities/Converters/StringArrayToJsonConverter.cs index fa9533f73..0991d1c3c 100644 --- a/src/BaGet.Core/Entities/Converters/StringArrayToJsonConverter.cs +++ b/src/BaGet.Core/Entities/Converters/StringArrayToJsonConverter.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Newtonsoft.Json; -namespace BaGet.Core.Entities +namespace BaGet.Core { public class StringArrayToJsonConverter : ValueConverter { diff --git a/src/BaGet.Core/Entities/Converters/UriToStringConverter.cs b/src/BaGet.Core/Entities/Converters/UriToStringConverter.cs index aaff7fb5a..d8ace4a68 100644 --- a/src/BaGet.Core/Entities/Converters/UriToStringConverter.cs +++ b/src/BaGet.Core/Entities/Converters/UriToStringConverter.cs @@ -1,7 +1,7 @@ using System; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -namespace BaGet.Core.Entities +namespace BaGet.Core { public class UriToStringConverter : ValueConverter { diff --git a/src/BaGet.Core/Entities/IContext.cs b/src/BaGet.Core/Entities/IContext.cs index 6be87def7..0cbee33e1 100644 --- a/src/BaGet.Core/Entities/IContext.cs +++ b/src/BaGet.Core/Entities/IContext.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -namespace BaGet.Core.Entities +namespace BaGet.Core { public interface IContext { diff --git a/src/BaGet.Core/Entities/Package.cs b/src/BaGet.Core/Entities/Package.cs index b2e18689b..269bbeb6e 100644 --- a/src/BaGet.Core/Entities/Package.cs +++ b/src/BaGet.Core/Entities/Package.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using NuGet.Versioning; -namespace BaGet.Core.Entities +namespace BaGet.Core { // See NuGetGallery's: https://github.com/NuGet/NuGetGallery/blob/master/src/NuGetGallery.Core/Entities/Package.cs public class Package diff --git a/src/BaGet.Core/Entities/PackageDependency.cs b/src/BaGet.Core/Entities/PackageDependency.cs index 04a5a20be..cd1edb391 100644 --- a/src/BaGet.Core/Entities/PackageDependency.cs +++ b/src/BaGet.Core/Entities/PackageDependency.cs @@ -1,4 +1,4 @@ -namespace BaGet.Core.Entities +namespace BaGet.Core { // See NuGetGallery.Core's: https://github.com/NuGet/NuGetGallery/blob/master/src/NuGetGallery.Core/Entities/PackageDependency.cs public class PackageDependency diff --git a/src/BaGet.Core/Entities/PackageType.cs b/src/BaGet.Core/Entities/PackageType.cs index 68f31e287..4e67d694b 100644 --- a/src/BaGet.Core/Entities/PackageType.cs +++ b/src/BaGet.Core/Entities/PackageType.cs @@ -1,4 +1,4 @@ -namespace BaGet.Core.Entities +namespace BaGet.Core { // See NuGetGallery.Core's: https://github.com/NuGet/NuGetGallery/blob/master/src/NuGetGallery.Core/Entities/PackageType.cs public class PackageType diff --git a/src/BaGet.Core/Entities/SemVerLevel.cs b/src/BaGet.Core/Entities/SemVerLevel.cs index 383fe7a35..29aa5ae41 100644 --- a/src/BaGet.Core/Entities/SemVerLevel.cs +++ b/src/BaGet.Core/Entities/SemVerLevel.cs @@ -1,4 +1,4 @@ -namespace BaGet.Core.Entities +namespace BaGet.Core { public enum SemVerLevel { diff --git a/src/BaGet.Core/Entities/TargetFramework.cs b/src/BaGet.Core/Entities/TargetFramework.cs index 55463a45a..a8e4a9a84 100644 --- a/src/BaGet.Core/Entities/TargetFramework.cs +++ b/src/BaGet.Core/Entities/TargetFramework.cs @@ -1,4 +1,4 @@ -namespace BaGet.Core.Entities +namespace BaGet.Core { public class TargetFramework { diff --git a/src/BaGet.Core/Extensions/PackageArchiveReaderExtensions.cs b/src/BaGet.Core/Extensions/PackageArchiveReaderExtensions.cs index f98aecec9..6154f6173 100644 --- a/src/BaGet.Core/Extensions/PackageArchiveReaderExtensions.cs +++ b/src/BaGet.Core/Extensions/PackageArchiveReaderExtensions.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using NuGet.Packaging; -namespace BaGet.Core.Extensions +namespace BaGet.Core { public static class PackageArchiveReaderExtensions { diff --git a/src/BaGet.Core/Extensions/ServiceCollectionExtensions.cs b/src/BaGet.Core/Extensions/ServiceCollectionExtensions.cs index 203c728a6..25a077a97 100644 --- a/src/BaGet.Core/Extensions/ServiceCollectionExtensions.cs +++ b/src/BaGet.Core/Extensions/ServiceCollectionExtensions.cs @@ -1,9 +1,8 @@ -using BaGet.Core.Configuration; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -namespace BaGet.Core.Extensions +namespace BaGet.Core { public static class ServiceCollectionExtensions { diff --git a/src/BaGet.Core/Extensions/StreamExtensions.cs b/src/BaGet.Core/Extensions/StreamExtensions.cs index 28994a6e3..bfe9d840a 100644 --- a/src/BaGet.Core/Extensions/StreamExtensions.cs +++ b/src/BaGet.Core/Extensions/StreamExtensions.cs @@ -5,7 +5,7 @@ using System.Threading; using System.Threading.Tasks; -namespace BaGet.Core.Extensions +namespace BaGet.Core { public static class StreamExtensions { diff --git a/src/BaGet.Core/Metadata/IPackageService.cs b/src/BaGet.Core/IPackageService.cs similarity index 96% rename from src/BaGet.Core/Metadata/IPackageService.cs rename to src/BaGet.Core/IPackageService.cs index 1a2d6cdd9..76878ff8a 100644 --- a/src/BaGet.Core/Metadata/IPackageService.cs +++ b/src/BaGet.Core/IPackageService.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; using NuGet.Versioning; -namespace BaGet.Core.Metadata +namespace BaGet.Core { /// /// The "source of truth" for packages' state. Packages' content - /// are stored by the . + /// are stored by the . /// public interface IPackageService { diff --git a/src/BaGet.Core/Indexing/FrameworkCompatibilityService.cs b/src/BaGet.Core/Indexing/FrameworkCompatibilityService.cs index c6be673d2..4cf4820b2 100644 --- a/src/BaGet.Core/Indexing/FrameworkCompatibilityService.cs +++ b/src/BaGet.Core/Indexing/FrameworkCompatibilityService.cs @@ -4,7 +4,7 @@ using System.Linq; using NuGet.Frameworks; -namespace BaGet.Core.Indexing +namespace BaGet.Core { using static NuGet.Frameworks.FrameworkConstants; diff --git a/src/BaGet.Core/Indexing/IFrameworkCompatibilityService.cs b/src/BaGet.Core/Indexing/IFrameworkCompatibilityService.cs index ef9aa1a3e..50f07256e 100644 --- a/src/BaGet.Core/Indexing/IFrameworkCompatibilityService.cs +++ b/src/BaGet.Core/Indexing/IFrameworkCompatibilityService.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace BaGet.Core.Indexing +namespace BaGet.Core { /// /// Used to determine the compatibility matrix between frameworks. diff --git a/src/BaGet.Core/Metadata/IPackageDeletionService.cs b/src/BaGet.Core/Indexing/IPackageDeletionService.cs similarity index 95% rename from src/BaGet.Core/Metadata/IPackageDeletionService.cs rename to src/BaGet.Core/Indexing/IPackageDeletionService.cs index 245b5bb01..691b99e8b 100644 --- a/src/BaGet.Core/Metadata/IPackageDeletionService.cs +++ b/src/BaGet.Core/Indexing/IPackageDeletionService.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using NuGet.Versioning; -namespace BaGet.Core.Metadata +namespace BaGet.Core { public interface IPackageDeletionService { diff --git a/src/BaGet.Core/Indexing/IPackageIndexingService.cs b/src/BaGet.Core/Indexing/IPackageIndexingService.cs index c9fd2e659..ddbf06d27 100644 --- a/src/BaGet.Core/Indexing/IPackageIndexingService.cs +++ b/src/BaGet.Core/Indexing/IPackageIndexingService.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace BaGet.Core.Indexing +namespace BaGet.Core { /// /// The result of attempting to index a package. diff --git a/src/BaGet.Core/Indexing/ISymbolIndexingService.cs b/src/BaGet.Core/Indexing/ISymbolIndexingService.cs index b87454841..85a671a96 100644 --- a/src/BaGet.Core/Indexing/ISymbolIndexingService.cs +++ b/src/BaGet.Core/Indexing/ISymbolIndexingService.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace BaGet.Core.Indexing +namespace BaGet.Core { /// /// The result of attempting to index a symbol package. diff --git a/src/BaGet.Core/Metadata/PackageDeletionService.cs b/src/BaGet.Core/Indexing/PackageDeletionService.cs similarity index 97% rename from src/BaGet.Core/Metadata/PackageDeletionService.cs rename to src/BaGet.Core/Indexing/PackageDeletionService.cs index f6a0f7449..aabee884e 100644 --- a/src/BaGet.Core/Metadata/PackageDeletionService.cs +++ b/src/BaGet.Core/Indexing/PackageDeletionService.cs @@ -1,13 +1,11 @@ using System; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Configuration; -using BaGet.Core.Storage; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using NuGet.Versioning; -namespace BaGet.Core.Metadata +namespace BaGet.Core { public class PackageDeletionService : IPackageDeletionService { diff --git a/src/BaGet.Core/Indexing/PackageIndexingService.cs b/src/BaGet.Core/Indexing/PackageIndexingService.cs index 9b7bfd4e9..e84ef2741 100644 --- a/src/BaGet.Core/Indexing/PackageIndexingService.cs +++ b/src/BaGet.Core/Indexing/PackageIndexingService.cs @@ -4,17 +4,11 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Configuration; -using BaGet.Core.Entities; -using BaGet.Core.Extensions; -using BaGet.Core.Metadata; -using BaGet.Core.Search; -using BaGet.Core.Storage; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using NuGet.Packaging; -namespace BaGet.Core.Indexing +namespace BaGet.Core { using NuGetPackageType = NuGet.Packaging.Core.PackageType; @@ -22,14 +16,14 @@ public class PackageIndexingService : IPackageIndexingService { private readonly IPackageService _packages; private readonly IPackageStorageService _storage; - private readonly IBaGetSearchResource _search; + private readonly ISearchService _search; private readonly IOptionsSnapshot _options; private readonly ILogger _logger; public PackageIndexingService( IPackageService packages, IPackageStorageService storage, - IBaGetSearchResource search, + ISearchService search, IOptionsSnapshot options, ILogger logger) { diff --git a/src/BaGet.Core/Indexing/SymbolIndexingService.cs b/src/BaGet.Core/Indexing/SymbolIndexingService.cs index 91e28ff10..dedcca3a3 100644 --- a/src/BaGet.Core/Indexing/SymbolIndexingService.cs +++ b/src/BaGet.Core/Indexing/SymbolIndexingService.cs @@ -5,13 +5,10 @@ using System.Reflection.Metadata; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Extensions; -using BaGet.Core.Metadata; -using BaGet.Core.Storage; using Microsoft.Extensions.Logging; using NuGet.Packaging; -namespace BaGet.Core.Indexing +namespace BaGet.Core { // Based off: https://github.com/NuGet/NuGetGallery/blob/master/src/NuGetGallery/Services/SymbolPackageUploadService.cs // Based off: https://github.com/NuGet/NuGet.Jobs/blob/master/src/Validation.Symbols/SymbolsValidatorService.cs#L44 diff --git a/src/BaGet.Core/Metadata/BaGetPackageMetadata.cs b/src/BaGet.Core/Metadata/BaGetPackageMetadata.cs index 46a3b6a20..ff1ed4bed 100644 --- a/src/BaGet.Core/Metadata/BaGetPackageMetadata.cs +++ b/src/BaGet.Core/Metadata/BaGetPackageMetadata.cs @@ -1,10 +1,7 @@ -using System; using System.Collections.Generic; -using BaGet.Protocol; using BaGet.Protocol.Models; -using NuGet.Versioning; -namespace BaGet.Core.Metadata +namespace BaGet.Core { /// /// BaGet's extensions to the package metadata model. These additions diff --git a/src/BaGet.Core/Metadata/BaGetRegistrationIndexResponse.cs b/src/BaGet.Core/Metadata/BaGetRegistrationIndexResponse.cs index de5691fed..6786b85ec 100644 --- a/src/BaGet.Core/Metadata/BaGetRegistrationIndexResponse.cs +++ b/src/BaGet.Core/Metadata/BaGetRegistrationIndexResponse.cs @@ -1,11 +1,9 @@ -using System.Collections.Generic; -using BaGet.Protocol; using BaGet.Protocol.Models; -namespace BaGet.Core.Metadata +namespace BaGet.Core { /// - /// BaGet's extensions to a search request. These additions + /// BaGet's extensions to a registration index response. These additions /// are not part of the official protocol. /// public class BaGetRegistrationIndexResponse : RegistrationIndexResponse diff --git a/src/BaGet.Core/Metadata/BaGetRegistrationLeafResponse.cs b/src/BaGet.Core/Metadata/BaGetRegistrationLeafResponse.cs index 65c262d5d..9a2d9205b 100644 --- a/src/BaGet.Core/Metadata/BaGetRegistrationLeafResponse.cs +++ b/src/BaGet.Core/Metadata/BaGetRegistrationLeafResponse.cs @@ -1,7 +1,11 @@ using BaGet.Protocol.Models; -namespace BaGet.Core.Metadata +namespace BaGet.Core { + /// + /// BaGet's extensions to a registration leaf response. These additions + /// are not part of the official protocol. + /// public class BaGetRegistrationLeafResponse : RegistrationLeafResponse { public long Downloads { get; set; } diff --git a/src/BaGet.Core/Metadata/DatabasePackageMetadataService.cs b/src/BaGet.Core/Metadata/DatabasePackageMetadataService.cs index 385365a7b..683d7fe8f 100644 --- a/src/BaGet.Core/Metadata/DatabasePackageMetadataService.cs +++ b/src/BaGet.Core/Metadata/DatabasePackageMetadataService.cs @@ -3,15 +3,13 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; -using BaGet.Core.Mirror; using BaGet.Protocol.Models; using NuGet.Versioning; -namespace BaGet.Core.Metadata +namespace BaGet.Core { /// - public class DatabasePackageMetadataService : IBaGetPackageMetadataService + public class DatabasePackageMetadataService : IPackageMetadataService { private readonly IMirrorService _mirror; private readonly IPackageService _packages; @@ -24,7 +22,9 @@ public DatabasePackageMetadataService(IMirrorService mirror, IPackageService pac _url = url ?? throw new ArgumentNullException(nameof(url)); } - public async Task GetRegistrationIndexOrNullAsync(string id, CancellationToken cancellationToken = default) + public async Task GetRegistrationIndexOrNullAsync( + string id, + CancellationToken cancellationToken = default) { // Find the packages that match the given package id from the upstream, if // one is configured. If these packages cannot be found on the upstream, @@ -66,7 +66,7 @@ public async Task GetRegistrationIndexOrNullAsync(str }; } - public async Task GetRegistrationLeafOrNullAsync( + public async Task GetRegistrationLeafOrNullAsync( string id, NuGetVersion version, CancellationToken cancellationToken = default) @@ -92,19 +92,6 @@ public async Task GetRegistrationLeafOrNullAsync( }; } - public Task GetRegistrationPageOrNullAsync( - string id, - NuGetVersion lower, - NuGetVersion upper, - CancellationToken cancellationToken = default) - { - // TODO: BaGet does not support paging of registration items. - // Currently, all items are inlined into the registration index. - // Implementing this feature efficiently requires the ability to - // sort packages by their versions from the database. - throw new NotImplementedException(); - } - private RegistrationIndexPageItem ToRegistrationIndexPageItem(Package package) => new RegistrationIndexPageItem { diff --git a/src/BaGet.Core/Metadata/IBaGetPackageMetadataService.cs b/src/BaGet.Core/Metadata/IBaGetPackageMetadataService.cs deleted file mode 100644 index 95b5f31c5..000000000 --- a/src/BaGet.Core/Metadata/IBaGetPackageMetadataService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using BaGet.Protocol; - -namespace BaGet.Core.Metadata -{ - /// - /// BaGet's extensions to the NuGet Package Metadata resource. These additions - /// are not part of the official protocol. - /// - public interface IBaGetPackageMetadataService : IPackageMetadataResource - { - } -} diff --git a/src/BaGet.Core/Metadata/IPackageMetadataService.cs b/src/BaGet.Core/Metadata/IPackageMetadataService.cs new file mode 100644 index 000000000..50cfb94e7 --- /dev/null +++ b/src/BaGet.Core/Metadata/IPackageMetadataService.cs @@ -0,0 +1,35 @@ +using System.Threading; +using System.Threading.Tasks; +using NuGet.Versioning; + +namespace BaGet.Core +{ + /// + /// The Package Metadata client, used to fetch packages' metadata. + /// + /// See https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource + /// + public interface IPackageMetadataService + { + /// + /// Attempt to get a package's registration index, if it exists. + /// See: https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#registration-page + /// + /// The package's ID. + /// A token to cancel the task. + /// The package's registration index, or null if the package does not exist + Task GetRegistrationIndexOrNullAsync(string packageId, CancellationToken cancellationToken = default); + + /// + /// Get the metadata for a single package version, if the package exists. + /// + /// The package's id. + /// The package's version. + /// A token to cancel the task. + /// The registration leaf, or null if the package does not exist. + Task GetRegistrationLeafOrNullAsync( + string packageId, + NuGetVersion packageVersion, + CancellationToken cancellationToken = default); + } +} diff --git a/src/BaGet.Core/Mirror/DownloadsImporter.cs b/src/BaGet.Core/Mirror/DownloadsImporter.cs index b86141d76..9887fab60 100644 --- a/src/BaGet.Core/Mirror/DownloadsImporter.cs +++ b/src/BaGet.Core/Mirror/DownloadsImporter.cs @@ -1,12 +1,11 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using BaGet.Core.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; -namespace BaGet.Core.Mirror +namespace BaGet.Core { public class DownloadsImporter { diff --git a/src/BaGet.Core/Mirror/IMirrorService.cs b/src/BaGet.Core/Mirror/IMirrorService.cs index 48b4ff7bc..01bdcee71 100644 --- a/src/BaGet.Core/Mirror/IMirrorService.cs +++ b/src/BaGet.Core/Mirror/IMirrorService.cs @@ -1,10 +1,9 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; using NuGet.Versioning; -namespace BaGet.Core.Mirror +namespace BaGet.Core { /// /// Indexes packages from an external source. diff --git a/src/BaGet.Core/Mirror/IPackageDownloader.cs b/src/BaGet.Core/Mirror/IPackageDownloader.cs deleted file mode 100644 index 49ed659fd..000000000 --- a/src/BaGet.Core/Mirror/IPackageDownloader.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace BaGet.Core.Mirror -{ - public interface IPackageDownloader - { - /// - /// Attempt to download a package. - /// - /// The package to download. - /// The token to cancel the download. - /// The package, or null if it couldn't be downloaded. - Task DownloadOrNullAsync(Uri packageUri, CancellationToken cancellationToken); - } -} diff --git a/src/BaGet.Core/Mirror/IPackageDownloadsSource.cs b/src/BaGet.Core/Mirror/IPackageDownloadsSource.cs index fc051b921..706e9638f 100644 --- a/src/BaGet.Core/Mirror/IPackageDownloadsSource.cs +++ b/src/BaGet.Core/Mirror/IPackageDownloadsSource.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; -namespace BaGet.Core.Mirror +namespace BaGet.Core { public interface IPackageDownloadsSource { diff --git a/src/BaGet.Core/Mirror/MirrorService.cs b/src/BaGet.Core/Mirror/MirrorService.cs index 184fd46f7..e0dc359ce 100644 --- a/src/BaGet.Core/Mirror/MirrorService.cs +++ b/src/BaGet.Core/Mirror/MirrorService.cs @@ -4,16 +4,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; -using BaGet.Core.Extensions; -using BaGet.Core.Indexing; -using BaGet.Core.Metadata; using BaGet.Protocol; using BaGet.Protocol.Models; using Microsoft.Extensions.Logging; using NuGet.Versioning; -namespace BaGet.Core.Mirror +namespace BaGet.Core { using PackageIdentity = NuGet.Packaging.Core.PackageIdentity; diff --git a/src/BaGet.Core/Mirror/FakeMirrorService.cs b/src/BaGet.Core/Mirror/NullMirrorService.cs similarity index 84% rename from src/BaGet.Core/Mirror/FakeMirrorService.cs rename to src/BaGet.Core/Mirror/NullMirrorService.cs index 3ef157f4b..dbcc74b63 100644 --- a/src/BaGet.Core/Mirror/FakeMirrorService.cs +++ b/src/BaGet.Core/Mirror/NullMirrorService.cs @@ -1,15 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; using NuGet.Versioning; -namespace BaGet.Core.Mirror +namespace BaGet.Core { /// /// The mirror service used when mirroring has been disabled. /// - public class FakeMirrorService : IMirrorService + public class NullMirrorService : IMirrorService { public Task> FindPackageVersionsOrNullAsync(string id, CancellationToken cancellationToken) { diff --git a/src/BaGet.Core/Mirror/PackageDownloader.cs b/src/BaGet.Core/Mirror/PackageDownloader.cs deleted file mode 100644 index 7507ed6b6..000000000 --- a/src/BaGet.Core/Mirror/PackageDownloader.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using BaGet.Core.Extensions; -using Microsoft.Extensions.Logging; - -namespace BaGet.Core.Mirror -{ - // See: https://github.com/NuGet/NuGet.Jobs/blob/master/src/Validation.Common.Job/PackageDownloader.cs - public class PackageDownloader : IPackageDownloader - { - private readonly HttpClient _httpClient; - private readonly ILogger _logger; - - public PackageDownloader(HttpClient httpClient, ILogger logger) - { - _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - - public async Task DownloadOrNullAsync(Uri packageUri, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - _logger.LogInformation("Attempting to download package from {PackageUri}...", packageUri); - - Stream packageStream = null; - var stopwatch = Stopwatch.StartNew(); - - try - { - // Download the package from the network to a temporary file. - using (var response = await _httpClient.GetAsync(packageUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken)) - { - _logger.LogInformation( - "Received response {StatusCode}: {ReasonPhrase} of type {ContentType} for request {PackageUri}", - response.StatusCode, - response.ReasonPhrase, - response.Content.Headers.ContentType, - packageUri); - - if (response.StatusCode != HttpStatusCode.OK) - { - _logger.LogWarning( - $"Expected status code {HttpStatusCode.OK} for package download, actual: {{ResponseStatusCode}}", - response.StatusCode); - - return null; - } - - using (var networkStream = await response.Content.ReadAsStreamAsync()) - { - packageStream = await networkStream.AsTemporaryFileStreamAsync(cancellationToken); - } - } - - _logger.LogInformation( - "Downloaded {PackageSizeInBytes} bytes in {DownloadElapsedTime} seconds for request {PackageUri}", - packageStream.Length, - stopwatch.Elapsed.TotalSeconds, - packageUri); - - return packageStream; - } - catch (Exception e) - { - _logger.LogError( - e, - "Exception thrown when trying to download package from {PackageUri}", - packageUri); - - packageStream?.Dispose(); - - return null; - } - } - } -} diff --git a/src/BaGet.Core/Mirror/PackageDownloadsJsonSource.cs b/src/BaGet.Core/Mirror/PackageDownloadsJsonSource.cs index 60a5d0403..9c95aff55 100644 --- a/src/BaGet.Core/Mirror/PackageDownloadsJsonSource.cs +++ b/src/BaGet.Core/Mirror/PackageDownloadsJsonSource.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -9,7 +9,7 @@ using Newtonsoft.Json.Linq; using NuGet.Versioning; -namespace BaGet.Core.Mirror +namespace BaGet.Core { // See https://github.com/NuGet/NuGet.Services.Metadata/blob/master/src/NuGet.Indexing/Downloads.cs public class PackageDownloadsJsonSource : IPackageDownloadsSource diff --git a/src/BaGet.Core/Metadata/PackageService.cs b/src/BaGet.Core/PackageService.cs similarity index 98% rename from src/BaGet.Core/Metadata/PackageService.cs rename to src/BaGet.Core/PackageService.cs index 2f2574c98..e6aeb32d5 100644 --- a/src/BaGet.Core/Metadata/PackageService.cs +++ b/src/BaGet.Core/PackageService.cs @@ -3,11 +3,10 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; using Microsoft.EntityFrameworkCore; using NuGet.Versioning; -namespace BaGet.Core.Metadata +namespace BaGet.Core { public class PackageService : IPackageService { diff --git a/src/BaGet.Core/Search/DatabaseSearchService.cs b/src/BaGet.Core/Search/DatabaseSearchService.cs index dc32b6eff..2c9b18de2 100644 --- a/src/BaGet.Core/Search/DatabaseSearchService.cs +++ b/src/BaGet.Core/Search/DatabaseSearchService.cs @@ -3,14 +3,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; -using BaGet.Core.Indexing; using BaGet.Protocol.Models; using Microsoft.EntityFrameworkCore; -namespace BaGet.Core.Search +namespace BaGet.Core { - public class DatabaseSearchService : IBaGetSearchResource + public class DatabaseSearchService : ISearchService { private readonly IContext _context; private readonly IFrameworkCompatibilityService _frameworks; diff --git a/src/BaGet.Core/Search/DependentsRequest.cs b/src/BaGet.Core/Search/DependentsRequest.cs index 5b5410374..fe27e0666 100644 --- a/src/BaGet.Core/Search/DependentsRequest.cs +++ b/src/BaGet.Core/Search/DependentsRequest.cs @@ -1,4 +1,4 @@ -namespace BaGet.Core.Search +namespace BaGet.Core { /// /// The request to find the packages that depend on a given package. diff --git a/src/BaGet.Core/Search/DependentsResponse.cs b/src/BaGet.Core/Search/DependentsResponse.cs index 6298acab3..5678332eb 100644 --- a/src/BaGet.Core/Search/DependentsResponse.cs +++ b/src/BaGet.Core/Search/DependentsResponse.cs @@ -1,7 +1,6 @@ -using System; using System.Collections.Generic; -namespace BaGet.Core.Search +namespace BaGet.Core { /// /// The package ids that depend on the queried package. diff --git a/src/BaGet.Core/Search/IBaGetSearchResource.cs b/src/BaGet.Core/Search/ISearchService.cs similarity index 64% rename from src/BaGet.Core/Search/IBaGetSearchResource.cs rename to src/BaGet.Core/Search/ISearchService.cs index 4bde6b247..69cb2ea81 100644 --- a/src/BaGet.Core/Search/IBaGetSearchResource.cs +++ b/src/BaGet.Core/Search/ISearchService.cs @@ -1,16 +1,15 @@ using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; -using BaGet.Protocol; using BaGet.Protocol.Models; -namespace BaGet.Core.Search +namespace BaGet.Core { /// - /// BaGet's extensions to the NuGet Search resource. These additions - /// are not part of the official protocol. + /// The service used to search for packages. + /// + /// See https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource /// - public interface IBaGetSearchResource : ISearchResource + public interface ISearchService { /// /// Add a package to the search index. @@ -43,6 +42,27 @@ Task SearchAsync( string framework = null, CancellationToken cancellationToken = default); + /// + /// Perform an autocomplete query. + /// See: https://docs.microsoft.com/en-us/nuget/api/search-autocomplete-service-resource + /// + /// The autocomplete query. + /// The autocomplete request type. + /// How many results to skip. + /// How many results to return. + /// Whether pre-release packages should be returned. + /// Whether packages that require SemVer 2.0.0 compatibility should be returned. + /// A token to cancel the task. + /// The autocomplete response. + Task AutocompleteAsync( + string query = null, + AutocompleteType type = AutocompleteType.PackageIds, + int skip = 0, + int take = 20, + bool includePrerelease = true, + bool includeSemVer2 = true, + CancellationToken cancellationToken = default); + /// /// Find the packages that depend on a given package. /// diff --git a/src/BaGet.Core/Search/NullSearchService.cs b/src/BaGet.Core/Search/NullSearchService.cs index 8b7d79785..110ca828d 100644 --- a/src/BaGet.Core/Search/NullSearchService.cs +++ b/src/BaGet.Core/Search/NullSearchService.cs @@ -1,15 +1,14 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; using BaGet.Protocol.Models; -namespace BaGet.Core.Search +namespace BaGet.Core { /// /// A minimal search service implementation, used for advanced scenarios. /// - public class NullSearchService : IBaGetSearchResource + public class NullSearchService : ISearchService { private static readonly IReadOnlyList EmptyStringList = new List(); diff --git a/src/BaGet.Core/ServiceIndex/BaGetServiceIndex.cs b/src/BaGet.Core/ServiceIndex/BaGetServiceIndex.cs index 268c28334..db84b65fd 100644 --- a/src/BaGet.Core/ServiceIndex/BaGetServiceIndex.cs +++ b/src/BaGet.Core/ServiceIndex/BaGetServiceIndex.cs @@ -4,9 +4,9 @@ using System.Threading.Tasks; using BaGet.Protocol.Models; -namespace BaGet.Core.ServiceIndex +namespace BaGet.Core { - public class BaGetServiceIndex : IBaGetServiceIndex + public class BaGetServiceIndex : IServiceIndexService { private readonly IUrlGenerator _url; diff --git a/src/BaGet.Core/ServiceIndex/IBaGetServiceIndex.cs b/src/BaGet.Core/ServiceIndex/IBaGetServiceIndex.cs deleted file mode 100644 index b9b6c7d59..000000000 --- a/src/BaGet.Core/ServiceIndex/IBaGetServiceIndex.cs +++ /dev/null @@ -1,12 +0,0 @@ -using BaGet.Protocol; - -namespace BaGet.Core.ServiceIndex -{ - /// - /// BaGet's extensions to the NuGet Service Index resource. These additions - /// are not part of the official protocol. - /// - public interface IBaGetServiceIndex : IServiceIndexResource - { - } -} diff --git a/src/BaGet.Core/ServiceIndex/IServiceIndexService.cs b/src/BaGet.Core/ServiceIndex/IServiceIndexService.cs new file mode 100644 index 000000000..67bf9a8b0 --- /dev/null +++ b/src/BaGet.Core/ServiceIndex/IServiceIndexService.cs @@ -0,0 +1,21 @@ +using System.Threading; +using System.Threading.Tasks; +using BaGet.Protocol.Models; + +namespace BaGet.Core +{ + /// + /// The NuGet Service Index service, used to discover other resources. + /// + /// See https://docs.microsoft.com/en-us/nuget/api/service-index + /// + public interface IServiceIndexService + { + /// + /// Get the resources available on this package feed. + /// See: https://docs.microsoft.com/en-us/nuget/api/service-index#resources + /// + /// The resources available on this package feed. + Task GetAsync(CancellationToken cancellationToken = default); + } +} diff --git a/src/BaGet.Core/Storage/FileStorageService.cs b/src/BaGet.Core/Storage/FileStorageService.cs index 4d5b07d1b..26d6f6ec0 100644 --- a/src/BaGet.Core/Storage/FileStorageService.cs +++ b/src/BaGet.Core/Storage/FileStorageService.cs @@ -2,11 +2,9 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Configuration; -using BaGet.Core.Extensions; using Microsoft.Extensions.Options; -namespace BaGet.Core.Storage +namespace BaGet.Core { /// /// Stores content on disk. diff --git a/src/BaGet.Core/Storage/IPackageStorageService.cs b/src/BaGet.Core/Storage/IPackageStorageService.cs index 674a57239..aefae56c9 100644 --- a/src/BaGet.Core/Storage/IPackageStorageService.cs +++ b/src/BaGet.Core/Storage/IPackageStorageService.cs @@ -1,14 +1,13 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; using NuGet.Versioning; -namespace BaGet.Core.Storage +namespace BaGet.Core { /// /// Stores packages' content. Packages' state are stored by the - /// . + /// . /// public interface IPackageStorageService { diff --git a/src/BaGet.Core/Storage/IStorageService.cs b/src/BaGet.Core/Storage/IStorageService.cs index 93db153cc..40ae76c92 100644 --- a/src/BaGet.Core/Storage/IStorageService.cs +++ b/src/BaGet.Core/Storage/IStorageService.cs @@ -3,7 +3,7 @@ using System.Threading; using System.Threading.Tasks; -namespace BaGet.Core.Storage +namespace BaGet.Core { /// /// A low-level storage abstraction. diff --git a/src/BaGet.Core/Storage/ISymbolStorageService.cs b/src/BaGet.Core/Storage/ISymbolStorageService.cs index 2eedf8e0d..f8681ab6a 100644 --- a/src/BaGet.Core/Storage/ISymbolStorageService.cs +++ b/src/BaGet.Core/Storage/ISymbolStorageService.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace BaGet.Core.Storage +namespace BaGet.Core { /// /// Stores the content of symbols, also known as PDBs. diff --git a/src/BaGet.Core/Storage/NullStorageService.cs b/src/BaGet.Core/Storage/NullStorageService.cs index 517753f28..4367abbb2 100644 --- a/src/BaGet.Core/Storage/NullStorageService.cs +++ b/src/BaGet.Core/Storage/NullStorageService.cs @@ -2,9 +2,8 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Storage; -namespace BaGet.Core.Search +namespace BaGet.Core { /// /// A minimal storage implementation, used for advanced scenarios. diff --git a/src/BaGet.Core/Storage/PackageStorageService.cs b/src/BaGet.Core/Storage/PackageStorageService.cs index dc11c273c..9d51643c9 100644 --- a/src/BaGet.Core/Storage/PackageStorageService.cs +++ b/src/BaGet.Core/Storage/PackageStorageService.cs @@ -2,11 +2,10 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; using Microsoft.Extensions.Logging; using NuGet.Versioning; -namespace BaGet.Core.Storage +namespace BaGet.Core { public class PackageStorageService : IPackageStorageService { diff --git a/src/BaGet.Core/Storage/SymbolStorageService.cs b/src/BaGet.Core/Storage/SymbolStorageService.cs index e08d4f405..0a0718f16 100644 --- a/src/BaGet.Core/Storage/SymbolStorageService.cs +++ b/src/BaGet.Core/Storage/SymbolStorageService.cs @@ -4,7 +4,7 @@ using System.Threading; using System.Threading.Tasks; -namespace BaGet.Core.Storage +namespace BaGet.Core { public class SymbolStorageService : ISymbolStorageService { diff --git a/src/BaGet.Core/Validation/RequiredIfAttribute.cs b/src/BaGet.Core/Validation/RequiredIfAttribute.cs index 2ba768304..56571a3d0 100644 --- a/src/BaGet.Core/Validation/RequiredIfAttribute.cs +++ b/src/BaGet.Core/Validation/RequiredIfAttribute.cs @@ -1,9 +1,8 @@ -using System; +using System; using System.ComponentModel.DataAnnotations; using System.Globalization; -using System.Reflection; -namespace BaGet.Core.Validation +namespace BaGet.Core { /// /// Provides conditional validation based on related property value. @@ -108,23 +107,23 @@ protected override ValidationResult IsValid(object value, ValidationContext vali if (validationContext == null) throw new ArgumentNullException(nameof(validationContext)); - PropertyInfo otherProperty = validationContext.ObjectType.GetProperty(OtherProperty); + var otherProperty = validationContext.ObjectType.GetProperty(OtherProperty); if (otherProperty == null) { return new ValidationResult( string.Format(CultureInfo.CurrentCulture, "Could not find a property named '{0}'.", OtherProperty)); } - object otherValue = otherProperty.GetValue(validationContext.ObjectInstance); + var otherValue = otherProperty.GetValue(validationContext.ObjectInstance); - // check if this value is actually required and validate it + // Check if this value is actually required and validate it. if (!IsInverted && Equals(otherValue, OtherPropertyValue) || IsInverted && !Equals(otherValue, OtherPropertyValue)) { if (value == null) return new ValidationResult(FormatErrorMessage(validationContext.DisplayName)); - // additional check for strings so they're not empty + // Additional check for strings so they're not empty if (value is string val && val.Trim().Length == 0) return new ValidationResult(FormatErrorMessage(validationContext.DisplayName)); } diff --git a/src/BaGet.Core/Configuration/ValidatePostConfigureOptions.cs b/src/BaGet.Core/Validation/ValidatePostConfigureOptions.cs similarity index 98% rename from src/BaGet.Core/Configuration/ValidatePostConfigureOptions.cs rename to src/BaGet.Core/Validation/ValidatePostConfigureOptions.cs index c62905e0e..cd4676148 100644 --- a/src/BaGet.Core/Configuration/ValidatePostConfigureOptions.cs +++ b/src/BaGet.Core/Validation/ValidatePostConfigureOptions.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; using Microsoft.Extensions.Options; -namespace BaGet.Core.Configuration +namespace BaGet.Core { /// /// A configuration that validates options using data annotations. diff --git a/src/BaGet.Database.MySql/MySqlContext.cs b/src/BaGet.Database.MySql/MySqlContext.cs index f8fe425fc..49bbb65fb 100644 --- a/src/BaGet.Database.MySql/MySqlContext.cs +++ b/src/BaGet.Database.MySql/MySqlContext.cs @@ -1,4 +1,4 @@ -using BaGet.Core.Entities; +using BaGet.Core; using Microsoft.EntityFrameworkCore; using MySql.Data.MySqlClient; diff --git a/src/BaGet.Database.PostgreSql/PostgreSqlContext.cs b/src/BaGet.Database.PostgreSql/PostgreSqlContext.cs index c8d6b63ef..542630994 100644 --- a/src/BaGet.Database.PostgreSql/PostgreSqlContext.cs +++ b/src/BaGet.Database.PostgreSql/PostgreSqlContext.cs @@ -1,4 +1,4 @@ -using BaGet.Core.Entities; +using BaGet.Core; using Microsoft.EntityFrameworkCore; using Npgsql; diff --git a/src/BaGet.Database.SqlServer/SqlServerContext.cs b/src/BaGet.Database.SqlServer/SqlServerContext.cs index fa63c2d82..b7f34c1a0 100644 --- a/src/BaGet.Database.SqlServer/SqlServerContext.cs +++ b/src/BaGet.Database.SqlServer/SqlServerContext.cs @@ -1,6 +1,6 @@ using System.Data.SqlClient; using System.Linq; -using BaGet.Core.Entities; +using BaGet.Core; using Microsoft.EntityFrameworkCore; namespace BaGet.Database.SqlServer diff --git a/src/BaGet.Database.Sqlite/SqliteContext.cs b/src/BaGet.Database.Sqlite/SqliteContext.cs index 44649b4a1..e2e3c672f 100644 --- a/src/BaGet.Database.Sqlite/SqliteContext.cs +++ b/src/BaGet.Database.Sqlite/SqliteContext.cs @@ -1,4 +1,4 @@ -using BaGet.Core.Entities; +using BaGet.Core; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; diff --git a/src/BaGet.Gcp/Configuration/GoogleCloudStorageOptions.cs b/src/BaGet.Gcp/Configuration/GoogleCloudStorageOptions.cs index 548b16a5e..3aa4ab220 100644 --- a/src/BaGet.Gcp/Configuration/GoogleCloudStorageOptions.cs +++ b/src/BaGet.Gcp/Configuration/GoogleCloudStorageOptions.cs @@ -1,5 +1,5 @@ using System.ComponentModel.DataAnnotations; -using BaGet.Core.Configuration; +using BaGet.Core; namespace BaGet.Gcp.Configuration { diff --git a/src/BaGet.Gcp/Services/GoogleCloudStorageService.cs b/src/BaGet.Gcp/Services/GoogleCloudStorageService.cs index 2d9fce507..b0c318508 100644 --- a/src/BaGet.Gcp/Services/GoogleCloudStorageService.cs +++ b/src/BaGet.Gcp/Services/GoogleCloudStorageService.cs @@ -5,7 +5,7 @@ using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Storage; +using BaGet.Core; using BaGet.Gcp.Configuration; using Google; using Google.Cloud.Storage.V1; diff --git a/src/BaGet.Protocol/Catalog/CatalogClient.cs b/src/BaGet.Protocol/Catalog/CatalogClient.cs index 61135d699..ec5759e07 100644 --- a/src/BaGet.Protocol/Catalog/CatalogClient.cs +++ b/src/BaGet.Protocol/Catalog/CatalogClient.cs @@ -1,68 +1,45 @@ using System; -using System.Net.Http; using System.Threading; using System.Threading.Tasks; using BaGet.Protocol.Models; namespace BaGet.Protocol.Internal { - public class CatalogClient : ICatalogResource + public class CatalogClient : ICatalogClient { - private readonly HttpClient _httpClient; - private readonly string _catalogUrl; + private readonly NuGetClientFactory _clientfactory; - public CatalogClient(HttpClient httpClient, string catalogUrl) + public CatalogClient(NuGetClientFactory clientFactory) { - _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); - _catalogUrl = catalogUrl ?? throw new ArgumentNullException(nameof(catalogUrl)); + _clientfactory = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory)); } public async Task GetIndexAsync(CancellationToken cancellationToken = default) { - var response = await _httpClient.DeserializeUrlAsync(_catalogUrl, cancellationToken); + var client = await _clientfactory.CreateCatalogClientAsync(cancellationToken); - return response.GetResultOrThrow(); + return await client.GetIndexAsync(cancellationToken); } public async Task GetPageAsync(string pageUrl, CancellationToken cancellationToken = default) { - var response = await _httpClient.DeserializeUrlAsync(pageUrl, cancellationToken); + var client = await _clientfactory.CreateCatalogClientAsync(cancellationToken); - return response.GetResultOrThrow(); - } - - public async Task GetPackageDeleteLeafAsync(string leafUrl, CancellationToken cancellationToken = default) - { - return await GetAndValidateLeafAsync( - CatalogLeafType.PackageDelete, - leafUrl, - cancellationToken); + return await client.GetPageAsync(pageUrl, cancellationToken); } public async Task GetPackageDetailsLeafAsync(string leafUrl, CancellationToken cancellationToken = default) { - return await GetAndValidateLeafAsync( - CatalogLeafType.PackageDetails, - leafUrl, - cancellationToken); + var client = await _clientfactory.CreateCatalogClientAsync(cancellationToken); + + return await client.GetPackageDetailsLeafAsync(leafUrl, cancellationToken); } - private async Task GetAndValidateLeafAsync( - CatalogLeafType type, - string leafUrl, - CancellationToken cancellationToken) where T : CatalogLeaf + public async Task GetPackageDeleteLeafAsync(string leafUrl, CancellationToken cancellationToken = default) { - var result = await _httpClient.DeserializeUrlAsync(leafUrl, cancellationToken); - var leaf = result.GetResultOrThrow(); - - if (leaf.Type != type) - { - throw new ArgumentException( - $"The leaf type found in the document does not match the expected '{type}' type.", - nameof(type)); - } + var client = await _clientfactory.CreateCatalogClientAsync(cancellationToken); - return leaf; + return await client.GetPackageDeleteLeafAsync(leafUrl, cancellationToken); } } } diff --git a/src/BaGet.Protocol/Catalog/CatalogProcessor.cs b/src/BaGet.Protocol/Catalog/CatalogProcessor.cs index 59a938adc..684d6ddb4 100644 --- a/src/BaGet.Protocol/Catalog/CatalogProcessor.cs +++ b/src/BaGet.Protocol/Catalog/CatalogProcessor.cs @@ -14,7 +14,7 @@ namespace BaGet.Protocol.Catalog public class CatalogProcessor { private readonly ICatalogLeafProcessor _leafProcessor; - private readonly ICatalogResource _client; + private readonly ICatalogClient _client; private readonly ICursor _cursor; private readonly CatalogProcessorOptions _options; private readonly ILogger _logger; @@ -30,7 +30,7 @@ public class CatalogProcessor /// The logger used for telemetry. public CatalogProcessor( ICursor cursor, - ICatalogResource client, + ICatalogClient client, ICatalogLeafProcessor leafProcessor, CatalogProcessorOptions options, ILogger logger) diff --git a/src/BaGet.Protocol/Catalog/ICatalogResource.cs b/src/BaGet.Protocol/Catalog/ICatalogClient.cs similarity index 93% rename from src/BaGet.Protocol/Catalog/ICatalogResource.cs rename to src/BaGet.Protocol/Catalog/ICatalogClient.cs index 7c1aafe87..65dbb4604 100644 --- a/src/BaGet.Protocol/Catalog/ICatalogResource.cs +++ b/src/BaGet.Protocol/Catalog/ICatalogClient.cs @@ -5,11 +5,12 @@ namespace BaGet.Protocol { /// - /// The Catalog resource that records all package operations. + /// The Catalog client, used to discover package events. /// You can use this resource to query for all published packages. - /// See: https://docs.microsoft.com/en-us/nuget/api/catalog-resource + /// + /// See https://docs.microsoft.com/en-us/nuget/api/catalog-resource /// - public interface ICatalogResource + public interface ICatalogClient { /// /// Get the entry point for the catalog resource. diff --git a/src/BaGet.Protocol/Catalog/RawCatalogClient.cs b/src/BaGet.Protocol/Catalog/RawCatalogClient.cs new file mode 100644 index 000000000..e5feb6572 --- /dev/null +++ b/src/BaGet.Protocol/Catalog/RawCatalogClient.cs @@ -0,0 +1,68 @@ +using System; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using BaGet.Protocol.Models; + +namespace BaGet.Protocol.Internal +{ + public class RawCatalogClient : ICatalogClient + { + private readonly HttpClient _httpClient; + private readonly string _catalogUrl; + + public RawCatalogClient(HttpClient httpClient, string catalogUrl) + { + _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); + _catalogUrl = catalogUrl ?? throw new ArgumentNullException(nameof(catalogUrl)); + } + + public async Task GetIndexAsync(CancellationToken cancellationToken = default) + { + var response = await _httpClient.DeserializeUrlAsync(_catalogUrl, cancellationToken); + + return response.GetResultOrThrow(); + } + + public async Task GetPageAsync(string pageUrl, CancellationToken cancellationToken = default) + { + var response = await _httpClient.DeserializeUrlAsync(pageUrl, cancellationToken); + + return response.GetResultOrThrow(); + } + + public async Task GetPackageDeleteLeafAsync(string leafUrl, CancellationToken cancellationToken = default) + { + return await GetAndValidateLeafAsync( + CatalogLeafType.PackageDelete, + leafUrl, + cancellationToken); + } + + public async Task GetPackageDetailsLeafAsync(string leafUrl, CancellationToken cancellationToken = default) + { + return await GetAndValidateLeafAsync( + CatalogLeafType.PackageDetails, + leafUrl, + cancellationToken); + } + + private async Task GetAndValidateLeafAsync( + CatalogLeafType type, + string leafUrl, + CancellationToken cancellationToken) where T : CatalogLeaf + { + var result = await _httpClient.DeserializeUrlAsync(leafUrl, cancellationToken); + var leaf = result.GetResultOrThrow(); + + if (leaf.Type != type) + { + throw new ArgumentException( + $"The leaf type found in the document does not match the expected '{type}' type.", + nameof(type)); + } + + return leaf; + } + } +} diff --git a/src/BaGet.Protocol/Extensions/ServiceIndexModelExtensions.cs b/src/BaGet.Protocol/Extensions/ServiceIndexModelExtensions.cs index ad47d7418..12662da51 100644 --- a/src/BaGet.Protocol/Extensions/ServiceIndexModelExtensions.cs +++ b/src/BaGet.Protocol/Extensions/ServiceIndexModelExtensions.cs @@ -14,18 +14,17 @@ public static class ServiceIndexModelExtensions private static readonly string Version300 = "/3.0.0"; private static readonly string Version340 = "/3.4.0"; private static readonly string Version360 = "/3.6.0"; - private static readonly string Versioned = "/Versioned"; private static readonly string Version470 = "/4.7.0"; private static readonly string Version490 = "/4.9.0"; private static readonly string[] Catalog = { "Catalog" + Version300 }; - private static readonly string[] SearchQueryService = { "SearchQueryService" + Versioned, "SearchQueryService" + Version340, "SearchQueryService" + Version300beta }; - private static readonly string[] RegistrationsBaseUrl = { "RegistrationsBaseUrl" + Versioned, "RegistrationsBaseUrl" + Version360, "RegistrationsBaseUrl" + Version340, "RegistrationsBaseUrl" + Version300beta }; - private static readonly string[] SearchAutocompleteService = { "SearchAutocompleteService" + Versioned, "SearchAutocompleteService" + Version300beta }; - private static readonly string[] ReportAbuse = { "ReportAbuseUriTemplate" + Versioned, "ReportAbuseUriTemplate" + Version300 }; - private static readonly string[] LegacyGallery = { "LegacyGallery" + Versioned, "LegacyGallery" + Version200 }; - private static readonly string[] PackagePublish = { "PackagePublish" + Versioned, "PackagePublish" + Version200 }; - private static readonly string[] PackageBaseAddress = { "PackageBaseAddress" + Versioned, "PackageBaseAddress" + Version300 }; + private static readonly string[] SearchQueryService = { "SearchQueryService", "SearchQueryService" + Version340, "SearchQueryService" + Version300beta }; + private static readonly string[] RegistrationsBaseUrl = { "RegistrationsBaseUrl", "RegistrationsBaseUrl" + Version360, "RegistrationsBaseUrl" + Version340, "RegistrationsBaseUrl" + Version300beta }; + private static readonly string[] SearchAutocompleteService = { "SearchAutocompleteService", "SearchAutocompleteService" + Version300beta }; + private static readonly string[] ReportAbuse = { "ReportAbuseUriTemplate", "ReportAbuseUriTemplate" + Version300 }; + private static readonly string[] LegacyGallery = { "LegacyGallery" + Version200 }; + private static readonly string[] PackagePublish = { "PackagePublish" + Version200 }; + private static readonly string[] PackageBaseAddress = { "PackageBaseAddress" + Version300 }; private static readonly string[] RepositorySignatures = { "RepositorySignatures" + Version490, "RepositorySignatures" + Version470 }; private static readonly string[] SymbolPackagePublish = { "SymbolPackagePublish" + Version490 }; diff --git a/src/BaGet.Protocol/NuGetClient.cs b/src/BaGet.Protocol/NuGetClient.cs index c902c46de..198cd8e04 100644 --- a/src/BaGet.Protocol/NuGetClient.cs +++ b/src/BaGet.Protocol/NuGetClient.cs @@ -167,10 +167,8 @@ public virtual async Task> GetPackageMetadataAsyn var items = registrationIndexPage.ItemsOrNull; if (items == null) { - var externalRegistrationPage = await client.GetRegistrationPageOrNullAsync( - packageId, - registrationIndexPage.ParseLower(), - registrationIndexPage.ParseUpper(), + var externalRegistrationPage = await client.GetRegistrationPageAsync( + registrationIndexPage.RegistrationPageUrl, cancellationToken); // Skip malformed external pages. @@ -220,10 +218,8 @@ public virtual async Task GetPackageMetadataAsync(string packag var items = registrationIndexPage.ItemsOrNull; if (items == null) { - var externalRegistrationPage = await client.GetRegistrationPageOrNullAsync( - packageId, - pageLowerVersion, - pageUpperVersion, + var externalRegistrationPage = await client.GetRegistrationPageAsync( + registrationIndexPage.RegistrationPageUrl, cancellationToken); // Skip malformed external pages. diff --git a/src/BaGet.Protocol/NuGetClientFactory.cs b/src/BaGet.Protocol/NuGetClientFactory.cs index 6dd53f8ff..dcd8d9107 100644 --- a/src/BaGet.Protocol/NuGetClientFactory.cs +++ b/src/BaGet.Protocol/NuGetClientFactory.cs @@ -50,7 +50,7 @@ public NuGetClientFactory(HttpClient httpClient, string serviceIndexUrl) /// See https://docs.microsoft.com/en-us/nuget/api/service-index /// /// A client to interact with the NuGet Service Index resource. - public virtual Task CreateServiceIndexClientAsync(CancellationToken cancellationToken = default) + public virtual Task CreateServiceIndexClientAsync(CancellationToken cancellationToken = default) { return GetClientAsync(c => c.ServiceIndexClient, cancellationToken); } @@ -61,7 +61,7 @@ public virtual Task CreateServiceIndexClientAsync(Cancell /// See https://docs.microsoft.com/en-us/nuget/api/package-base-address-resource /// /// A client to interact with the NuGet Package Content resource. - public virtual Task CreatePackageContentClientAsync(CancellationToken cancellationToken = default) + public virtual Task CreatePackageContentClientAsync(CancellationToken cancellationToken = default) { return GetClientAsync(c => c.PackageContentClient, cancellationToken); } @@ -72,7 +72,7 @@ public virtual Task CreatePackageContentClientAsync(Can /// See https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource /// /// A client to interact with the NuGet Package Metadata resource. - public virtual Task CreatePackageMetadataClientAsync(CancellationToken cancellationToken = default) + public virtual Task CreatePackageMetadataClientAsync(CancellationToken cancellationToken = default) { return GetClientAsync(c => c.PackageMetadataClient, cancellationToken); } @@ -83,10 +83,8 @@ public virtual Task CreatePackageMetadataClientAsync(C /// See https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource /// /// A client to interact with the NuGet Search resource. - public virtual Task CreateSearchClientAsync(CancellationToken cancellationToken = default) + public virtual Task CreateSearchClientAsync(CancellationToken cancellationToken = default) { - // TODO: There are multiple search endpoints to support high read availability. - // This factory should create a search client that uses all these endpoints. return GetClientAsync(c => c.SearchClient, cancellationToken); } @@ -96,7 +94,7 @@ public virtual Task CreateSearchClientAsync(CancellationToken c /// See https://docs.microsoft.com/en-us/nuget/api/catalog-resource /// /// A client to interact with the Catalog resource. - public virtual Task CreateCatalogClientAsync(CancellationToken cancellationToken = default) + public virtual Task CreateCatalogClientAsync(CancellationToken cancellationToken = default) { return GetClientAsync(c => c.CatalogClient, cancellationToken); } @@ -115,10 +113,10 @@ private async Task GetClientAsync(Func clientFactory, Can var serviceIndex = await serviceIndexClient.GetAsync(cancellationToken); - var contentClient = new PackageContentClient(_httpClient, serviceIndex.GetPackageContentResourceUrl()); - var metadataClient = new PackageMetadataClient(_httpClient, serviceIndex.GetPackageMetadataResourceUrl()); - var catalogClient = new CatalogClient(_httpClient, serviceIndex.GetCatalogResourceUrl()); - var searchClient = new SearchClient(_httpClient, + var contentClient = new RawPackageContentClient(_httpClient, serviceIndex.GetPackageContentResourceUrl()); + var metadataClient = new RawPackageMetadataClient(_httpClient, serviceIndex.GetPackageMetadataResourceUrl()); + var catalogClient = new RawCatalogClient(_httpClient, serviceIndex.GetCatalogResourceUrl()); + var searchClient = new RawSearchClient(_httpClient, serviceIndex.GetSearchQueryResourceUrl(), serviceIndex.GetSearchAutocompleteResourceUrl()); @@ -144,11 +142,11 @@ private async Task GetClientAsync(Func clientFactory, Can private class NuGetClients { - public IServiceIndexResource ServiceIndexClient { get; set; } - public IPackageContentResource PackageContentClient { get; set; } - public IPackageMetadataResource PackageMetadataClient { get; set; } - public ISearchResource SearchClient { get; set; } - public ICatalogResource CatalogClient { get; set; } + public IServiceIndexClient ServiceIndexClient { get; set; } + public IPackageContentClient PackageContentClient { get; set; } + public IPackageMetadataClient PackageMetadataClient { get; set; } + public ISearchClient SearchClient { get; set; } + public ICatalogClient CatalogClient { get; set; } } } } diff --git a/src/BaGet.Protocol/PackageContent/IPackageContentResource.cs b/src/BaGet.Protocol/PackageContent/IPackageContentClient.cs similarity index 98% rename from src/BaGet.Protocol/PackageContent/IPackageContentResource.cs rename to src/BaGet.Protocol/PackageContent/IPackageContentClient.cs index c7bf5027d..12321b449 100644 --- a/src/BaGet.Protocol/PackageContent/IPackageContentResource.cs +++ b/src/BaGet.Protocol/PackageContent/IPackageContentClient.cs @@ -8,9 +8,10 @@ namespace BaGet.Protocol { /// /// The Package Content resource, used to download NuGet packages and to fetch other metadata. + /// /// See: https://docs.microsoft.com/en-us/nuget/api/package-base-address-resource /// - public interface IPackageContentResource + public interface IPackageContentClient { /// /// Get a package's versions, or null if the package does not exist. diff --git a/src/BaGet.Protocol/PackageContent/PackageContentClient.cs b/src/BaGet.Protocol/PackageContent/PackageContentClient.cs index d1f3e3cee..0af177426 100644 --- a/src/BaGet.Protocol/PackageContent/PackageContentClient.cs +++ b/src/BaGet.Protocol/PackageContent/PackageContentClient.cs @@ -1,7 +1,5 @@ using System; using System.IO; -using System.Net; -using System.Net.Http; using System.Threading; using System.Threading.Tasks; using BaGet.Protocol.Models; @@ -9,84 +7,42 @@ namespace BaGet.Protocol.Internal { - /// - /// The client to interact with an upstream source's Package Content resource. - /// - public class PackageContentClient : IPackageContentResource + public class PackageContentClient : IPackageContentClient { - private readonly HttpClient _httpClient; - private readonly string _packageContentUrl; + private readonly NuGetClientFactory _clientfactory; - /// - /// Create a new Package Content client. - /// - /// The HTTP client used to send requests. - /// The NuGet Server's package content URL. - public PackageContentClient(HttpClient httpClient, string packageContentUrl) + public PackageContentClient(NuGetClientFactory clientFactory) { - _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); - _packageContentUrl = packageContentUrl?.TrimEnd('/') - ?? throw new ArgumentNullException(nameof(packageContentUrl)); + _clientfactory = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory)); } - /// - public async Task GetPackageVersionsOrNullAsync( + public async Task GetPackageContentStreamOrNullAsync( string packageId, + NuGetVersion packageVersion, CancellationToken cancellationToken = default) { - var id = packageId.ToLowerInvariant(); - - var url = $"{_packageContentUrl}/{id}/index.json"; - var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); + var client = await _clientfactory.CreatePackageContentClientAsync(cancellationToken); - if (response.StatusCode == HttpStatusCode.NotFound) - { - return null; - } - - return response.GetResultOrThrow(); + return await client.GetPackageContentStreamOrNullAsync(packageId, packageVersion, cancellationToken); } - /// - public async Task GetPackageContentStreamOrNullAsync( + public async Task GetPackageManifestStreamOrNullAsync( string packageId, NuGetVersion packageVersion, CancellationToken cancellationToken = default) { - var id = packageId.ToLowerInvariant(); - var version = packageVersion.ToNormalizedString().ToLowerInvariant(); + var client = await _clientfactory.CreatePackageContentClientAsync(cancellationToken); - // The response will be disposed when the returned content stream is disposed. - var url = $"{_packageContentUrl}/{id}/{version}/{id}.{version}.nupkg"; - var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken); - - if (response.StatusCode == HttpStatusCode.NotFound) - { - return null; - } - - return await response.Content.ReadAsStreamAsync(); + return await client.GetPackageManifestStreamOrNullAsync(packageId, packageVersion, cancellationToken); } - /// - public async Task GetPackageManifestStreamOrNullAsync( + public async Task GetPackageVersionsOrNullAsync( string packageId, - NuGetVersion packageVersion, CancellationToken cancellationToken = default) { - var id = packageId.ToLowerInvariant(); - var version = packageVersion.ToNormalizedString().ToLowerInvariant(); - - // The response will be disposed when the returned content stream is disposed. - var url = $"{_packageContentUrl}/{id}/{version}/{id}.nuspec"; - var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken); - - if (response.StatusCode == HttpStatusCode.NotFound) - { - return null; - } + var client = await _clientfactory.CreatePackageContentClientAsync(cancellationToken); - return await response.Content.ReadAsStreamAsync(); + return await client.GetPackageVersionsOrNullAsync(packageId, cancellationToken); } } } diff --git a/src/BaGet.Protocol/PackageContent/RawPackageContentClient.cs b/src/BaGet.Protocol/PackageContent/RawPackageContentClient.cs new file mode 100644 index 000000000..15db69e90 --- /dev/null +++ b/src/BaGet.Protocol/PackageContent/RawPackageContentClient.cs @@ -0,0 +1,92 @@ +using System; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using BaGet.Protocol.Models; +using NuGet.Versioning; + +namespace BaGet.Protocol.Internal +{ + /// + /// The client to interact with an upstream source's Package Content resource. + /// + public class RawPackageContentClient : IPackageContentClient + { + private readonly HttpClient _httpClient; + private readonly string _packageContentUrl; + + /// + /// Create a new Package Content client. + /// + /// The HTTP client used to send requests. + /// The NuGet Server's package content URL. + public RawPackageContentClient(HttpClient httpClient, string packageContentUrl) + { + _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); + _packageContentUrl = packageContentUrl?.TrimEnd('/') + ?? throw new ArgumentNullException(nameof(packageContentUrl)); + } + + /// + public async Task GetPackageVersionsOrNullAsync( + string packageId, + CancellationToken cancellationToken = default) + { + var id = packageId.ToLowerInvariant(); + + var url = $"{_packageContentUrl}/{id}/index.json"; + var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); + + if (response.StatusCode == HttpStatusCode.NotFound) + { + return null; + } + + return response.GetResultOrThrow(); + } + + /// + public async Task GetPackageContentStreamOrNullAsync( + string packageId, + NuGetVersion packageVersion, + CancellationToken cancellationToken = default) + { + var id = packageId.ToLowerInvariant(); + var version = packageVersion.ToNormalizedString().ToLowerInvariant(); + + // The response will be disposed when the returned content stream is disposed. + var url = $"{_packageContentUrl}/{id}/{version}/{id}.{version}.nupkg"; + var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken); + + if (response.StatusCode == HttpStatusCode.NotFound) + { + return null; + } + + return await response.Content.ReadAsStreamAsync(); + } + + /// + public async Task GetPackageManifestStreamOrNullAsync( + string packageId, + NuGetVersion packageVersion, + CancellationToken cancellationToken = default) + { + var id = packageId.ToLowerInvariant(); + var version = packageVersion.ToNormalizedString().ToLowerInvariant(); + + // The response will be disposed when the returned content stream is disposed. + var url = $"{_packageContentUrl}/{id}/{version}/{id}.nuspec"; + var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken); + + if (response.StatusCode == HttpStatusCode.NotFound) + { + return null; + } + + return await response.Content.ReadAsStreamAsync(); + } + } +} diff --git a/src/BaGet.Protocol/PackageMetadata/IPackageMetadataResource.cs b/src/BaGet.Protocol/PackageMetadata/IPackageMetadataClient.cs similarity index 71% rename from src/BaGet.Protocol/PackageMetadata/IPackageMetadataResource.cs rename to src/BaGet.Protocol/PackageMetadata/IPackageMetadataClient.cs index 18187d236..ee18e941f 100644 --- a/src/BaGet.Protocol/PackageMetadata/IPackageMetadataResource.cs +++ b/src/BaGet.Protocol/PackageMetadata/IPackageMetadataClient.cs @@ -6,10 +6,11 @@ namespace BaGet.Protocol { /// - /// The Package Metadata resource, used to fetch packages' metadata. - /// See: https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource + /// The Package Metadata client, used to fetch packages' metadata. + /// + /// See https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource /// - public interface IPackageMetadataResource + public interface IPackageMetadataClient { /// /// Attempt to get a package's registration index, if it exists. @@ -21,18 +22,14 @@ public interface IPackageMetadataResource Task GetRegistrationIndexOrNullAsync(string packageId, CancellationToken cancellationToken = default); /// - /// Get a page that was linked by the package's registration index, if it exists. + /// Get a page that was linked from the package's registration index. /// See: https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#registration-page /// - /// The package's id. - /// The lowest SemVer 2.0.0 version in the page (inclusive). - /// The highest SemVer 2.0.0 version in the page (inclusive). + /// The URL of the page, from the . /// A token to cancel the task. /// The registration index page, or null if the page does not exist. - Task GetRegistrationPageOrNullAsync( - string packageId, - NuGetVersion lower, - NuGetVersion upper, + Task GetRegistrationPageAsync( + string pageUrl, CancellationToken cancellationToken = default); /// diff --git a/src/BaGet.Protocol/PackageMetadata/PackageMetadataClient.cs b/src/BaGet.Protocol/PackageMetadata/PackageMetadataClient.cs index 679f51085..5c6c6ae1f 100644 --- a/src/BaGet.Protocol/PackageMetadata/PackageMetadataClient.cs +++ b/src/BaGet.Protocol/PackageMetadata/PackageMetadataClient.cs @@ -1,6 +1,4 @@ using System; -using System.Net; -using System.Net.Http; using System.Threading; using System.Threading.Tasks; using BaGet.Protocol.Models; @@ -8,82 +6,41 @@ namespace BaGet.Protocol.Internal { - /// - /// The client to interact with an upstream source's Package Metadata resource. - /// - public class PackageMetadataClient : IPackageMetadataResource + public class PackageMetadataClient : IPackageMetadataClient { - private readonly HttpClient _httpClient; - private readonly string _packageMetadataUrl; + private readonly NuGetClientFactory _clientfactory; - /// - /// Create a new Package Metadata client. - /// - /// The HTTP client used to send requests. - /// The NuGet server's registration resource URL. - public PackageMetadataClient(HttpClient httpClient, string registrationBaseUrl) + public PackageMetadataClient(NuGetClientFactory clientFactory) { - _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); - _packageMetadataUrl = registrationBaseUrl.TrimEnd('/') - ?? throw new ArgumentNullException(nameof(registrationBaseUrl)); + _clientfactory = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory)); } - /// public async Task GetRegistrationIndexOrNullAsync( string packageId, CancellationToken cancellationToken = default) { - var url = $"{_packageMetadataUrl}/{packageId.ToLowerInvariant()}/index.json"; - var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); + var client = await _clientfactory.CreatePackageMetadataClientAsync(cancellationToken); - if (response.StatusCode == HttpStatusCode.NotFound) - { - return null; - } - - return response.GetResultOrThrow(); + return await client.GetRegistrationIndexOrNullAsync(packageId, cancellationToken); } - /// - public async Task GetRegistrationPageOrNullAsync( - string packageId, - NuGetVersion lower, - NuGetVersion upper, + public async Task GetRegistrationPageAsync( + string pageUrl, CancellationToken cancellationToken = default) { - var id = packageId.ToLowerInvariant(); - var lowerVersion = lower.ToNormalizedString().ToLowerInvariant(); - var upperVersion = upper.ToNormalizedString().ToLowerInvariant(); - - var url = $"{_packageMetadataUrl}/{id}/page/{lowerVersion}/{upperVersion}.json"; - var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); + var client = await _clientfactory.CreatePackageMetadataClientAsync(cancellationToken); - if (response.StatusCode == HttpStatusCode.NotFound) - { - return null; - } - - return response.GetResultOrThrow(); + return await client.GetRegistrationPageAsync(pageUrl, cancellationToken); } - /// public async Task GetRegistrationLeafOrNullAsync( string packageId, NuGetVersion packageVersion, CancellationToken cancellationToken = default) { - var id = packageId.ToLowerInvariant(); - var version = packageVersion.ToNormalizedString().ToLowerInvariant(); - - var url = $"{_packageMetadataUrl}/{id}/{version}.json"; - var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); - - if (response.StatusCode == HttpStatusCode.NotFound) - { - return null; - } + var client = await _clientfactory.CreatePackageMetadataClientAsync(cancellationToken); - return response.GetResultOrThrow(); + return await client.GetRegistrationLeafOrNullAsync(packageId, packageVersion, cancellationToken); } } } diff --git a/src/BaGet.Protocol/PackageMetadata/RawPackageMetadataClient.cs b/src/BaGet.Protocol/PackageMetadata/RawPackageMetadataClient.cs new file mode 100644 index 000000000..53fd02ede --- /dev/null +++ b/src/BaGet.Protocol/PackageMetadata/RawPackageMetadataClient.cs @@ -0,0 +1,76 @@ +using System; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using BaGet.Protocol.Models; +using NuGet.Versioning; + +namespace BaGet.Protocol.Internal +{ + /// + /// The client to interact with an upstream source's Package Metadata resource. + /// + public class RawPackageMetadataClient : IPackageMetadataClient + { + private readonly HttpClient _httpClient; + private readonly string _packageMetadataUrl; + + /// + /// Create a new Package Metadata client. + /// + /// The HTTP client used to send requests. + /// The NuGet server's registration resource URL. + public RawPackageMetadataClient(HttpClient httpClient, string registrationBaseUrl) + { + _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); + _packageMetadataUrl = registrationBaseUrl ?? throw new ArgumentNullException(nameof(registrationBaseUrl)); + } + + /// + public async Task GetRegistrationIndexOrNullAsync( + string packageId, + CancellationToken cancellationToken = default) + { + var url = $"{_packageMetadataUrl}/{packageId.ToLowerInvariant()}/index.json"; + var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); + + if (response.StatusCode == HttpStatusCode.NotFound) + { + return null; + } + + return response.GetResultOrThrow(); + } + + /// + public async Task GetRegistrationPageAsync( + string pageUrl, + CancellationToken cancellationToken = default) + { + var response = await _httpClient.DeserializeUrlAsync(pageUrl, cancellationToken); + + return response.GetResultOrThrow(); + } + + /// + public async Task GetRegistrationLeafOrNullAsync( + string packageId, + NuGetVersion packageVersion, + CancellationToken cancellationToken = default) + { + var id = packageId.ToLowerInvariant(); + var version = packageVersion.ToNormalizedString().ToLowerInvariant(); + + var url = $"{_packageMetadataUrl}/{id}/{version}.json"; + var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); + + if (response.StatusCode == HttpStatusCode.NotFound) + { + return null; + } + + return response.GetResultOrThrow(); + } + } +} diff --git a/src/BaGet.Protocol/Search/ISearchResource.cs b/src/BaGet.Protocol/Search/ISearchClient.cs similarity index 92% rename from src/BaGet.Protocol/Search/ISearchResource.cs rename to src/BaGet.Protocol/Search/ISearchClient.cs index ecbca02a4..ccaa691ab 100644 --- a/src/BaGet.Protocol/Search/ISearchResource.cs +++ b/src/BaGet.Protocol/Search/ISearchClient.cs @@ -5,10 +5,11 @@ namespace BaGet.Protocol { /// - /// The resource used to search for packages. - /// See: https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource + /// The client used to search for packages. + /// + /// See https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource /// - public interface ISearchResource + public interface ISearchClient { /// /// Perform a search query. diff --git a/src/BaGet.Protocol/Search/RawSearchClient.cs b/src/BaGet.Protocol/Search/RawSearchClient.cs new file mode 100644 index 000000000..9bc19a9fe --- /dev/null +++ b/src/BaGet.Protocol/Search/RawSearchClient.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading; +using System.Threading.Tasks; +using BaGet.Protocol.Models; + +namespace BaGet.Protocol.Internal +{ + /// + /// The client used to search for packages. + /// + /// See https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource + /// + public class RawSearchClient : ISearchClient + { + private readonly HttpClient _httpClient; + private readonly string _searchUrl; + private readonly string _autocompleteUrl; + + /// + /// Create a new Search client. + /// + /// The HTTP client used to send requests. + /// The NuGet server's search URL. + /// The NuGet server's autocomplete URL. + public RawSearchClient(HttpClient httpClient, string searchUrl, string autocompleteUrl) + { + _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); + _searchUrl = searchUrl ?? throw new ArgumentNullException(nameof(searchUrl)); + _autocompleteUrl = autocompleteUrl ?? throw new ArgumentNullException(nameof(autocompleteUrl)); + } + + public async Task AutocompleteAsync( + string query = null, + AutocompleteType type = AutocompleteType.PackageIds, + int skip = 0, + int take = 20, + bool includePrerelease = true, + bool includeSemVer2 = true, + CancellationToken cancellationToken = default) + { + var param = (type == AutocompleteType.PackageIds) ? "q" : "id"; + var url = AddSearchQueryString(_autocompleteUrl, query, skip, take, includePrerelease, includeSemVer2, param); + + var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); + + return response.GetResultOrThrow(); + } + + public async Task SearchAsync( + string query = null, + int skip = 0, + int take = 20, + bool includePrerelease = true, + bool includeSemVer2 = true, + CancellationToken cancellationToken = default) + { + var url = AddSearchQueryString(_searchUrl, query, skip, take, includePrerelease, includeSemVer2, "q"); + + var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); + + return response.GetResultOrThrow(); + } + + private string AddSearchQueryString( + string uri, + string query, + int skip, + int take, + bool includePrerelease, + bool includeSemVer2, + string queryParamName) + { + var queryString = new Dictionary(); + + if (skip != 0) queryString["skip"] = skip.ToString(); + if (take != 0) queryString["take"] = take.ToString(); + if (includePrerelease) queryString["prerelease"] = true.ToString(); + if (includeSemVer2) queryString["semVerLevel"] = "2.0.0"; + + if (!string.IsNullOrEmpty(query)) + { + queryString[queryParamName] = query; + } + + return AddQueryString(uri, queryString); + } + + // See: https://github.com/aspnet/AspNetCore/blob/8c02467b4a218df3b1b0a69bceb50f5b64f482b1/src/Http/WebUtilities/src/QueryHelpers.cs#L63 + private string AddQueryString(string uri, Dictionary queryString) + { + if (uri.IndexOf('#') != -1) throw new InvalidOperationException("URL anchors are not supported"); + if (uri.IndexOf('?') != -1) throw new InvalidOperationException("Adding query strings to URL with query strings is not supported"); + + var builder = new StringBuilder(uri); + var hasQuery = false; + + foreach (var parameter in queryString) + { + builder.Append(hasQuery ? '&' : '?'); + builder.Append(UrlEncoder.Default.Encode(parameter.Key)); + builder.Append('='); + builder.Append(UrlEncoder.Default.Encode(parameter.Value)); + hasQuery = true; + } + + return builder.ToString(); + } + } +} diff --git a/src/BaGet.Protocol/Search/SearchClient.cs b/src/BaGet.Protocol/Search/SearchClient.cs index 8ffacfcfb..29b4c6460 100644 --- a/src/BaGet.Protocol/Search/SearchClient.cs +++ b/src/BaGet.Protocol/Search/SearchClient.cs @@ -1,37 +1,19 @@ using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Text; -using System.Text.Encodings.Web; using System.Threading; using System.Threading.Tasks; using BaGet.Protocol.Models; namespace BaGet.Protocol.Internal { - /// - /// The client to interact with an upstream source's Search resource. - /// - public class SearchClient : ISearchResource + public class SearchClient : ISearchClient { - private readonly HttpClient _httpClient; - private readonly string _searchUrl; - private readonly string _autocompleteUrl; + private readonly NuGetClientFactory _clientfactory; - /// - /// Create a new Search client. - /// - /// The HTTP client used to send requests. - /// The NuGet server's search URL. - /// The NuGet server's autocomplete URL. - public SearchClient(HttpClient httpClient, string searchUrl, string autocompleteUrl) + public SearchClient(NuGetClientFactory clientFactory) { - _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); - _searchUrl = searchUrl ?? throw new ArgumentNullException(nameof(searchUrl)); - _autocompleteUrl = autocompleteUrl ?? throw new ArgumentNullException(nameof(autocompleteUrl)); + _clientfactory = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory)); } - /// public async Task AutocompleteAsync( string query = null, AutocompleteType type = AutocompleteType.PackageIds, @@ -41,15 +23,13 @@ public async Task AutocompleteAsync( bool includeSemVer2 = true, CancellationToken cancellationToken = default) { - var param = (type == AutocompleteType.PackageIds) ? "q" : "id"; - var url = AddSearchQueryString(_autocompleteUrl, query, skip, take, includePrerelease, includeSemVer2, param); + // TODO: Support search failover. + // See: https://github.com/loic-sharma/BaGet/issues/314 + var client = await _clientfactory.CreateSearchClientAsync(cancellationToken); - var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); - - return response.GetResultOrThrow(); + return await client.AutocompleteAsync(query, type, skip, take, includePrerelease, includeSemVer2); } - /// public async Task SearchAsync( string query = null, int skip = 0, @@ -58,56 +38,11 @@ public async Task SearchAsync( bool includeSemVer2 = true, CancellationToken cancellationToken = default) { - var url = AddSearchQueryString(_searchUrl, query, skip, take, includePrerelease, includeSemVer2, "q"); - - var response = await _httpClient.DeserializeUrlAsync(url, cancellationToken); - - return response.GetResultOrThrow(); - } - - private string AddSearchQueryString( - string uri, - string query, - int skip, - int take, - bool includePrerelease, - bool includeSemVer2, - string queryParamName) - { - var queryString = new Dictionary(); - - if (skip != 0) queryString["skip"] = skip.ToString(); - if (take != 0) queryString["take"] = take.ToString(); - if (includePrerelease) queryString["prerelease"] = true.ToString(); - if (includeSemVer2) queryString["semVerLevel"] = "2.0.0"; - - if (!string.IsNullOrEmpty(query)) - { - queryString[queryParamName] = query; - } - - return AddQueryString(uri, queryString); - } - - // See: https://github.com/aspnet/AspNetCore/blob/8c02467b4a218df3b1b0a69bceb50f5b64f482b1/src/Http/WebUtilities/src/QueryHelpers.cs#L63 - private string AddQueryString(string uri, Dictionary queryString) - { - if (uri.IndexOf('#') != -1) throw new InvalidOperationException("URL anchors are not supported"); - if (uri.IndexOf('?') != -1) throw new InvalidOperationException("Adding query strings to URL with query strings is not supported"); - - var builder = new StringBuilder(uri); - var hasQuery = false; - - foreach (var parameter in queryString) - { - builder.Append(hasQuery ? '&' : '?'); - builder.Append(UrlEncoder.Default.Encode(parameter.Key)); - builder.Append('='); - builder.Append(UrlEncoder.Default.Encode(parameter.Value)); - hasQuery = true; - } + // TODO: Support search failover. + // See: https://github.com/loic-sharma/BaGet/issues/314 + var client = await _clientfactory.CreateSearchClientAsync(cancellationToken); - return builder.ToString(); + return await client.SearchAsync(query, skip, take, includePrerelease, includeSemVer2); } } } diff --git a/src/BaGet.Protocol/ServiceIndex/IServiceIndexResource.cs b/src/BaGet.Protocol/ServiceIndex/IServiceIndexClient.cs similarity index 73% rename from src/BaGet.Protocol/ServiceIndex/IServiceIndexResource.cs rename to src/BaGet.Protocol/ServiceIndex/IServiceIndexClient.cs index c342934bd..73fc2cfbc 100644 --- a/src/BaGet.Protocol/ServiceIndex/IServiceIndexResource.cs +++ b/src/BaGet.Protocol/ServiceIndex/IServiceIndexClient.cs @@ -5,10 +5,11 @@ namespace BaGet.Protocol { /// - /// The NuGet Service Index resource, used to discover other resources. - /// See: https://docs.microsoft.com/en-us/nuget/api/service-index + /// The NuGet Service Index client, used to discover other resources. + /// + /// See https://docs.microsoft.com/en-us/nuget/api/service-index /// - public interface IServiceIndexResource + public interface IServiceIndexClient { /// /// Get the resources available on this package feed. diff --git a/src/BaGet.Protocol/ServiceIndex/ServiceIndexClient.cs b/src/BaGet.Protocol/ServiceIndex/ServiceIndexClient.cs index 7f8e5a8db..e5364f990 100644 --- a/src/BaGet.Protocol/ServiceIndex/ServiceIndexClient.cs +++ b/src/BaGet.Protocol/ServiceIndex/ServiceIndexClient.cs @@ -7,9 +7,11 @@ namespace BaGet.Protocol.Internal { /// - /// Fetches the service index from an upstream package source. + /// The NuGet Service Index client, used to discover other resources. + /// + /// See https://docs.microsoft.com/en-us/nuget/api/service-index /// - public class ServiceIndexClient : IServiceIndexResource + public class ServiceIndexClient : IServiceIndexClient { private readonly HttpClient _httpClient; private readonly string _serviceIndexUrl; diff --git a/src/BaGet.Tools.AzureSearchImporter/Initializer.cs b/src/BaGet.Tools.AzureSearchImporter/Initializer.cs index 8b634f2d2..e0fdef4a6 100644 --- a/src/BaGet.Tools.AzureSearchImporter/Initializer.cs +++ b/src/BaGet.Tools.AzureSearchImporter/Initializer.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Threading.Tasks; using BaGet.Azure.Search; -using BaGet.Core.Entities; +using BaGet.Core; using BaGet.Tools.AzureSearchImporter.Entities; using Microsoft.Azure.Search; using Microsoft.Azure.Search.Models; diff --git a/src/BaGet/Extensions/IServiceCollectionExtensions.cs b/src/BaGet/Extensions/IServiceCollectionExtensions.cs index 958b09af9..d8066329b 100644 --- a/src/BaGet/Extensions/IServiceCollectionExtensions.cs +++ b/src/BaGet/Extensions/IServiceCollectionExtensions.cs @@ -9,18 +9,8 @@ using BaGet.Azure.Extensions; using BaGet.Azure.Search; using BaGet.Core; -using BaGet.Core.Authentication; -using BaGet.Core.Configuration; using BaGet.Core.Content; -using BaGet.Core.Entities; -using BaGet.Core.Extensions; -using BaGet.Core.Indexing; -using BaGet.Core.Metadata; -using BaGet.Core.Mirror; -using BaGet.Core.Search; using BaGet.Core.Server.Extensions; -using BaGet.Core.ServiceIndex; -using BaGet.Core.Storage; using BaGet.Database.MySql; using BaGet.Database.PostgreSql; using BaGet.Database.Sqlite; @@ -68,9 +58,9 @@ public static IServiceCollection ConfigureBaGet( services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddSingleton(); services.AddMirrorServices(); @@ -211,7 +201,7 @@ public static IServiceCollection AddStorageProviders(this IServiceCollection ser public static IServiceCollection AddSearchProviders(this IServiceCollection services) { - services.AddTransient(provider => + services.AddTransient(provider => { var options = provider.GetRequiredService>(); @@ -245,7 +235,7 @@ public static IServiceCollection AddSearchProviders(this IServiceCollection serv /// The defined services. public static IServiceCollection AddMirrorServices(this IServiceCollection services) { - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(provider => @@ -254,7 +244,7 @@ public static IServiceCollection AddMirrorServices(this IServiceCollection servi if (!options.Value.Enabled) { - return provider.GetRequiredService(); + return provider.GetRequiredService(); } else { @@ -273,8 +263,6 @@ public static IServiceCollection AddMirrorServices(this IServiceCollection servi options.Value.PackageSource.ToString()); }); - services.AddTransient(); - services.AddSingleton(provider => { var options = provider.GetRequiredService>().Value; diff --git a/src/BaGet/Program.cs b/src/BaGet/Program.cs index 12c9a2812..8d472b8b1 100644 --- a/src/BaGet/Program.cs +++ b/src/BaGet/Program.cs @@ -1,5 +1,5 @@ using System; -using BaGet.Core.Mirror; +using BaGet.Core; using BaGet.Extensions; using McMaster.Extensions.CommandLineUtils; using Microsoft.AspNetCore; diff --git a/src/BaGet/Startup.cs b/src/BaGet/Startup.cs index 052c707b5..05b8fa21b 100644 --- a/src/BaGet/Startup.cs +++ b/src/BaGet/Startup.cs @@ -1,7 +1,6 @@ using System; using BaGet.Configuration; -using BaGet.Core.Configuration; -using BaGet.Core.Entities; +using BaGet.Core; using BaGet.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; diff --git a/tests/BaGet.Core.Tests/Mirror/MirrorServiceTests.cs b/tests/BaGet.Core.Tests/Mirror/MirrorServiceTests.cs index e4389bb07..0a10afd43 100644 --- a/tests/BaGet.Core.Tests/Mirror/MirrorServiceTests.cs +++ b/tests/BaGet.Core.Tests/Mirror/MirrorServiceTests.cs @@ -1,7 +1,4 @@ using System.Threading.Tasks; -using BaGet.Core.Indexing; -using BaGet.Core.Metadata; -using BaGet.Core.Mirror; using BaGet.Protocol; using Microsoft.Extensions.Logging; using Moq; diff --git a/tests/BaGet.Core.Tests/Services/FileStorageServiceTests.cs b/tests/BaGet.Core.Tests/Services/FileStorageServiceTests.cs index 5f16b202c..19e81d77c 100644 --- a/tests/BaGet.Core.Tests/Services/FileStorageServiceTests.cs +++ b/tests/BaGet.Core.Tests/Services/FileStorageServiceTests.cs @@ -3,8 +3,6 @@ using System.IO; using System.Text; using System.Threading.Tasks; -using BaGet.Core.Configuration; -using BaGet.Core.Storage; using Microsoft.Extensions.Options; using Moq; using Xunit; @@ -238,7 +236,7 @@ public IEnumerable OutsideStorePathData { get { - string fullPath = Path.GetFullPath(_storePath); + var fullPath = Path.GetFullPath(_storePath); yield return "../file"; yield return "."; yield return $"../{Path.GetFileName(_storePath)}"; diff --git a/tests/BaGet.Core.Tests/Services/PackageDeletionServiceTests.cs b/tests/BaGet.Core.Tests/Services/PackageDeletionServiceTests.cs index 7e461ad34..6e8ab76fc 100644 --- a/tests/BaGet.Core.Tests/Services/PackageDeletionServiceTests.cs +++ b/tests/BaGet.Core.Tests/Services/PackageDeletionServiceTests.cs @@ -1,8 +1,5 @@ using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Configuration; -using BaGet.Core.Metadata; -using BaGet.Core.Storage; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; diff --git a/tests/BaGet.Core.Tests/Services/PackageIndexingServiceTests.cs b/tests/BaGet.Core.Tests/Services/PackageIndexingServiceTests.cs index ce8de16ba..cf3d901b2 100644 --- a/tests/BaGet.Core.Tests/Services/PackageIndexingServiceTests.cs +++ b/tests/BaGet.Core.Tests/Services/PackageIndexingServiceTests.cs @@ -1,9 +1,4 @@ using System.Threading.Tasks; -using BaGet.Core.Configuration; -using BaGet.Core.Indexing; -using BaGet.Core.Metadata; -using BaGet.Core.Search; -using BaGet.Core.Storage; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; @@ -15,14 +10,14 @@ public class PackageIndexingServiceTests { private readonly Mock _packages; private readonly Mock _storage; - private readonly Mock _search; + private readonly Mock _search; private readonly PackageIndexingService _target; public PackageIndexingServiceTests() { _packages = new Mock(); _storage = new Mock(); - _search = new Mock(); + _search = new Mock(); _target = new PackageIndexingService( _packages.Object, diff --git a/tests/BaGet.Core.Tests/Services/PackageServiceTests.cs b/tests/BaGet.Core.Tests/Services/PackageServiceTests.cs index 5ced383bb..bcb8c7be5 100644 --- a/tests/BaGet.Core.Tests/Services/PackageServiceTests.cs +++ b/tests/BaGet.Core.Tests/Services/PackageServiceTests.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; using System.Threading.Tasks; -using BaGet.Core.Entities; -using BaGet.Core.Metadata; using Moq; using Xunit; diff --git a/tests/BaGet.Core.Tests/Services/PackageStorageServiceTests.cs b/tests/BaGet.Core.Tests/Services/PackageStorageServiceTests.cs index 1bfc27a39..5d36f4646 100644 --- a/tests/BaGet.Core.Tests/Services/PackageStorageServiceTests.cs +++ b/tests/BaGet.Core.Tests/Services/PackageStorageServiceTests.cs @@ -4,8 +4,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using BaGet.Core.Entities; -using BaGet.Core.Storage; using Microsoft.Extensions.Logging; using Moq; using NuGet.Versioning; diff --git a/tests/BaGet.Protocol.Tests/CatalogClientTests.cs b/tests/BaGet.Protocol.Tests/RawCatalogClientTests.cs similarity index 92% rename from tests/BaGet.Protocol.Tests/CatalogClientTests.cs rename to tests/BaGet.Protocol.Tests/RawCatalogClientTests.cs index 36e9a8ee4..5ebb2ccf8 100644 --- a/tests/BaGet.Protocol.Tests/CatalogClientTests.cs +++ b/tests/BaGet.Protocol.Tests/RawCatalogClientTests.cs @@ -7,11 +7,11 @@ namespace BaGet.Protocol.Tests { - public class CatalogClientTests : IClassFixture + public class RawCatalogClientTests : IClassFixture { - private readonly CatalogClient _target; + private readonly RawCatalogClient _target; - public CatalogClientTests(ProtocolFixture fixture) + public RawCatalogClientTests(ProtocolFixture fixture) { _target = fixture.CatalogClient; } diff --git a/tests/BaGet.Protocol.Tests/PackageContentClientTests.cs b/tests/BaGet.Protocol.Tests/RawPackageContentClientTests.cs similarity index 82% rename from tests/BaGet.Protocol.Tests/PackageContentClientTests.cs rename to tests/BaGet.Protocol.Tests/RawPackageContentClientTests.cs index dae6470a5..4c66e7989 100644 --- a/tests/BaGet.Protocol.Tests/PackageContentClientTests.cs +++ b/tests/BaGet.Protocol.Tests/RawPackageContentClientTests.cs @@ -5,11 +5,11 @@ namespace BaGet.Protocol.Tests { - public class PackageContentTests : IClassFixture + public class RawPackageContentTests : IClassFixture { - private readonly PackageContentClient _target; + private readonly RawPackageContentClient _target; - public PackageContentTests(ProtocolFixture fixture) + public RawPackageContentTests(ProtocolFixture fixture) { _target = fixture.ContentClient; } diff --git a/tests/BaGet.Protocol.Tests/PackageMetadataClientTests.cs b/tests/BaGet.Protocol.Tests/RawPackageMetadataClientTests.cs similarity index 90% rename from tests/BaGet.Protocol.Tests/PackageMetadataClientTests.cs rename to tests/BaGet.Protocol.Tests/RawPackageMetadataClientTests.cs index 2c4136115..b79e521a7 100644 --- a/tests/BaGet.Protocol.Tests/PackageMetadataClientTests.cs +++ b/tests/BaGet.Protocol.Tests/RawPackageMetadataClientTests.cs @@ -5,11 +5,11 @@ namespace BaGet.Protocol.Tests { - public class PackageMetadataClientTests : IClassFixture + public class RawPackageMetadataClientTests : IClassFixture { - private readonly PackageMetadataClient _target; + private readonly RawPackageMetadataClient _target; - public PackageMetadataClientTests(ProtocolFixture fixture) + public RawPackageMetadataClientTests(ProtocolFixture fixture) { _target = fixture.MetadataClient; } @@ -57,9 +57,7 @@ public async Task GetRegistrationIndexPagedItems() [Fact] public async Task GetRegistrationPage() { - var lower = NuGetVersion.Parse("2.0.0+build"); - var upper = NuGetVersion.Parse("3.0.0"); - var result = await _target.GetRegistrationPageOrNullAsync("Paged.Package", lower, upper); + var result = await _target.GetRegistrationPageAsync(TestData.RegistrationPageUrl); Assert.NotNull(result); Assert.Equal(2, result.Count); diff --git a/tests/BaGet.Protocol.Tests/SearchClientTests.cs b/tests/BaGet.Protocol.Tests/RawSearchClientTests.cs similarity index 84% rename from tests/BaGet.Protocol.Tests/SearchClientTests.cs rename to tests/BaGet.Protocol.Tests/RawSearchClientTests.cs index bd44c8d9f..90a5f8bf3 100644 --- a/tests/BaGet.Protocol.Tests/SearchClientTests.cs +++ b/tests/BaGet.Protocol.Tests/RawSearchClientTests.cs @@ -4,11 +4,11 @@ namespace BaGet.Protocol.Tests { - public class SearchClientTests : IClassFixture + public class RawSearchClientTests : IClassFixture { - private readonly SearchClient _target; + private readonly RawSearchClient _target; - public SearchClientTests(ProtocolFixture fixture) + public RawSearchClientTests(ProtocolFixture fixture) { _target = fixture.SearchClient; } diff --git a/tests/BaGet.Protocol.Tests/Support/ProtocolFixture.cs b/tests/BaGet.Protocol.Tests/Support/ProtocolFixture.cs index 39b760302..e8007bc37 100644 --- a/tests/BaGet.Protocol.Tests/Support/ProtocolFixture.cs +++ b/tests/BaGet.Protocol.Tests/Support/ProtocolFixture.cs @@ -14,10 +14,10 @@ public ProtocolFixture() NuGetClient = new NuGetClient(NuGetClientFactory); ServiceIndexClient = new ServiceIndexClient(httpClient, TestData.ServiceIndexUrl); - ContentClient = new PackageContentClient(httpClient, TestData.PackageContentUrl); - MetadataClient = new PackageMetadataClient(httpClient, TestData.PackageMetadataUrl); - CatalogClient = new CatalogClient(httpClient, TestData.CatalogIndexUrl); - SearchClient = new SearchClient( + ContentClient = new RawPackageContentClient(httpClient, TestData.PackageContentUrl); + MetadataClient = new RawPackageMetadataClient(httpClient, TestData.PackageMetadataUrl); + CatalogClient = new RawCatalogClient(httpClient, TestData.CatalogIndexUrl); + SearchClient = new RawSearchClient( httpClient, TestData.SearchUrl, TestData.AutocompleteUrl); @@ -27,9 +27,9 @@ public ProtocolFixture() public NuGetClientFactory NuGetClientFactory { get; } public ServiceIndexClient ServiceIndexClient { get; } - public PackageContentClient ContentClient { get; } - public PackageMetadataClient MetadataClient { get; } - public SearchClient SearchClient { get; } - public CatalogClient CatalogClient { get; } + public RawPackageContentClient ContentClient { get; } + public RawPackageMetadataClient MetadataClient { get; } + public RawSearchClient SearchClient { get; } + public RawCatalogClient CatalogClient { get; } } } diff --git a/tests/BaGet.Tests/ServiceCollectionExtensionsTest.cs b/tests/BaGet.Tests/ServiceCollectionExtensionsTest.cs index 1ddca42cb..ba4fdd3b7 100644 --- a/tests/BaGet.Tests/ServiceCollectionExtensionsTest.cs +++ b/tests/BaGet.Tests/ServiceCollectionExtensionsTest.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; -using BaGet.Core.Configuration; -using BaGet.Core.Entities; +using BaGet.Core; using BaGet.Database.Sqlite; using BaGet.Extensions; using Microsoft.Extensions.Configuration; diff --git a/tests/BaGet.Tests/TestServerBuilder.cs b/tests/BaGet.Tests/TestServerBuilder.cs index 53bdc7449..c2c315bb6 100644 --- a/tests/BaGet.Tests/TestServerBuilder.cs +++ b/tests/BaGet.Tests/TestServerBuilder.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; using System.IO; -using BaGet.Core.Configuration; -using BaGet.Core.Entities; +using BaGet.Core; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; using Microsoft.EntityFrameworkCore; @@ -19,7 +18,6 @@ namespace BaGet.Tests /// public class TestServerBuilder { - private const string DefaultPackagesFolderName = "Packages"; private readonly string DatabaseTypeKey = $"{nameof(BaGetOptions.Database)}:{nameof(DatabaseOptions.Type)}";