Skip to content

Commit e57d120

Browse files
authored
Refactor BaGet.Core (loic-sharma#259)
⚠️ This change changes the namespace of most core types! These are breaking changes, BaGet's version has been bumped to `0.2.x-prerelease` to reflect this!
1 parent feea116 commit e57d120

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+191
-148
lines changed

src/BaGet.AWS/S3StorageService.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Amazon.S3;
66
using Amazon.S3.Model;
77
using BaGet.AWS.Configuration;
8-
using BaGet.Core.Services;
8+
using BaGet.Core.Storage;
99
using Microsoft.Extensions.Options;
1010

1111
namespace BaGet.AWS
@@ -70,7 +70,7 @@ public Task<Uri> GetDownloadUriAsync(string path, CancellationToken cancellation
7070
return Task.FromResult(new Uri(url));
7171
}
7272

73-
public async Task<PutResult> PutAsync(string path, Stream content, string contentType, CancellationToken cancellationToken = default)
73+
public async Task<StoragePutResult> PutAsync(string path, Stream content, string contentType, CancellationToken cancellationToken = default)
7474
{
7575
// TODO: Uploads should be idempotent. This should fail if and only if the blob
7676
// already exists but has different content.
@@ -92,7 +92,7 @@ await _client.PutObjectAsync(new PutObjectRequest
9292
}, cancellationToken);
9393
}
9494

95-
return PutResult.Success;
95+
return StoragePutResult.Success;
9696
}
9797

9898
public async Task DeleteAsync(string path, CancellationToken cancellationToken = default)

src/BaGet.Azure/BlobStorageService.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using BaGet.Core.Extensions;
7-
using BaGet.Core.Services;
7+
using BaGet.Core.Storage;
88
using Microsoft.WindowsAzure.Storage;
99
using Microsoft.WindowsAzure.Storage.Blob;
1010

@@ -43,7 +43,7 @@ public Task<Uri> GetDownloadUriAsync(string path, CancellationToken cancellation
4343
return Task.FromResult(result);
4444
}
4545

46-
public async Task<PutResult> PutAsync(
46+
public async Task<StoragePutResult> PutAsync(
4747
string path,
4848
Stream content,
4949
string contentType,
@@ -63,16 +63,16 @@ await blob.UploadFromStreamAsync(
6363
operationContext: null,
6464
cancellationToken: cancellationToken);
6565

66-
return PutResult.Success;
66+
return StoragePutResult.Success;
6767
}
6868
catch (StorageException e) when (IsAlreadyExistsException(e))
6969
{
7070
using (var targetStream = await blob.OpenReadAsync(cancellationToken))
7171
{
7272
content.Position = 0;
7373
return content.Matches(targetStream)
74-
? PutResult.AlreadyExists
75-
: PutResult.Conflict;
74+
? StoragePutResult.AlreadyExists
75+
: StoragePutResult.Conflict;
7676
}
7777
}
7878
}

src/BaGet.Azure/Search/AzureSearchService.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5-
using BaGet.Core.Services;
65
using BaGet.Core.Entities;
6+
using BaGet.Core.Indexing;
7+
using BaGet.Core.Search;
78
using Microsoft.Azure.Search;
89
using NuGet.Versioning;
910

1011
namespace BaGet.Azure.Search
1112
{
12-
using SearchParameters = Microsoft.Azure.Search.Models.SearchParameters;
1313
using QueryType = Microsoft.Azure.Search.Models.QueryType;
14+
using SearchParameters = Microsoft.Azure.Search.Models.SearchParameters;
1415

1516
public class AzureSearchService : ISearchService
1617
{

src/BaGet.Azure/Search/BatchIndexer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using BaGet.Core.Entities;
7-
using BaGet.Core.Services;
7+
using BaGet.Core.State;
88
using Microsoft.Azure.Search;
99
using Microsoft.Azure.Search.Models;
1010
using Microsoft.Extensions.Logging;

src/BaGet.Core.Server/Controllers/PackageController.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using BaGet.Core.Mirror;
6-
using BaGet.Core.Services;
6+
using BaGet.Core.State;
7+
using BaGet.Core.Storage;
78
using BaGet.Protocol;
89
using Microsoft.AspNetCore.Mvc;
9-
using NuGet.Packaging.Core;
1010
using NuGet.Versioning;
1111

1212
namespace BaGet.Controllers
@@ -108,4 +108,4 @@ public async Task<IActionResult> DownloadReadme(string id, string version, Cance
108108
return File(readmeStream, "text/markdown");
109109
}
110110
}
111-
}
111+
}

src/BaGet.Core.Server/Controllers/PackagePublishController.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Threading;
33
using System.Threading.Tasks;
4+
using BaGet.Core.Authentication;
45
using BaGet.Core.Configuration;
5-
using BaGet.Core.Services;
6+
using BaGet.Core.Indexing;
7+
using BaGet.Core.State;
68
using BaGet.Extensions;
79
using Microsoft.AspNetCore.Mvc;
810
using Microsoft.Extensions.Logging;

src/BaGet.Core.Server/Controllers/Registration/RegistrationIndexController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading.Tasks;
66
using BaGet.Core.Entities;
77
using BaGet.Core.Mirror;
8-
using BaGet.Core.Services;
8+
using BaGet.Core.State;
99
using BaGet.Extensions;
1010
using BaGet.Protocol;
1111
using Microsoft.AspNetCore.Mvc;

src/BaGet.Core.Server/Controllers/Registration/RegistrationLeafController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using BaGet.Core.Mirror;
5-
using BaGet.Core.Services;
5+
using BaGet.Core.State;
66
using BaGet.Extensions;
77
using BaGet.Protocol;
88
using Microsoft.AspNetCore.Mvc;

src/BaGet.Core.Server/Controllers/SearchController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
using System;
22
using System.Linq;
33
using System.Threading.Tasks;
4-
using BaGet.Core.Services;
4+
using BaGet.Core.Search;
55
using BaGet.Extensions;
66
using BaGet.Protocol;
77
using Microsoft.AspNetCore.Mvc;
88

99
namespace BaGet.Controllers
1010
{
1111
using ProtocolSearchResult = Protocol.SearchResult;
12-
using QuerySearchResult = Core.Services.SearchResult;
12+
using QuerySearchResult = Core.Search.SearchResult;
1313

1414
public class SearchController : Controller
1515
{

src/BaGet.Core.Server/Controllers/SymbolController.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Threading;
33
using System.Threading.Tasks;
4+
using BaGet.Core.Authentication;
45
using BaGet.Core.Configuration;
5-
using BaGet.Core.Services;
6+
using BaGet.Core.Indexing;
7+
using BaGet.Core.Storage;
68
using BaGet.Extensions;
79
using Microsoft.AspNetCore.Mvc;
810
using Microsoft.Extensions.Logging;

src/BaGet.Core/Services/ApiKeyAuthenticationService.cs src/BaGet.Core/Authentication/ApiKeyAuthenticationService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using BaGet.Core.Configuration;
44
using Microsoft.Extensions.Options;
55

6-
namespace BaGet.Core.Services
6+
namespace BaGet.Core.Authentication
77
{
88
public class ApiKeyAuthenticationService : IAuthenticationService
99
{

src/BaGet.Core/Services/IAuthenticationService.cs src/BaGet.Core/Authentication/IAuthenticationService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
22

3-
namespace BaGet.Core.Services
3+
namespace BaGet.Core.Authentication
44
{
55
public interface IAuthenticationService
66
{

src/BaGet.Core/Services/FrameworkCompatibilityService.cs src/BaGet.Core/Indexing/FrameworkCompatibilityService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Linq;
55
using NuGet.Frameworks;
66

7-
namespace BaGet.Core.Services
7+
namespace BaGet.Core.Indexing
88
{
99
using static NuGet.Frameworks.FrameworkConstants;
1010

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
3+
namespace BaGet.Core.Indexing
4+
{
5+
/// <summary>
6+
/// Used to determine the compatibility matrix between frameworks.
7+
/// </summary>
8+
public interface IFrameworkCompatibilityService
9+
{
10+
/// <summary>
11+
/// Given a framework, find all other compatible frameworks.
12+
/// </summary>
13+
/// <param name="framework">The input framework.</param>
14+
/// <returns>The list of compatible frameworks.</returns>
15+
IReadOnlyList<string> FindAllCompatibleFrameworks(string framework);
16+
}
17+
}

src/BaGet.Core/Services/IPackageIndexingService.cs src/BaGet.Core/Indexing/IPackageIndexingService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44

5-
namespace BaGet.Core.Services
5+
namespace BaGet.Core.Indexing
66
{
77
/// <summary>
88
/// The result of attempting to index a package.
@@ -39,4 +39,4 @@ public interface IPackageIndexingService
3939
/// <returns>The result of the attempted indexing operation.</returns>
4040
Task<PackageIndexingResult> IndexAsync(Stream stream, CancellationToken cancellationToken);
4141
}
42-
}
42+
}

src/BaGet.Core/Services/ISymbolIndexingService.cs src/BaGet.Core/Indexing/ISymbolIndexingService.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System.IO;
1+
using System.IO;
22
using System.Threading;
33
using System.Threading.Tasks;
44

5-
namespace BaGet.Core.Services
5+
namespace BaGet.Core.Indexing
66
{
77
/// <summary>
88
/// The result of attempting to index a symbol package.
@@ -39,4 +39,4 @@ public interface ISymbolIndexingService
3939
/// <returns>The result of the attempted indexing operation.</returns>
4040
Task<SymbolIndexingResult> IndexAsync(Stream stream, CancellationToken cancellationToken);
4141
}
42-
}
42+
}

src/BaGet.Core/Services/PackageIndexingService.cs src/BaGet.Core/Indexing/PackageIndexingService.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
using BaGet.Core.Configuration;
88
using BaGet.Core.Entities;
99
using BaGet.Core.Extensions;
10+
using BaGet.Core.Search;
11+
using BaGet.Core.State;
12+
using BaGet.Core.Storage;
1013
using Microsoft.Extensions.Logging;
1114
using Microsoft.Extensions.Options;
1215
using NuGet.Packaging;
1316

14-
namespace BaGet.Core.Services
17+
namespace BaGet.Core.Indexing
1518
{
1619
using NuGetPackageType = NuGet.Packaging.Core.PackageType;
17-
using BaGetPackageDependency = Entities.PackageDependency;
1820

1921
public class PackageIndexingService : IPackageIndexingService
2022
{
@@ -254,17 +256,17 @@ private string[] ParseTags(string tags)
254256
return (repositoryUri, repository.Type);
255257
}
256258

257-
private List<BaGetPackageDependency> GetDependencies(NuspecReader nuspec)
259+
private List<PackageDependency> GetDependencies(NuspecReader nuspec)
258260
{
259-
var dependencies = new List<BaGetPackageDependency>();
261+
var dependencies = new List<PackageDependency>();
260262

261263
foreach (var group in nuspec.GetDependencyGroups())
262264
{
263265
var targetFramework = group.TargetFramework.GetShortFolderName();
264266

265267
if (!group.Packages.Any())
266268
{
267-
dependencies.Add(new BaGetPackageDependency
269+
dependencies.Add(new PackageDependency
268270
{
269271
Id = null,
270272
VersionRange = null,
@@ -274,7 +276,7 @@ private List<BaGetPackageDependency> GetDependencies(NuspecReader nuspec)
274276

275277
foreach (var dependency in group.Packages)
276278
{
277-
dependencies.Add(new BaGetPackageDependency
279+
dependencies.Add(new PackageDependency
278280
{
279281
Id = dependency.Id,
280282
VersionRange = dependency.VersionRange?.ToString(),

src/BaGet.Core/Services/SymbolIndexingService.cs src/BaGet.Core/Indexing/SymbolIndexingService.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
55
using System.Reflection.Metadata;
66
using System.Threading;
77
using System.Threading.Tasks;
88
using BaGet.Core.Extensions;
9-
using Microsoft.EntityFrameworkCore.Metadata.Internal;
9+
using BaGet.Core.State;
10+
using BaGet.Core.Storage;
1011
using Microsoft.Extensions.Logging;
1112
using NuGet.Packaging;
12-
using NuGet.Packaging.Core;
1313

14-
namespace BaGet.Core.Services
14+
namespace BaGet.Core.Indexing
1515
{
1616
// Based off: https://github.com/NuGet/NuGetGallery/blob/master/src/NuGetGallery/Services/SymbolPackageUploadService.cs
1717
// Based off: https://github.com/NuGet/NuGet.Jobs/blob/master/src/Validation.Symbols/SymbolsValidatorService.cs#L44

src/BaGet.Core/Mirror/MirrorService.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading;
55
using System.Threading.Tasks;
66
using BaGet.Core.Entities;
7-
using BaGet.Core.Services;
7+
using BaGet.Core.Indexing;
8+
using BaGet.Core.State;
89
using BaGet.Protocol;
910
using Microsoft.Extensions.Logging;
1011
using NuGet.Versioning;

src/BaGet.Core/Services/DatabaseSearchService.cs src/BaGet.Core/Search/DatabaseSearchService.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using BaGet.Core.Entities;
6+
using BaGet.Core.Indexing;
67
using Microsoft.EntityFrameworkCore;
78

8-
namespace BaGet.Core.Services
9+
namespace BaGet.Core.Search
910
{
1011
public class DatabaseSearchService : ISearchService
1112
{

src/BaGet.Core/Services/ISearchService.cs src/BaGet.Core/Search/ISearchService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using BaGet.Core.Entities;
55
using NuGet.Versioning;
66

7-
namespace BaGet.Core.Services
7+
namespace BaGet.Core.Search
88
{
99
public interface ISearchService
1010
{

src/BaGet.Core/Services/NullSearchService.cs src/BaGet.Core/Search/NullSearchService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Threading.Tasks;
33
using BaGet.Core.Entities;
44

5-
namespace BaGet.Core.Services
5+
namespace BaGet.Core.Search
66
{
77
/// <summary>
88
/// A minimal search service implementation, used for advanced scenarios.

src/BaGet.Core/Services/IFrameworkCompatibilityService.cs

-9
This file was deleted.

src/BaGet.Core/Services/IPackageDeletionService.cs src/BaGet.Core/State/IPackageDeletionService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System.Threading;
1+
using System.Threading;
22
using System.Threading.Tasks;
33
using NuGet.Versioning;
44

5-
namespace BaGet.Core.Services
5+
namespace BaGet.Core.State
66
{
77
public interface IPackageDeletionService
88
{

0 commit comments

Comments
 (0)