Example #1
0
        public void Execute(DocumentDatabase database)
        {
            docDb = database;
            string publicKey;

            using (var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public"))
            {
                if (stream == null)
                {
                    throw new InvalidOperationException("Could not find public key for the license");
                }
                publicKey = new StreamReader(stream).ReadToEnd();
            }
            var fullPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "license.xml"));

            licenseValidator = new LicenseValidator(publicKey, fullPath)
            {
                DisableFloatingLicenses = true,
            };
            licenseValidator.LicenseInvalidated += LicenseValidatorOnLicenseInvalidated;
            if (licenseValidator.TryLoadingLicenseValuesFromValidatedXml() == false)
            {
                throw new LicenseNotFoundException("Could not find valid license for RavenDB at: " + fullPath);
            }

            if (DateTime.UtcNow < licenseValidator.ExpirationDate)
            {
                return;
            }

            LicenseValidatorOnLicenseInvalidated(InvalidationType.TimeExpired);
        }