Skip to content

Commit 0f08564

Browse files
committed
handle http exception correct
1 parent d08a28b commit 0f08564

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/automatica.core/Automatica.Core.Internals/License/LicenseContext.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using System.Diagnostics;
77
using System.IO;
88
using System.Linq;
9+
using System.Net.Http;
910
using System.Reflection;
10-
using System.Threading;
1111
using System.Threading.Tasks;
1212
using Automatica.Core.Base.Common;
1313
using Automatica.Core.Internals.Cloud;
@@ -40,7 +40,7 @@ public sealed class LicenseContext : ILicenseContext
4040
public int MaxSatellites { get; private set; }
4141
public bool AllowTextToSpeech { get; private set; }
4242

43-
private readonly AsyncNonKeyedLocker _semaphore = new(1);
43+
private readonly AsyncNonKeyedLocker _semaphore = new();
4444

4545
public bool DriverLicenseCountExceeded()
4646
{
@@ -76,16 +76,28 @@ public async Task<bool> Init()
7676
using (await _semaphore.LockAsync())
7777
{
7878
_dataPointsInUse = 0;
79-
string pubKey = "";
79+
string pubKey;
8080
using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Automatica.Core.Internals.pub.txt") ?? throw new InvalidOperationException()))
8181
{
8282
pubKey = await reader.ReadToEndAsync();
8383
}
8484

8585
try
8686
{
87+
var licenseString = String.Empty;
8788

88-
var licenseString = await _cloudApi.GetLicense();
89+
try
90+
{
91+
licenseString = await _cloudApi.GetLicense();
92+
}
93+
catch (HttpRequestException)
94+
{
95+
//ignore right now, if we have a local license available!
96+
if (!File.Exists(LicensePath))
97+
{
98+
throw;
99+
}
100+
}
89101

90102
if (!String.IsNullOrEmpty(licenseString))
91103
{
@@ -104,7 +116,6 @@ public async Task<bool> Init()
104116
var license = Standard.Licensing.License.Load(file);
105117
if (license.Id != ServerInfo.ServerUid)
106118
{
107-
await file.DisposeAsync();
108119
File.Delete(LicensePath);
109120
return false;
110121
}
@@ -128,6 +139,7 @@ public async Task<bool> Init()
128139
}
129140
}
130141
}
142+
131143
catch (System.Xml.XmlException)
132144
{
133145
File.Delete(LicensePath);

0 commit comments

Comments
 (0)