This commit is contained in:
2020-01-28 19:19:50 +00:00
parent 9a9641a96b
commit 861d8624a7
4 changed files with 26 additions and 11 deletions

View File

@@ -46,9 +46,8 @@ namespace AyaNova.Core
//Trial key magic number for development and testing, all other guids will be fully licensed
private static Guid TEST_TRIAL_KEY_DBID = new Guid("{A6D18A8A-5613-4979-99DA-80D07641A2FE}");
//https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
private static HttpClient _Client = new HttpClient();
//Current license key, can be empty
private static AyaNovaLicenseKey _ActiveLicense = new AyaNovaLicenseKey();
@@ -72,7 +71,7 @@ namespace AyaNova.Core
internal class AyaNovaLicenseKey
{
public AyaNovaLicenseKey()
{
{
Features = new List<LicenseFeature>();
RegisteredTo = "UNLICENSED";
Id = RegisteredTo;
@@ -358,7 +357,8 @@ namespace AyaNova.Core
string sUrl = $"{LICENSE_SERVER_URL}rvr" + q.ToQueryString();
try
{
var res = await _Client.GetStringAsync(sUrl);
//var res = await _Client.GetStringAsync(sUrl);
var res = await ServiceProviderProvider.HttpClientFactory.CreateClient().GetStringAsync(sUrl);
return res;
}
catch (Exception ex)
@@ -391,7 +391,9 @@ namespace AyaNova.Core
try
{
string RawTextKeyFromRockfish = await _Client.GetStringAsync(sUrl);
//string RawTextKeyFromRockfish = await _Client.GetStringAsync(sUrl);
string RawTextKeyFromRockfish = await ServiceProviderProvider.HttpClientFactory.CreateClient().GetStringAsync(sUrl);
//FUTURE: if there is any kind of error response or REASON or LicenseFetchStatus then here is
//where to deal with it
@@ -519,7 +521,7 @@ namespace AyaNova.Core
}
//Can't install a trial into a non-empty db
if (ParsedNewKey.TrialLicense && ! await DbUtil.DBIsEmptyAsync(ct, log))
if (ParsedNewKey.TrialLicense && !await DbUtil.DBIsEmptyAsync(ct, log))
{
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
}

View File

@@ -25,11 +25,12 @@ namespace AyaNova.Util
{
get
{
#if (DEBUG)
if(_provider==null){
#if (DEBUG)
if (_provider == null)
{
throw new System.NotSupportedException("ServiceProviderProvider.cs - Attempt to use service provider before it's been initialized");
}
#endif
#endif
return _provider;
}
set
@@ -57,6 +58,14 @@ namespace AyaNova.Util
}
}
// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1
internal static System.Net.Http.IHttpClientFactory HttpClientFactory
{
get
{
return Scope.ServiceProvider.GetRequiredService<System.Net.Http.IHttpClientFactory>();
}
}
}