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> { new LicenseHasNotExpiredRule(), new ValidNumberOfCoresLicenseRule() }; // new LicenseValidator().Validate(clientLicense, publicKey, licenseValidationRules); new LicenseValidator().Validate(clientLicense, publicKey, licenseValidationRules, "This is my password"); } catch (InvalidLicenseException exception) { violations.Add(exception.Message); } catch (AggregateException ex) { var innerExceptions = ex.InnerExceptions; foreach (var exception in innerExceptions) { if (exception is LicenseViolationException) { violations.Add(exception.Message); } } if (!violations.Any()) { throw; } } catch (Exception) { violations.Add(Messages.UnknownLicenseError); } if (violations.Any()) { Console.WriteLine(Messages.LicenseViolationsEncountered); foreach (var violation in violations) { Console.WriteLine(" - " + violation); } Console.WriteLine(Messages.PressAnyKey); Console.ReadKey(); Environment.Exit(-1); } }
private static void GetKey(string licensePath, string elementKey = null) { var clientLicense = ClientLicense.Create(File.ReadAllText(licensePath)); var mylcP = new LicenseCriteriaParser(); var licenseCriteria = mylcP.Parse(clientLicense, elementKey); if (licenseCriteria.MetaData.ContainsKey("LicensedCores")) { Console.WriteLine(licenseCriteria.MetaData["LicensedCores"]); } else { Console.WriteLine("no key found"); } }