This commit is contained in:
2020-06-17 17:59:34 +00:00
parent 6cdf44cb6f
commit fb586e0f5b
5 changed files with 603 additions and 74 deletions

View File

@@ -36,7 +36,7 @@ namespace rockfishCore.Util
#region license classes
//DTO object returned on license query
internal class LicenseFeature
public class LicenseFeature
{
//name of feature / product
public string Feature { get; set; }
@@ -53,7 +53,14 @@ namespace rockfishCore.Util
{
Features = new List<LicenseFeature>();
RegisteredTo = UNLICENSED_TOKEN;
Id = RegisteredTo;
//Id = RegisteredTo;
LicenseFormat = "8";
var vv = Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
string sId = vv.ToString();
if (sId.Contains(","))
sId = sId.Split('.')[0];
Id = $"00-{sId}";
}
public bool IsEmpty
@@ -169,7 +176,7 @@ namespace rockfishCore.Util
// private static string SAMPLE_KEY = @"[KEY
// {
// ""Key"": {
// ""LicenseFormat"": ""2018"",
// ""LicenseFormat"": ""8"",
// ""Id"": ""34-1516288681"", <----Customer id followed by key serial id
// ""RegisteredTo"": ""Super TestCo"",
// ""DBID"": ""df558559-7f8a-4c7b-955c-959ebcdf71f3"",
@@ -210,13 +217,13 @@ namespace rockfishCore.Util
//Build a sample test key, sign it and return it
AyaNovaLicenseKey k = new AyaNovaLicenseKey();
k.LicenseFormat = "2018";
k.LicenseFormat = "8";
var vv = Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
string sId = vv.ToString();
if (sId.Contains(","))
sId = sId.Split('.')[0];
k.Id = $"00-{sId}";
// var vv = Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
// string sId = vv.ToString();
// if (sId.Contains(","))
// sId = sId.Split('.')[0];
// k.Id = $"00-{sId}";
k.RegisteredTo = CompanyName;
k.DbId = dbid;
@@ -232,66 +239,26 @@ namespace rockfishCore.Util
k.Features.Add(new LicenseFeature() { Feature = ACCOUNTING_FEATURE_NAME, Count = 0 });
k.Features.Add(new LicenseFeature() { Feature = SERVICE_TECHS_FEATURE_NAME, Count = 1000 });
return genKey(k);
return GenerateRavenKey(k);
}
#region RAVEN test code for development
//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}");
public static string GetRavenTestKey(Guid dbid)
{
//Build a sample test key, sign it and return it
AyaNovaLicenseKey k = new AyaNovaLicenseKey();
k.LicenseFormat = "2018";
var vv = Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
string sId = vv.ToString();
if (sId.Contains(","))
sId = sId.Split('.')[0];
k.Id = $"00-{sId}";
k.RegisteredTo = "Best Besterson Inc.";
k.DbId = dbid;
//add accounting and user features either way
k.Features.Add(new LicenseFeature() { Feature = ACCOUNTING_FEATURE_NAME, Count = 0 });
k.Features.Add(new LicenseFeature() { Feature = SERVICE_TECHS_FEATURE_NAME, Count = 1000 });
//fake trial key or fake licensed key
if (dbid == TEST_TRIAL_KEY_DBID)
{
k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddMonths(1);
k.Features.Add(new LicenseFeature() { Feature = TRIAL_FEATURE_NAME, Count = 0 });
}
else
{
k.MaintenanceExpiration = DateTime.UtcNow.AddYears(1);
k.LicenseExpiration = DateUtil.EmptyDateValue;//1/1/5555 as per spec
}
return genKey(k);
}
#endregion
/// <summary>
/// New RAVEN key generator, so far just for testing purposes
/// RAVEN key generator
/// </summary>
/// <returns></returns>
private static string genKey(AyaNovaLicenseKey k)
internal static string GenerateRavenKey(AyaNovaLicenseKey k)
{
if (string.IsNullOrWhiteSpace(k.RegisteredTo))
throw new ArgumentException("RegisteredTo is required", "RegisteredTo");
if (k.DbId == Guid.Empty)
throw new ArgumentException("DBId is required", "RegisteredTo");
try
{
@@ -438,28 +405,53 @@ oArP0E2Vbow3JMxq/oeXmHbrLMLQfYyXwFmciLFigOtkd45bfHdrbA==
// private static void AddLicensePlugin(Newtonsoft.Json.JsonWriter w, string pluginName, DateTime pluginExpires)
// {
// //this dictionary is used by the additional message code to
// //make the human readable portion of the license
// _plugins.Add(pluginName, pluginExpires);
// //this is adding it to the actual key
// w.WriteStartObject();
// w.WritePropertyName("Item");
// w.WriteValue(pluginName);
// w.WritePropertyName("SubscriptionExpires");
// w.WriteValue(pluginExpires);
// w.WriteEndObject();
// //----------------
// }
//eoc
}
//eons
}
}
// #region RAVEN test code for development
// //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}");
// public static string GetRavenTestKey(Guid dbid)
// {
// //Build a sample test key, sign it and return it
// AyaNovaLicenseKey k = new AyaNovaLicenseKey();
// k.LicenseFormat = "8";
// var vv = Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
// string sId = vv.ToString();
// if (sId.Contains(","))
// sId = sId.Split('.')[0];
// k.Id = $"00-{sId}";
// k.RegisteredTo = "Best Besterson Inc.";
// k.DbId = dbid;
// //add accounting and user features either way
// k.Features.Add(new LicenseFeature() { Feature = ACCOUNTING_FEATURE_NAME, Count = 0 });
// k.Features.Add(new LicenseFeature() { Feature = SERVICE_TECHS_FEATURE_NAME, Count = 1000 });
// //fake trial key or fake licensed key
// if (dbid == TEST_TRIAL_KEY_DBID)
// {
// k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddMonths(1);
// k.Features.Add(new LicenseFeature() { Feature = TRIAL_FEATURE_NAME, Count = 0 });
// }
// else
// {
// k.MaintenanceExpiration = DateTime.UtcNow.AddYears(1);
// k.LicenseExpiration = DateUtil.EmptyDateValue;//1/1/5555 as per spec
// }
// return genKey(k);
// }
// #endregion