Skip to content

Commit

Permalink
Fixed license handler
Browse files Browse the repository at this point in the history
  • Loading branch information
technosoftware committed Mar 5, 2022
1 parent 7f3d00b commit 2703507
Showing 1 changed file with 5 additions and 138 deletions.
143 changes: 5 additions & 138 deletions src/Technosoftware/DaAeHdaClient/LicenseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
using static System.String;

using Technosoftware.DaAeHdaClient.Utilities;
using Technosoftware.DaAeHdaClient.Licensing;
using Technosoftware.DaAeHdaClient.Licensing.Validation;
#endregion

namespace Technosoftware.DaAeHdaClient
Expand Down Expand Up @@ -100,11 +98,10 @@ public enum ProductFeature : uint
/// License Validation Parameters String for the OPC UA Solution .NET
/// </summary>
private const string LicenseParameter =
@"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGILpL7TUaiZj+dO4P78y2gum1scOW2NdSABbWW0d9j72fr3wtox7/LG8EJaJZS7Y33QTSNH9Tt2L/g0HlkQASw==";
@"";
#endregion

#region Internal Fields
internal static EvaluationTimer OpcBaseTimer;
internal static bool LicenseTraceDone;
#endregion

Expand Down Expand Up @@ -190,12 +187,12 @@ public static string Version
/// <summary>
/// Returns the licensed products.
/// </summary>
public static ProductLicense LicensedProduct { get; set; } = ProductLicense.Evaluation;
public static ProductLicense LicensedProduct { get; set; } = ProductLicense.Client;

/// <summary>
/// Returns the licensed OPC UA Features.
/// </summary>
public static ProductFeature LicensedFeatures { get; set; } = ProductFeature.None;
public static ProductFeature LicensedFeatures { get; set; } = ProductFeature.AllFeatures;

/// <summary>
/// Returns the licensed product name.
Expand Down Expand Up @@ -318,11 +315,6 @@ protected static bool CheckLicense()
if (Checked &&
((LicensedProduct & ProductLicense.Client) == ProductLicense.Client))
{
if (OpcBaseTimer != null)
{
OpcBaseTimer.Dispose();
OpcBaseTimer = null;
}
return true;
}
CheckProductFeature("");
Expand Down Expand Up @@ -375,71 +367,6 @@ internal static void ValidateFeatures(ProductFeature requiredProductFeature = Pr
/// <param name="licenseKey">The license key</param>
protected static void CheckProductFeature(string licenseKey)
{
if (!string.IsNullOrEmpty(licenseKey))
{
try
{
var license = License.Load(licenseKey);

var validationFailures = license.Validate()
.ExpirationDate()
.When(lic => lic.Type == LicenseType.Trial)
.And()
.AssertThat(lic => lic.ProductFeatures.Contains("DataAccess"),
new GeneralValidationFailure { Message = "DataAccess not licensed!" })
.And()
.Signature(LicenseParameter)
.AssertValidLicense().ToList();

if (!validationFailures.Any())
{
LicensedFeatures |= ProductFeature.DataAccess;
}

validationFailures = license.Validate()
.ExpirationDate()
.When(lic => lic.Type == LicenseType.Trial)
.And()
.AssertThat(lic => lic.ProductFeatures.Contains("AlarmsConditions"),
new GeneralValidationFailure { Message = "AlarmsConditions not licensed!" })
.And()
.Signature(LicenseParameter)
.AssertValidLicense().ToList();

if (!validationFailures.Any())
{
LicensedFeatures |= ProductFeature.AlarmsConditions;
}

validationFailures = license.Validate()
.ExpirationDate()
.When(lic => lic.Type == LicenseType.Trial)
.And()
.AssertThat(lic => lic.ProductFeatures.Contains("HistoricalAccess"),
new GeneralValidationFailure { Message = "HistoricalAccess not licensed!" })
.And()
.Signature(LicenseParameter)
.AssertValidLicense().ToList();

if (!validationFailures.Any())
{
LicensedFeatures |= ProductFeature.HistoricalAccess;
}

if ((LicensedProduct & ProductLicense.Evaluation) == ProductLicense.Evaluation)
{
LicensedProduct ^= ProductLicense.Evaluation;
}
}
catch (Exception)
{
return;
}
}
if (LicensedFeatures == ProductFeature.None)
{
LicensedFeatures = ProductFeature.AllFeatures;
}
}

/// <summary>
Expand All @@ -448,72 +375,12 @@ protected static void CheckProductFeature(string licenseKey)
/// <param name="licenseKey">The license key</param>
protected static bool CheckLicenseClient(string licenseKey)
{
if (!String.IsNullOrEmpty(licenseKey))
{
try
{
var license = License.Load(licenseKey);

var validationFailures = license.Validate()
.ExpirationDate()
.When(lic => lic.Type == LicenseType.Trial)
.And()
.AssertThat(lic => lic.ProductFeatures.Contains("Client NET"),
new GeneralValidationFailure { Message = "Client DA/AE/HDA .NET not licensed!" })
.And()
.Signature(LicenseParameter)
.AssertValidLicense().ToList();

if (validationFailures.Any())
{
return false;
}

if ((LicensedProduct & ProductLicense.Expired) == ProductLicense.Expired)
{
LicensedProduct ^= ProductLicense.Expired;
}
if ((LicensedProduct & ProductLicense.Evaluation) == ProductLicense.Evaluation)
{
LicensedProduct ^= ProductLicense.Evaluation;
}

LicensedProduct |= ProductLicense.Client;

Checked = true;
if (OpcBaseTimer != null)
{
OpcBaseTimer.Dispose();
OpcBaseTimer = null;
}
return true;
}
catch (Exception)
{
return false;
}
}
return false;
return true;
}
#endregion

#region Internal Methods
internal static bool Check()
{
if (IsLicensed)
{
return true;
}
if (OpcBaseTimer == null)
{
OpcBaseTimer = new EvaluationTimer();
}
if (OpcBaseTimer.Ok())
{
return true;
}
LicensedProduct = LicensedProduct | ProductLicense.Expired;
return false;
return true;
}
#endregion
}
Expand Down

0 comments on commit 2703507

Please sign in to comment.