From 052a66f9925380d8f4ef0922f983578756321e0b Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Fri, 8 Mar 2024 20:13:11 +0100 Subject: [PATCH] Add logic to get license key information --- .github/workflows/dotnet-release.yml | 4 ++-- src/Nager.Date/Helpers/LicenseHelper.cs | 32 +++++++++++++++++++++++++ src/Nager.Date/HolidaySystem.cs | 11 +++------ 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 src/Nager.Date/Helpers/LicenseHelper.cs diff --git a/.github/workflows/dotnet-release.yml b/.github/workflows/dotnet-release.yml index 15b2d04b..fb7306f9 100644 --- a/.github/workflows/dotnet-release.yml +++ b/.github/workflows/dotnet-release.yml @@ -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 diff --git a/src/Nager.Date/Helpers/LicenseHelper.cs b/src/Nager.Date/Helpers/LicenseHelper.cs new file mode 100644 index 00000000..ee682865 --- /dev/null +++ b/src/Nager.Date/Helpers/LicenseHelper.cs @@ -0,0 +1,32 @@ +using Nager.LicenseSystem; + +namespace Nager.Date.Helpers +{ + /// + /// License Helper + /// + public static class LicenseHelper + { + /// + /// Get License Key Informations + /// + /// + /// + 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; + } + } +} diff --git a/src/Nager.Date/HolidaySystem.cs b/src/Nager.Date/HolidaySystem.cs index 0aa92aa1..57753bcc 100644 --- a/src/Nager.Date/HolidaySystem.cs +++ b/src/Nager.Date/HolidaySystem.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; namespace Nager.Date { @@ -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");