Skip to content

Commit

Permalink
Merge branch 'hotfix-4.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Simons committed Apr 23, 2014
2 parents 010d1f1 + 1ca5856 commit 960fc08
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
20 changes: 18 additions & 2 deletions src/NServiceBus.Core/Licensing/LicenseInitializer.cs
@@ -1,22 +1,38 @@
namespace NServiceBus.Licensing
{
using System;
using Logging;
using Pipeline;
using Pipeline.Contexts;

class LicenseInitializer : PipelineOverride, INeedInitialization
{
public void Init()
{
LicenseManager.InitializeLicense();
var expiredLicense = true;
try
{
LicenseManager.InitializeLicense();

expiredLicense = LicenseManager.HasLicenseExpired();
}
catch (Exception ex)
{
//we only log here to prevent licensing issue to abort startup and cause production outages
Logger.Fatal("Failed to initialize the license",ex);
}


Configure.Component<LicenseBehavior>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.LicenseExpired, LicenseManager.HasLicenseExpired());
.ConfigureProperty(p => p.LicenseExpired, expiredLicense);

}

public override void Override(BehaviorList<ReceivePhysicalMessageContext> behaviorList)
{
behaviorList.Add<LicenseBehavior>();
}

static ILog Logger = LogManager.GetLogger(typeof(LicenseInitializer));
}
}
30 changes: 21 additions & 9 deletions src/NServiceBus.Core/Licensing/LicenseManager.cs
@@ -1,5 +1,6 @@
namespace NServiceBus.Licensing
{
using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
Expand Down Expand Up @@ -116,7 +117,7 @@ static string GetExistingLicense()
string existingLicense;

//look in HKCU
if (new RegistryLicenseStore().TryReadLicense(out existingLicense))
if (UserSidChecker.IsNotSystemSid() && new RegistryLicenseStore().TryReadLicense(out existingLicense))
{
return existingLicense;
}
Expand All @@ -127,7 +128,6 @@ static string GetExistingLicense()
return existingLicense;
}


return LicenseLocationConventions.TryFindLicenseText();
}

Expand All @@ -142,23 +142,35 @@ public static License License
{
if (license == null)
{
InitializeLicense();
try
{
InitializeLicense();
}
catch (Exception ex)
{
//we only log here to prevent licensing issue to abort startup and cause production outages
Logger.Fatal("Failed to initialize the license", ex);
}
}

var nsbLicense = new License
{
AllowedNumberOfWorkerNodes = int.MaxValue,
MaxThroughputPerSecond = int.MaxValue,
ExpirationDate = DateTime.MaxValue
};

if (license.ExpirationDate.HasValue)
if (license != null)
{
nsbLicense.ExpirationDate = license.ExpirationDate.Value;
}
if (license.ExpirationDate.HasValue)
{
nsbLicense.ExpirationDate = license.ExpirationDate.Value;
}

if (license.UpgradeProtectionExpiration.HasValue)
{
nsbLicense.UpgradeProtectionExpiration = license.UpgradeProtectionExpiration.Value;
if (license.UpgradeProtectionExpiration.HasValue)
{
nsbLicense.UpgradeProtectionExpiration = license.UpgradeProtectionExpiration.Value;
}
}

return nsbLicense;
Expand Down

0 comments on commit 960fc08

Please sign in to comment.