2
2
using Nager . Date . HolidayProviders ;
3
3
using Nager . Date . Models ;
4
4
using Nager . Date . ReligiousProviders ;
5
- using Nager . LicenseSystem ;
6
5
using System ;
7
6
using System . Collections . Generic ;
8
7
using System . Linq ;
9
- using System . Runtime . CompilerServices ;
10
8
11
9
namespace Nager . Date
12
10
{
@@ -141,7 +139,7 @@ public static class HolidaySystem
141
139
{ CountryCode . ZW , new Lazy < IHolidayProvider > ( ( ) => new ZimbabweHolidayProvider ( _catholicProvider ) ) }
142
140
} ;
143
141
144
- private static bool ? _licenseValid ;
142
+ private static LicenseCheckStatus _licenseCheckStatus = LicenseCheckStatus . NotChecked ;
145
143
146
144
/// <summary>
147
145
/// License Key
@@ -155,24 +153,24 @@ private static void CheckLicense(string? licenseKey)
155
153
{
156
154
if ( string . IsNullOrEmpty ( licenseKey ) )
157
155
{
158
- _licenseValid = false ;
159
- throw new LicenseKeyException ( "No LicenseKey" ) ;
156
+ _licenseCheckStatus = LicenseCheckStatus . NotConfigured ;
157
+ return ;
160
158
}
161
159
162
160
var licenseInfo = LicenseHelper . CheckLicenseKey ( licenseKey ) ;
163
161
if ( licenseInfo is null )
164
162
{
165
- _licenseValid = false ;
166
- throw new LicenseKeyException ( "Invalid LicenseKey" ) ;
163
+ _licenseCheckStatus = LicenseCheckStatus . Invalid ;
164
+ return ;
167
165
}
168
166
169
167
if ( licenseInfo . ValidUntil < DateTime . Today )
170
168
{
171
- _licenseValid = false ;
172
- throw new LicenseKeyException ( "Expried LicenseKey" ) ;
169
+ _licenseCheckStatus = LicenseCheckStatus . Expired ;
170
+ return ;
173
171
}
174
172
175
- _licenseValid = true ;
173
+ _licenseCheckStatus = LicenseCheckStatus . Valid ;
176
174
}
177
175
178
176
/// <summary>
@@ -211,15 +209,23 @@ public static IHolidayProvider GetHolidayProvider(CountryCode countryCode)
211
209
/// <returns></returns>
212
210
public static bool TryGetHolidayProvider ( CountryCode countryCode , out IHolidayProvider holidayProvider )
213
211
{
214
- if ( _licenseValid is null )
212
+ if ( _licenseCheckStatus == LicenseCheckStatus . NotChecked )
215
213
{
216
214
CheckLicense ( LicenseKey ) ;
217
215
}
218
216
219
- if ( _licenseValid is not null && ! _licenseValid . Value )
217
+ switch ( _licenseCheckStatus )
220
218
{
221
- holidayProvider = NoHolidaysHolidayProvider . Instance ;
222
- return false ;
219
+ case LicenseCheckStatus . Valid :
220
+ break ;
221
+ case LicenseCheckStatus . NotConfigured :
222
+ throw new LicenseKeyException ( "No LicenseKey" ) ;
223
+ case LicenseCheckStatus . Invalid :
224
+ throw new LicenseKeyException ( "Invalid LicenseKey" ) ;
225
+ case LicenseCheckStatus . Expired :
226
+ throw new LicenseKeyException ( "Expried LicenseKey" ) ;
227
+ default :
228
+ throw new LicenseKeyException ( "Unknown LicenseKey Check Status" ) ;
223
229
}
224
230
225
231
if ( _holidaysProviders . TryGetValue ( countryCode , out var provider ) )
0 commit comments