Пример #1
0
        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);
            }
            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 bool Equals(PublicCryptoKey other)
 {
     return string.Equals(this.Contents, other.Contents);
 }
Пример #3
0
 private bool Equals(PublicCryptoKey other)
 {
     return(string.Equals(this.Contents, other.Contents));
 }