This commit is contained in:
@@ -417,23 +417,23 @@ namespace AyaNova.Core
|
||||
/// Initialize the key
|
||||
/// Handle if first boot scenario to tag DB ID etc
|
||||
/// </summary>
|
||||
internal static void Initialize(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ctx, ILogger log)
|
||||
internal static async Task Initialize(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log)
|
||||
{
|
||||
log.LogDebug("Initializing license");
|
||||
|
||||
try
|
||||
{
|
||||
//Fetch key from db as no tracking so doesn't hang round if need to immediately clear and then re-add the key
|
||||
Models.License ldb = ctx.License.AsNoTracking().SingleOrDefault();
|
||||
Models.License ldb = ct.License.AsNoTracking().SingleOrDefault();
|
||||
|
||||
//Non existent license should restrict server to ops routes only with closed API
|
||||
if (ldb == null)
|
||||
{
|
||||
ldb = new Models.License();
|
||||
ldb.DbId = Guid.NewGuid();
|
||||
ldb.DbId = Guid.NewGuid();
|
||||
ldb.Key = "none";
|
||||
ctx.License.Add(ldb);
|
||||
ctx.SaveChanges();
|
||||
ct.License.Add(ldb);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
|
||||
//ensure DB ID
|
||||
@@ -442,8 +442,8 @@ namespace AyaNova.Core
|
||||
ldb.DbId = Guid.NewGuid();
|
||||
//Convert the no tracking record fetched above to tracking
|
||||
//this is required because a prior call to initialize before dumping the db would mean the license is still in memory in the context
|
||||
ctx.Entry(ldb).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||
ctx.SaveChanges();
|
||||
ct.Entry(ldb).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
|
||||
//Get it early and set it here so that it can be displayed early to the user even if not licensed
|
||||
@@ -478,7 +478,7 @@ namespace AyaNova.Core
|
||||
}
|
||||
|
||||
//Has someone been trying funny business with the active techs in the db?
|
||||
if (AyaNova.Biz.UserBiz.ActiveCount > _ActiveLicense.ActiveNumber)
|
||||
if (await AyaNova.Biz.UserBiz.ActiveCountAsync() > _ActiveLicense.ActiveNumber)
|
||||
{
|
||||
var msg = $"E1020 - Active count exceeded capacity";
|
||||
apiServerState.SetSystemLock(msg);
|
||||
@@ -508,11 +508,11 @@ namespace AyaNova.Core
|
||||
/// <summary>
|
||||
/// Install key to db
|
||||
/// </summary>
|
||||
private static bool Install(string RawTextNewKey, AyaNovaLicenseKey ParsedNewKey, AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ctx, ILogger log)
|
||||
private static async Task<bool> Install(string RawTextNewKey, AyaNovaLicenseKey ParsedNewKey, AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log)
|
||||
{
|
||||
try
|
||||
{
|
||||
var CurrentInDbKeyRecord = ctx.License.OrderBy(x => x.Id).FirstOrDefault();
|
||||
var CurrentInDbKeyRecord = await ct.License.OrderBy(x => x.Id).FirstOrDefaultAsync();
|
||||
if (CurrentInDbKeyRecord == null)
|
||||
throw new ApplicationException("E1020 - Can't install key, no key record found");
|
||||
|
||||
@@ -522,13 +522,13 @@ namespace AyaNova.Core
|
||||
}
|
||||
|
||||
//Can't install a trial into a non-empty db
|
||||
if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmpty(ctx, log))
|
||||
if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmpty(ct, log))
|
||||
{
|
||||
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
|
||||
}
|
||||
|
||||
//TODO: TECHCOUNT - new license causes exceeding count?
|
||||
if (AyaNova.Biz.UserBiz.ActiveCount > ParsedNewKey.GetLicenseFeature(SERVICE_TECHS_FEATURE_NAME).Count)
|
||||
if (await AyaNova.Biz.UserBiz.ActiveCountAsync() > ParsedNewKey.GetLicenseFeature(SERVICE_TECHS_FEATURE_NAME).Count)
|
||||
{
|
||||
throw new ApplicationException("E1020 - Can't install key, too many active techs and / or subcontractors in database. Deactivate enough to install key.");
|
||||
}
|
||||
@@ -537,7 +537,7 @@ namespace AyaNova.Core
|
||||
CurrentInDbKeyRecord.Key = RawTextNewKey;
|
||||
//LOOKAT: reason, resultcode etc
|
||||
//There is similar block related to this in ayschema for db schema version 8
|
||||
ctx.SaveChanges();
|
||||
ct.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -547,7 +547,7 @@ namespace AyaNova.Core
|
||||
}
|
||||
finally
|
||||
{
|
||||
Initialize(apiServerState, ctx, log);
|
||||
await Initialize(apiServerState, ct, log);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user