Skip to content

Commit

Permalink
Add logic to get license key information
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Mar 8, 2024
1 parent fa023d3 commit 052a66f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
- name: Change LicenseKey
working-directory: ./src
run: |
sed -i 's/DCDCB65FD3009576BC11E23C883220F6292709DEB93174D0913D2E89DB3D5D88/${{secrets.PUBLIC_KEY1}}/g' Nager.Date/HolidaySystem.cs
sed -i 's/17F32AEC71CCB3D20166DCC7F49B32C1153464105344608692E005B16284A41D/${{secrets.PUBLIC_KEY2}}/g' Nager.Date/HolidaySystem.cs
sed -i 's/DCDCB65FD3009576BC11E23C883220F6292709DEB93174D0913D2E89DB3D5D88/${{secrets.PUBLIC_KEY1}}/g' Nager.Date/Helpers/LicenseHelper.cs
sed -i 's/17F32AEC71CCB3D20166DCC7F49B32C1153464105344608692E005B16284A41D/${{secrets.PUBLIC_KEY2}}/g' Nager.Date/Helpers/LicenseHelper.cs
- name: Second Build after change LicenseKey
working-directory: ./src
run: dotnet build --configuration Release --no-restore
Expand Down
32 changes: 32 additions & 0 deletions src/Nager.Date/Helpers/LicenseHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Nager.LicenseSystem;

namespace Nager.Date.Helpers
{
/// <summary>
/// License Helper
/// </summary>
public static class LicenseHelper
{
/// <summary>
/// Get License Key Informations
/// </summary>
/// <param name="licenseKey"></param>
/// <returns></returns>
public static LicenseInfo CheckLicenseKey(string licenseKey)
{
var licenseKeyConfiguration = new LicenseKeyConfiguration
{
Part1 = "DCDCB65FD3009576BC11E23C883220F6292709DEB93174D0913D2E89DB3D5D88",
Part2 = "17F32AEC71CCB3D20166DCC7F49B32C1153464105344608692E005B16284A41D"
};

var licenseKeyValidator = new LicenseKeyValidator(licenseKeyConfiguration);
if (licenseKeyValidator.Validate(licenseKey, out var licenseInfo))
{
return licenseInfo;
}

return null;
}
}
}
11 changes: 3 additions & 8 deletions src/Nager.Date/HolidaySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Nager.Date
{
Expand Down Expand Up @@ -154,14 +155,8 @@ private static void CheckLicense(string licenseKey)
throw new LicenseKeyException("No LicenseKey");
}

var licenseKeyConfiguration = new LicenseKeyConfiguration
{
Part1 = "DCDCB65FD3009576BC11E23C883220F6292709DEB93174D0913D2E89DB3D5D88",
Part2 = "17F32AEC71CCB3D20166DCC7F49B32C1153464105344608692E005B16284A41D"
};

var licenseKeyValidator = new LicenseSystem.LicenseKeyValidator(licenseKeyConfiguration);
if (!licenseKeyValidator.Validate(licenseKey, out var licenseInfo))
var licenseInfo = LicenseHelper.CheckLicenseKey(licenseKey);
if (licenseInfo is null)
{
_licenseValid = false;
throw new LicenseKeyException("Invalid LicenseKey");
Expand Down

0 comments on commit 052a66f

Please sign in to comment.