This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ILicenseValidator | |
{ | |
void Validate(IClientLicense clientLicense, ICryptoKey publicKey, IEnumerable<ILicenseValidationRule> validationRules); | |
LicenseCriteria LicenseCriteria { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Main(string[] args) | |
{ | |
var dataDirectory = @"..\..\..\..\LicenseData".ResolveBaseDirectory(); | |
var publicKeyPath = @"..\..\..\..\LicenseData\PublicKey.xml".ResolveBaseDirectory(); | |
var licensePath = @"..\..\..\..\LicenseData\License.xml".ResolveBaseDirectory(); | |
if (!Directory.Exists(dataDirectory)) | |
{ | |
Directory.CreateDirectory(dataDirectory); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Main(string[] args) | |
{ | |
// In a real implementation the public key would be embedded in the assembly | |
// possibly via an embedded resource | |
var publicKeyPath = @"..\..\..\..\LicenseData\PublicKey.xml".ResolveBaseDirectory(); | |
// You could also either load the license from the file system or deliver it | |
// on demand from a web endpoint | |
var licensePath = @"..\..\..\..\LicenseData\License.xml".ResolveBaseDirectory(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ValidateLicense(string publicKeyPath, string licensePath) | |
{ | |
var publicKey = new PublicCryptoKey { Contents = File.ReadAllText(publicKeyPath) }; | |
var clientLicense = ClientLicense.Create(File.ReadAllText(licensePath)); | |
var violations = new List<string>(); | |
try | |
{ | |
var licenseValidationRules = new List<ILicenseValidationRule> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValidNumberOfCoresLicenseRule : ILicenseValidationRule | |
{ | |
public void Validate(LicenseCriteria licenseCriteria) | |
{ | |
int licensedCores = 0; | |
if (licenseCriteria.MetaData.ContainsKey("LicensedCores")) | |
{ | |
licensedCores = Convert.ToInt32(licenseCriteria.MetaData["LicensedCores"]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LicensedCoresExceededException : LicenseViolationException | |
{ | |
public LicensedCoresExceededException(int actualCoreCount) | |
{ | |
this.ActualCoreCount = actualCoreCount; | |
} | |
public LicensedCoresExceededException(string message, int actualCoreCount) : base(message) | |
{ | |
this.ActualCoreCount = actualCoreCount; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Validate(IClientLicense clientLicense, ICryptoKey publicKey, IEnumerable<ILicenseValidationRule> validationRules) | |
{ | |
if (!LicenseSignatureValidator.ValidateSignature(clientLicense, publicKey)) | |
{ | |
throw new InvalidLicenseException(clientLicense); | |
} | |
this.LicenseCriteria = this.licenseCriteriaParser.Parse(clientLicense); | |
validationRules.ForEachFailEnd(x => x.Validate(this.LicenseCriteria)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var licenseCriteria = new LicenseCriteria | |
{ | |
ExpirationDate = DateTimeOffset.UtcNow.LastDayOfMonth().EndOfDay(), | |
IssueDate = DateTimeOffset.UtcNow, | |
Id = Guid.NewGuid(), | |
MetaData = new Dictionary<string, string> { { "LicensedCores", "2" } }, | |
Type = "Subscription" | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Using Directives | |
using System; | |
using Endjin.Core.Retry.Policies; | |
using Microsoft.WindowsAzure.Storage; | |
#endregion |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Using Directives | |
using System; | |
using Endjin.Core.Retry.Policies; | |
#endregion | |
public class DoNotRetryOnLeaseAcquisitionUnsuccessfulPolicy : IRetryPolicy | |
{ |