Update to properly handle revoke licenses

This commit is contained in:
2022-08-29 15:26:30 +00:00
parent 9b7508afe3
commit da4255a531
3 changed files with 36 additions and 29 deletions

View File

@@ -901,6 +901,10 @@ namespace AyaNova.Core
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
}
//Only check quantities if it's not a revoke token which should always pass through
if (ParsedNewKey.RegisteredTo != REVOKED_TOKEN)
{
#if (SUBSCRIPTION_BUILD)
//SUBSCRIPTION USER COUNTS - new license causes exceeding counts?
@@ -928,18 +932,18 @@ namespace AyaNova.Core
throw new ApplicationException(err);
#else
//PERPETUAL, vet the TECHCOUNT - new license causes exceeding count?
long NewTechCount = ParsedNewKey.ActiveTechsCount;
if (await AyaNova.Biz.UserBiz.ActiveTechUserCountAsync() > NewTechCount)
{
//attempt to set enough of the eldest last login techs to inactive
await AyaNova.Biz.UserBiz.DeActivateExcessiveTechs(NewTechCount, log);
//PERPETUAL, vet the TECHCOUNT - new license causes exceeding count?
long NewTechCount = ParsedNewKey.ActiveTechsCount;
if (await AyaNova.Biz.UserBiz.ActiveTechUserCountAsync() > NewTechCount)
throw new ApplicationException("E1020 - Can't install key, too many active techs and / or subcontractors in database. Deactivate enough to install key.");
}
#endif
{
//attempt to set enough of the eldest last login techs to inactive
await AyaNova.Biz.UserBiz.DeActivateExcessiveTechs(NewTechCount, log);
if (await AyaNova.Biz.UserBiz.ActiveTechUserCountAsync() > NewTechCount)
throw new ApplicationException("E1020 - Can't install key, too many active techs and / or subcontractors in database. Deactivate enough to install key.");
}
#endif
}
//Update current license
@@ -1063,17 +1067,18 @@ EQIDAQAB
#endregion get values
//Check if attempting to use a build of AyaNova that is newer than maintenance subscription expiry
if (MExBB(Util.FileUtil.GetLinkerTimestampUtc(System.Reflection.Assembly.GetExecutingAssembly()), key))
if (key.RegisteredTo != REVOKED_TOKEN)
{
Console.WriteLine(LICENSE_MISMATCH_TO_BUILD_ERROR);
log.LogError("E1020 - build too new for license");
//NOTE: LICENSE_MISMATCH_TO_BUILD_ERROR matched for in startup.cs DO NOT change this without fixing the side effects
throw new ApplicationException(LICENSE_MISMATCH_TO_BUILD_ERROR);
}
//Check if attempting to use a build of AyaNova that is newer than maintenance subscription expiry
if (MExBB(Util.FileUtil.GetLinkerTimestampUtc(System.Reflection.Assembly.GetExecutingAssembly()), key))
{
Console.WriteLine(LICENSE_MISMATCH_TO_BUILD_ERROR);
log.LogError("E1020 - build too new for license");
//NOTE: LICENSE_MISMATCH_TO_BUILD_ERROR matched for in startup.cs DO NOT change this without fixing the side effects
throw new ApplicationException(LICENSE_MISMATCH_TO_BUILD_ERROR);
}
//Subscription licenses only for subscription builds and Perpetual licenses only for Perpetual builds
//Subscription licenses only for subscription builds and Perpetual licenses only for Perpetual builds
#if (SUBSCRIPTION_BUILD)
if(key.Perpetual){
Console.WriteLine(LICENSE_MISMATCH_TO_BUILD_ERROR);
@@ -1082,16 +1087,16 @@ EQIDAQAB
throw new ApplicationException(LICENSE_MISMATCH_TO_BUILD_ERROR);
}
#else
if (!key.Perpetual)
{
Console.WriteLine(LICENSE_MISMATCH_TO_BUILD_ERROR);
log.LogError("E1020 - perpetual build but subscription key");
//NOTE: LICENSE_MISMATCH_TO_BUILD_ERROR bit below is checked for in startup.cs DO NOT remove this without fixing the side effects
throw new ApplicationException(LICENSE_MISMATCH_TO_BUILD_ERROR);
}
if (!key.Perpetual)
{
Console.WriteLine(LICENSE_MISMATCH_TO_BUILD_ERROR);
log.LogError("E1020 - perpetual build but subscription key");
//NOTE: LICENSE_MISMATCH_TO_BUILD_ERROR bit below is checked for in startup.cs DO NOT remove this without fixing the side effects
throw new ApplicationException(LICENSE_MISMATCH_TO_BUILD_ERROR);
}
#endif
}
//All is well return key
return key;