maintenance expiration vs build date checking code

This commit is contained in:
2022-08-05 23:31:37 +00:00
parent 379ba76b31
commit d95510cf48
8 changed files with 96 additions and 14 deletions

View File

@@ -593,7 +593,35 @@ namespace AyaNova
//log each item individually from runtime parameters
//Initialize license unless it doesn't exist yet then wait and do it after schema update and fingerprint
//this is necessary to accomodate checking build date against subscription and preventing schema update if they upgrade but are not entitled to
//so they don't fuck their database
//if there is a build date issue or a license issue it will fail with an exception, log to log file, log to console and not go beyond the license check preserving the db
//Note: case 4160 is to build an external license fetcher utility to allow a user to upgrade without uninstalling the newer version by purchasing a new sub and installing the key out of AyaNova
//If they don't want to purchase then they must downgrade
var tempSchema = dbContext.SchemaVersion.AsNoTracking().SingleOrDefault();
var tempLicense = dbContext.License.AsNoTracking().SingleOrDefault();
bool licenseChecked = false;
if (tempSchema != null && tempLicense != null && !string.IsNullOrWhiteSpace(tempSchema.Id))
{
//we have a schema and a license, check it now thus triggering build date vs maintenance expiry check
try
{
AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog).Wait();
licenseChecked = true;
}
catch (Exception ex)
{
//Only re-throw if it's a 1020 error with the text VERSION-TOO-NEW included, any other error allow it to keep doing it's thing below before the second license init
//our exception is buried inside multiple inner exceptions but it's the innermost so drill down into it
while (ex.InnerException != null)
ex = ex.InnerException;
if (ex.Message.Contains("1020") && ex.Message.Contains("VERSION-TOO-NEW "))
{
throw new Exception("AyaNova did not start to protect the integrity of your data, see the console and / or error log for details");
}
}
}
@@ -602,7 +630,6 @@ namespace AyaNova
AySchema.CheckAndUpdateAsync(dbContext, _newLog).Wait();
//Check database integrity
_newLog.LogDebug("DB integrity check");
DbUtil.CheckFingerPrintAsync(AySchema.EXPECTED_COLUMN_COUNT,
@@ -613,8 +640,9 @@ namespace AyaNova
AySchema.EXPECTED_ROUTINES,
_newLog).Wait();
//Initialize license
AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog).Wait();
//Initialize license if not already done (due to there being no db at all yet)
if (!licenseChecked)
AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog).Wait();
//Set static global biz settings
_newLog.LogDebug("Global settings");