@@ -118,6 +118,16 @@ private Version(VersionInfo info, bool expired) {
118
118
public static iText . Kernel . Version GetInstance ( ) {
119
119
lock ( staticLock ) {
120
120
if ( version != null ) {
121
+ try {
122
+ LicenseScheduledCheck ( ) ;
123
+ }
124
+ catch ( Exception e ) {
125
+ // If any exception occurs during scheduled check of core license,
126
+ // then it means that license is not valid yet, so roll back to AGPL.
127
+ // The key value is null as it is similar to case
128
+ // when an exception has been thrown during initial license loading
129
+ AtomicSetVersion ( InitAGPLVersion ( e , null ) ) ;
130
+ }
121
131
return version ;
122
132
}
123
133
}
@@ -195,7 +205,7 @@ public static iText.Kernel.Version GetInstance() {
195
205
/// <summary>Checks if the AGPL version is used.</summary>
196
206
/// <returns>returns true if the AGPL version is used.</returns>
197
207
public static bool IsAGPLVersion ( ) {
198
- return GetInstance ( ) . GetVersion ( ) . IndexOf ( AGPL , StringComparison . Ordinal ) > 0 ;
208
+ return GetInstance ( ) . IsAGPL ( ) ;
199
209
}
200
210
201
211
/// <summary>Is the license expired?</summary>
@@ -250,6 +260,12 @@ public VersionInfo GetInfo() {
250
260
return info ;
251
261
}
252
262
263
+ /// <summary>Checks if the current object has been initialized with AGPL license.</summary>
264
+ /// <returns>returns true if the current object has been initialized with AGPL license.</returns>
265
+ private bool IsAGPL ( ) {
266
+ return GetVersion ( ) . IndexOf ( AGPL , StringComparison . Ordinal ) > 0 ;
267
+ }
268
+
253
269
private static iText . Kernel . Version InitDefaultLicensedVersion ( String ownerName , String key ) {
254
270
String producer = producerLine + " (" + ownerName ;
255
271
if ( ! key . ToLowerInvariant ( ) . StartsWith ( "trial" ) ) {
@@ -271,6 +287,11 @@ private static iText.Kernel.Version InitVersion(String producer, String key, boo
271
287
return new iText . Kernel . Version ( new VersionInfo ( iTextProductName , release , producer , key ) , expired ) ;
272
288
}
273
289
290
+ private static Type GetLicenseKeyClass ( ) {
291
+ String licenseKeyClassFullName = "iText.License.LicenseKey, itext.licensekey" ;
292
+ return GetClassFromLicenseKey ( licenseKeyClassFullName ) ;
293
+ }
294
+
274
295
private static void CheckLicenseVersion ( String coreVersionString , String licenseVersionString ) {
275
296
String [ ] coreVersions = ParseVersionString ( coreVersionString ) ;
276
297
String [ ] licenseVersions = ParseVersionString ( licenseVersionString ) ;
@@ -364,31 +385,48 @@ private static iText.Kernel.Version AtomicSetVersion(iText.Kernel.Version newVer
364
385
}
365
386
}
366
387
367
- private static Type GetLicenseKeyClass ( ) {
368
- String licenseKeyClassPartialName = "iText.License.LicenseKey, itext.licensekey" ;
369
- String licenseKeyClassFullName = null ;
388
+ private static void LicenseScheduledCheck ( ) {
389
+ if ( version . IsAGPL ( ) ) {
390
+ return ;
391
+ }
392
+ String licenseKeyProductFullName = "iText.License.LicenseKeyProduct, itext.licensekey" ;
393
+ String checkLicenseKeyMethodName = "ScheduledCheck" ;
394
+ try {
395
+ Type licenseKeyClass = GetLicenseKeyClass ( ) ;
396
+ Type licenseKeyProductClass = GetClassFromLicenseKey ( licenseKeyProductFullName ) ;
397
+ Type [ ] cArg = new Type [ ] { licenseKeyProductClass } ;
398
+ MethodInfo method = licenseKeyClass . GetMethod ( checkLicenseKeyMethodName , cArg ) ;
399
+ method . Invoke ( null , new Object [ ] { null } ) ;
400
+ }
401
+ catch ( Exception e ) {
402
+ throw new Exception ( e . Message , e ) ;
403
+ }
404
+ }
405
+
406
+ private static Type GetClassFromLicenseKey ( String classPartialName ) {
407
+ String classFullName = null ;
370
408
371
409
Assembly kernelAssembly = typeof ( Version ) . GetAssembly ( ) ;
372
410
Attribute keyVersionAttr = kernelAssembly . GetCustomAttribute ( typeof ( KeyVersionAttribute ) ) ;
373
411
if ( keyVersionAttr is KeyVersionAttribute ) {
374
412
String keyVersion = ( ( KeyVersionAttribute ) keyVersionAttr ) . KeyVersion ;
375
413
String format = "{0}, Version={1}, Culture=neutral, PublicKeyToken=8354ae6d2174ddca" ;
376
- licenseKeyClassFullName = String . Format ( format , licenseKeyClassPartialName , keyVersion ) ;
414
+ classFullName = String . Format ( format , classPartialName , keyVersion ) ;
377
415
}
378
416
379
417
Type type = null ;
380
- if ( licenseKeyClassFullName != null ) {
418
+ if ( classFullName != null ) {
381
419
String fileLoadExceptionMessage = null ;
382
420
try {
383
- type = System . Type . GetType ( licenseKeyClassFullName ) ;
421
+ type = System . Type . GetType ( classFullName ) ;
384
422
} catch ( FileLoadException fileLoadException ) {
385
423
fileLoadExceptionMessage = fileLoadException . Message ;
386
424
}
387
425
388
426
if ( type == null ) {
389
427
ILog logger = LogManager . GetLogger ( typeof ( Version ) ) ;
390
428
try {
391
- type = System . Type . GetType ( licenseKeyClassPartialName ) ;
429
+ type = System . Type . GetType ( classPartialName ) ;
392
430
} catch {
393
431
// ignore
394
432
}
0 commit comments