Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide users access to license information at runtime #3656

Open
ramonsmits opened this issue Mar 31, 2016 · 0 comments
Open

Provide users access to license information at runtime #3656

ramonsmits opened this issue Mar 31, 2016 · 0 comments
Milestone

Comments

@ramonsmits
Copy link
Member

Customer requests access to license information at runtime.

In the customers case it seems they embed NServiceBus and want to present the license data in their UI.

We could expose an actual object representing the license but we could also expose the license blob of the loaded license.

Code

The customer currently is using reflection to access the license info.

private string GetNServiceBusLicenseInfo()
{
  const string nServiceBusCoreAssembyName = "NServiceBus.Core, Version = 5.0.0.0, Culture = neutral, PublicKeyToken = 9fc386479f8a226c";
  var result = "There was an Error obtaining NServiceBus License Information.";
  try
  {
    var licenseManagerType = Type.GetType($"NServiceBus.Licensing.LicenseManager, {nServiceBusCoreAssembyName}");
    var memberInfo = licenseManagerType?.GetField("license", BindingFlags.NonPublic | BindingFlags.Static);
    if (memberInfo != null)
    {
      var info = memberInfo.GetValue(null);
      var licenseType = Type.GetType($"Particular.Licensing.License, {nServiceBusCoreAssembyName}");
      if (licenseType != null)
      {
        var expirationDate = licenseType.GetProperty("ExpirationDate").GetValue(info) as DateTime?;
        var licenseTypeInfo = licenseType.GetProperty("LicenseType").GetValue(info);
        result = $"License Type: {licenseTypeInfo}, Expiration Date: {expirationDate.Value.ToShortDateString()}";
      }
    }
  }
  catch (Exception e)
  {
    _logger.Info(ErrorType.HealthCheckFailed, result, e);
  }
  return result;
}

Reference

https://nservicebus.desk.com/agent/case/17833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants