Skip to content

Commit 0fedaf3

Browse files
committed
feat: logging improved
fix: initial license check
1 parent 825a47e commit 0fedaf3

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

Common/Licensing/GlobalLicenseService.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using KY.Core;
1+
using System;
2+
using KY.Core;
23
using KY.Core.DataAccess;
34
using KY.Generator.Models;
45
using Newtonsoft.Json;
@@ -23,7 +24,15 @@ public SignedLicense Read()
2324
{
2425
if (FileSystem.FileExists(this.fileName))
2526
{
26-
this.cache = JsonConvert.DeserializeObject<SignedLicense>(FileSystem.ReadAllText(this.fileName));
27+
try
28+
{
29+
this.cache = JsonConvert.DeserializeObject<SignedLicense>(FileSystem.ReadAllText(this.fileName));
30+
}
31+
catch (Exception exception)
32+
{
33+
Logger.Warning("Could not read global license." + Environment.NewLine + exception.Message + Environment.NewLine + exception.StackTrace);
34+
this.cache = null;
35+
}
2736
}
2837
this.cache ??= new SignedLicense();
2938
}

Common/Licensing/LicenseService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void Check()
2929
{
3030
try
3131
{
32-
Guid licenseId = this.globalSettingsService.Read().License;
32+
Guid licenseId = this.globalSettingsService.Read()?.License ?? Guid.Empty;
3333
SignedLicense license = this.globalLicenseService.Read();
3434
if (license.License.Id == licenseId && (license.License.ValidUntil.Date - DateTime.Today).TotalDays >= 7 && license.Validate())
3535
{

Common/Settings/GlobalSettingsService.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ public GlobalSettings Read()
2626
stopwatch.Start();
2727
if (FileSystem.FileExists(this.fileName))
2828
{
29-
this.cache = JsonConvert.DeserializeObject<GlobalSettings>(FileSystem.ReadAllText(this.fileName));
29+
try
30+
{
31+
this.cache = JsonConvert.DeserializeObject<GlobalSettings>(FileSystem.ReadAllText(this.fileName));
32+
}
33+
catch (Exception exception)
34+
{
35+
Logger.Warning("Could not read global settings." + Environment.NewLine + exception.Message + Environment.NewLine + exception.StackTrace);
36+
this.cache = null;
37+
}
3038
}
31-
else
39+
if (this.cache == null)
3240
{
33-
this.cache ??= new GlobalSettings();
41+
this.cache = new GlobalSettings();
3442
this.Write();
3543
}
3644
stopwatch.Stop();

Reflection/Readers/ReflectionReader.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ public void Read(ReflectionReadConfiguration configuration, IOptions caller = nu
2727
Logger.Trace($"Class {configuration.Namespace}.{configuration.Name} not found");
2828
return;
2929
}
30-
ModelTransferObject selfModel = this.modelReader.Read(type, caller);
31-
IOptions modelOptions = this.options.Get(selfModel);
32-
if (configuration.OnlySubTypes || modelOptions.OnlySubTypes)
30+
try
3331
{
34-
modelOptions.OnlySubTypes = true;
32+
ModelTransferObject selfModel = this.modelReader.Read(type, caller);
33+
IOptions modelOptions = this.options.Get(selfModel);
34+
if (configuration.OnlySubTypes || modelOptions.OnlySubTypes)
35+
{
36+
modelOptions.OnlySubTypes = true;
37+
}
38+
}
39+
catch
40+
{
41+
Logger.Warning("Reflection reader could not read " + type.FullName);
42+
throw;
3543
}
3644
}
3745
}

0 commit comments

Comments
 (0)