config handler
Some checks failed
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (NuGet) (push) Successful in 3m38s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 4m2s
Build / Build Nuget package (SharedCringe) (push) Successful in 4m1s
Build / Build Nuget package (CringePlugins) (push) Successful in 4m18s
Build / Build Launcher (push) Failing after 4m31s

global service provider with our stuff so we stop using statics everywhere
polly retry policy for httpclient
This commit is contained in:
zznty
2025-06-02 22:40:16 +07:00
parent 27b859ea8b
commit eba25bbf88
14 changed files with 670 additions and 395 deletions

View File

@@ -97,43 +97,20 @@ public class NuGetClient
return _client.GetFromJsonAsync<SearchResult>(builder.Uri, SerializerOptions)!;
}
public static async Task<NuGetClient?> CreateFromIndexUrlAsync(string indexUrl)
public static async Task<NuGetClient?> CreateFromIndexUrlAsync(string indexUrl, HttpClient client)
{
var client = new HttpClient(new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.All,
});
var index = await client.GetFromJsonAsync<NuGetIndex>(indexUrl, SerializerOptions);
NuGetClient? ngClient = null;
var (packageBaseAddress, _, _) = index!.Resources.First(b => b.Type.Id == "PackageBaseAddress");
var (registration, _, _) = index.Resources.First(b => b.Type.Id == "RegistrationsBaseUrl");
var (search, _, _) = index.Resources.First(b => b.Type.Id == "SearchQueryService");
const int MaxRetries = 10;
if (!packageBaseAddress.EndsWith('/'))
packageBaseAddress += '/';
if (!registration.EndsWith('/'))
registration += '/';
for (var i = 0; i < MaxRetries; i++)
{
try
{
var index = await client.GetFromJsonAsync<NuGetIndex>(indexUrl, SerializerOptions);
var (packageBaseAddress, _, _) = index!.Resources.First(b => b.Type.Id == "PackageBaseAddress");
var (registration, _, _) = index.Resources.First(b => b.Type.Id == "RegistrationsBaseUrl");
var (search, _, _) = index.Resources.First(b => b.Type.Id == "SearchQueryService");
if (!packageBaseAddress.EndsWith('/'))
packageBaseAddress += '/';
if (!registration.EndsWith('/'))
registration += '/';
ngClient = new NuGetClient(new Uri(indexUrl), client, new Uri(packageBaseAddress), new Uri(registration), new Uri(search));
break;
}
catch (HttpRequestException ex)
{
Console.WriteLine(ex.Message);
}
}
return ngClient;
return new NuGetClient(new Uri(indexUrl), client, new Uri(packageBaseAddress), new Uri(registration), new Uri(search));
}
public override string ToString() => _index.ToString();