feature: online activation

This commit is contained in:
Gary Sharp
2024-12-27 14:28:56 +11:00
parent 39ba206831
commit b6dfaa3445
35 changed files with 2287 additions and 346 deletions
+45 -4
View File
@@ -242,9 +242,34 @@ namespace Disco.Data.Configuration
}
else if (itemType.BaseType != null && itemType.BaseType == typeof(Enum))
{
// Enum
// enum
itemValue = Enum.Parse(typeof(T), item.Item1.Value);
}
else if (itemType.IsGenericType &&
itemType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
IsConvertableFromString(Nullable.GetUnderlyingType(itemType)))
{
// nullable
itemValue = (T)Convert.ChangeType(item.Item1.Value, Nullable.GetUnderlyingType(itemType));
}
else if (itemType == typeof(Guid))
{
// guid
itemValue = new Guid(item.Item1.Value);
}
else if (itemType == typeof(Guid?))
{
// guid
if (string.IsNullOrEmpty(item.Item1.Value))
itemValue = null;
else
itemValue = new Guid(item.Item1.Value);
}
else if (itemType == typeof(byte[]))
{
// byte[]
itemValue = Convert.FromBase64String(item.Item1.Value);
}
else
{
// JSON Deserialize
@@ -269,7 +294,7 @@ namespace Disco.Data.Configuration
}
else if (valueType == typeof(object))
{
throw new ArgumentException(string.Format("Cannot serialize the configuration item [{0}].[{1}] which defines a type of [System.Object]", Scope, Key), "Value");
throw new ArgumentException($"Cannot serialize the configuration item [{Scope}].[{Key}] which has the type [System.Object]", "Value");
}
else if (IsConvertableFromString(valueType))
{
@@ -278,9 +303,25 @@ namespace Disco.Data.Configuration
}
else if (valueType.BaseType != null && valueType.BaseType == typeof(Enum))
{
// Enum
// enum
stringValue = Value.ToString();
}
else if (valueType.IsGenericType &&
valueType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
IsConvertableFromString(Nullable.GetUnderlyingType(valueType)))
{
// nullable
stringValue = Value.ToString();
}
else if (valueType == typeof(Guid) || valueType == typeof(Guid?))
{
stringValue = Value.ToString();
}
else if (Value is byte[] valueBytes)
{
// byte[]
stringValue = Convert.ToBase64String(valueBytes);
}
else
{
// JSON Serialize
@@ -290,7 +331,7 @@ namespace Disco.Data.Configuration
CacheSetItem(Database, Scope, Key, stringValue, Value);
}
}
#endregion
#region Cache Helpers
@@ -319,6 +319,29 @@ namespace Disco.Data.Configuration
#endregion
#region UpdateCheck
public bool IsActivated => ActivationId.HasValue;
public DateTime? ActivatedOn
{
get => Get((DateTime?)null);
set => Set(value);
}
public string ActivatedBy
{
get => Get((string)null);
set => Set(value);
}
public Guid? ActivationId
{
get => Get((Guid?)null);
set => Set(value);
}
public byte[] ActivationKey
{
get => Get((byte[])null);
set => Set(value);
}
public bool IsLicensed
{
get => LicenseKey != null && LicenseExpiresOn != null && LicenseExpiresOn > DateTime.UtcNow && LicenseError == null;
@@ -10,6 +10,10 @@ namespace Disco.Data.Migrations
AlterColumn("dbo.UserAttachments", "Comments", c => c.String(maxLength: 500));
AlterColumn("dbo.JobAttachments", "Comments", c => c.String(maxLength: 500));
AlterColumn("dbo.DeviceAttachments", "Comments", c => c.String(maxLength: 500));
Sql("DELETE [dbo].[Configuration] WHERE [Scope]='System' AND [Key] IN ('ActivatedOn', 'ActivationId', 'LicenseExpiresOn')");
Sql("DELETE [dbo].[Configuration] WHERE [Scope]='DocFill' AND [Key] IN ('LicenseExpiresOn')");
Sql("DELETE [dbo].[Configuration] WHERE [Scope]='JobPreferences' AND [Key] IN ('LastExportDate')");
}
public override void Down()