Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 6e92c5b

Browse files
committed
Also automatically register license key in SERVICESTACK_LICENSE Environment Variable
1 parent fa22d66 commit 6e92c5b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/ServiceStack.Text/PclExport.Net40.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public override string[] GetDirectoryNames(string dirPath, string searchPattern
119119
}
120120

121121
public const string AppSettingsKey = "servicestack:license";
122+
public const string EnvironmentKey = "SERVICESTACK_LICENSE";
123+
122124
public override void RegisterLicenseFromConfig()
123125
{
124126
#if ANDROID
@@ -127,6 +129,14 @@ public override void RegisterLicenseFromConfig()
127129
//Automatically register license key stored in <appSettings/>
128130
var licenceKeyText = System.Configuration.ConfigurationManager.AppSettings[AppSettingsKey];
129131
if (!string.IsNullOrEmpty(licenceKeyText))
132+
{
133+
LicenseUtils.RegisterLicense(licenceKeyText);
134+
return;
135+
}
136+
137+
//or SERVICESTACK_LICENSE Environment variable
138+
licenceKeyText = Environment.GetEnvironmentVariable(EnvironmentKey);
139+
if (!string.IsNullOrEmpty(licenceKeyText))
130140
{
131141
LicenseUtils.RegisterLicense(licenceKeyText);
132142
}
@@ -1092,7 +1102,7 @@ private static int VerifyAndGetStartIndex(string value, Type createMapType)
10921102

10931103
public static Hashtable ParseHashtable(string value)
10941104
{
1095-
if (value == null)
1105+
if (value == null)
10961106
return null;
10971107

10981108
var index = VerifyAndGetStartIndex(value, typeof(Hashtable));

tests/ServiceStack.Text.Tests/LicensingTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ public void Can_register_valid_license()
131131
Assert.That(LicenseUtils.ActivatedLicenseFeatures(), Is.EqualTo(LicenseFeature.All));
132132
}
133133

134+
[Test, Explicit]
135+
public void Can_register_valid_license_from_EnvironmentVariable()
136+
{
137+
#if !SL5
138+
var licenseKeyText = Environment.GetEnvironmentVariable("SERVICESTACK_LICENSE");
139+
Licensing.RegisterLicense(licenseKeyText);
140+
Assert.That(LicenseUtils.ActivatedLicenseFeatures(), Is.EqualTo(LicenseFeature.All));
141+
#endif
142+
}
143+
134144
[Test]
135145
public void Expired_licenses_throws_LicenseException()
136146
{

0 commit comments

Comments
 (0)