6
6
using System . Diagnostics ;
7
7
using System . IO ;
8
8
using System . Linq ;
9
+ using System . Net . Http ;
9
10
using System . Reflection ;
10
- using System . Threading ;
11
11
using System . Threading . Tasks ;
12
12
using Automatica . Core . Base . Common ;
13
13
using Automatica . Core . Internals . Cloud ;
@@ -40,7 +40,7 @@ public sealed class LicenseContext : ILicenseContext
40
40
public int MaxSatellites { get ; private set ; }
41
41
public bool AllowTextToSpeech { get ; private set ; }
42
42
43
- private readonly AsyncNonKeyedLocker _semaphore = new ( 1 ) ;
43
+ private readonly AsyncNonKeyedLocker _semaphore = new ( ) ;
44
44
45
45
public bool DriverLicenseCountExceeded ( )
46
46
{
@@ -76,16 +76,28 @@ public async Task<bool> Init()
76
76
using ( await _semaphore . LockAsync ( ) )
77
77
{
78
78
_dataPointsInUse = 0 ;
79
- string pubKey = "" ;
79
+ string pubKey ;
80
80
using ( var reader = new StreamReader ( Assembly . GetExecutingAssembly ( ) . GetManifestResourceStream ( "Automatica.Core.Internals.pub.txt" ) ?? throw new InvalidOperationException ( ) ) )
81
81
{
82
82
pubKey = await reader . ReadToEndAsync ( ) ;
83
83
}
84
84
85
85
try
86
86
{
87
+ var licenseString = String . Empty ;
87
88
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
+ }
89
101
90
102
if ( ! String . IsNullOrEmpty ( licenseString ) )
91
103
{
@@ -104,7 +116,6 @@ public async Task<bool> Init()
104
116
var license = Standard . Licensing . License . Load ( file ) ;
105
117
if ( license . Id != ServerInfo . ServerUid )
106
118
{
107
- await file . DisposeAsync ( ) ;
108
119
File . Delete ( LicensePath ) ;
109
120
return false ;
110
121
}
@@ -128,6 +139,7 @@ public async Task<bool> Init()
128
139
}
129
140
}
130
141
}
142
+
131
143
catch ( System . Xml . XmlException )
132
144
{
133
145
File . Delete ( LicensePath ) ;
0 commit comments