Files
se-launcher/NuGet/PackageSourceMapping.cs
pas2704 b12f1cc2f1
All checks were successful
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (SharedCringe) (push) Successful in 1m4s
Build / Build Nuget package (NuGet) (push) Successful in 1m6s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m10s
Build / Build Nuget package (CringePlugins) (push) Successful in 1m18s
Build / Build Launcher (push) Successful in 1m54s
Retry source requests
Handle missing sources
Minor Optimizations
Move thread pool improvement to debug while we fix it
2025-06-01 11:11:50 -04:00

28 lines
1.1 KiB
C#

using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
namespace NuGet;
public class PackageSourceMapping(ImmutableArray<PackageSource> sources)
{
private readonly ImmutableArray<(string pattern, Task<NuGetClient?> client)> _clients = [
..sources.Select(b =>
(b.Pattern,
NuGetClient.CreateFromIndexUrlAsync(b.Url)))
];
public Task<NuGetClient?> GetClientAsync(string packageId) =>
_clients.FirstOrDefault(b => Regex.IsMatch(packageId, b.pattern)).client;
public ConfiguredCancelableAsyncEnumerable<NuGetClient?>.Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
return _clients.ToAsyncEnumerable()
.SelectAwait(b => new ValueTask<NuGetClient?>(b.client))
.WithCancellation(cancellationToken)
.GetAsyncEnumerator();
}
}
public record PackageSource(string Name, [StringSyntax("Regex")] string Pattern, [StringSyntax("Uri")] string Url);