This commit is contained in:
2018-12-17 23:37:46 +00:00
parent 0514d86b4f
commit 677388910a
8 changed files with 140 additions and 107 deletions

View File

@@ -104,6 +104,13 @@ namespace AyaNova.Core
return null;
}
public long ActiveNumber
{
get
{
return GetLicenseFeature(SERVICE_TECHS_FEATURE_NAME).Count;
}
}
/// <summary>
/// Check for the existance of license feature
@@ -446,7 +453,7 @@ namespace AyaNova.Core
if (ldb.Key == "none")
{
var msg = "License key not found in database, running in unlicensed mode";
var msg = "E1020 - License key not found in database, running in unlicensed mode";
apiServerState.SetSystemLock(msg);
log.LogWarning(msg);
return;
@@ -456,9 +463,9 @@ namespace AyaNova.Core
AyaNovaLicenseKey k = Parse(ldb.Key, log);
if (k == null)
{
var msg = "Error: License key in database is not valid, running in unlicensed mode";
var msg = "E1020 - License key in database is not valid, running in unlicensed mode";
apiServerState.SetSystemLock(msg);
log.LogError(msg);
log.LogCritical(msg);
return;
}
@@ -466,9 +473,18 @@ namespace AyaNova.Core
if (_ActiveLicense.LicenseExpired)
{
var msg = $"License key expired {DateUtil.ServerDateTimeString(_ActiveLicense.LicenseExpiration)}";
var msg = $"E1020 - License key expired {DateUtil.ServerDateTimeString(_ActiveLicense.LicenseExpiration)}";
apiServerState.SetSystemLock(msg);
log.LogWarning(msg);
log.LogCritical(msg);
return;
}
//Has someone been trying funny business with the active techs in the db?
if (AyaNova.Biz.UserBiz.ActiveCount > _ActiveLicense.ActiveNumber)
{
var msg = $"E1020 - Active count exceeded capacity";
apiServerState.SetSystemLock(msg);
log.LogCritical(msg);
return;
}
@@ -484,7 +500,8 @@ namespace AyaNova.Core
catch (Exception ex)
{
var msg = "E1020 - Error initializing license key";
log.LogError(ex, msg);
log.LogCritical(ex, msg);
apiServerState.SetSystemLock(msg);
throw new ApplicationException(msg, ex);
}
}
@@ -503,7 +520,7 @@ namespace AyaNova.Core
if (ParsedNewKey == null)
{
throw new ApplicationException("License.Install -> key could not be parsed");
throw new ApplicationException("E1020 - License.Install -> key could not be parsed");
}
//Can't install a trial into a non-empty db
@@ -512,6 +529,12 @@ namespace AyaNova.Core
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)
{
throw new ApplicationException("E1020 - Can't install key, too many active techs and / or subcontractors in database. Deactivate enough to install key.");
}
//Update current license
CurrentInDbKeyRecord.Key = RawTextNewKey;
//LOOKAT: reason, resultcode etc
@@ -547,7 +570,7 @@ namespace AyaNova.Core
if (string.IsNullOrWhiteSpace(k))
{
throw new ApplicationException("License.Parse -> License key is empty and can't be validated");
throw new ApplicationException("E1020 - License.Parse -> License key is empty and can't be validated");
}
try
@@ -557,7 +580,7 @@ namespace AyaNova.Core
!k.Contains("[SIGNATURE") ||
!k.Contains("SIGNATURE]"))
{
throw new ApplicationException("License.Parse -> License key is missing required delimiters");
throw new ApplicationException("E1020 - License.Parse -> License key is missing required delimiters");
}
@@ -588,7 +611,7 @@ EQIDAQAB
signer.BlockUpdate(msgBytes, 0, msgBytes.Length);
if (!signer.VerifySignature(expectedSig))
{
throw new ApplicationException("License.Parse -> License key failed integrity check and is not valid");
throw new ApplicationException("E1020 - License.Parse -> License key failed integrity check and is not valid");
}
#endregion check signature
@@ -598,7 +621,7 @@ EQIDAQAB
key.LicenseFormat = (string)token.SelectToken("Key.LicenseFormat");
if (key.LicenseFormat != "2018")
throw new ApplicationException($"License.Parse -> License key format {key.LicenseFormat} not recognized");
throw new ApplicationException($"E1020 - License.Parse -> License key format {key.LicenseFormat} not recognized");
key.Id = (string)token.SelectToken("Key.Id");
key.RegisteredTo = (string)token.SelectToken("Key.RegisteredTo");
key.DbId = (Guid)token.SelectToken("Key.DBID");