/// <summary> /// Runs on a thread pool thread periodically. /// </summary> /// <param name="o"></param> private void Verify(object o) { lock (singleThreadedVerify) { try { //No verification of license store needed; they can be replaced by user ILicenseStore s = c.Plugins.GetOrInstall <ILicenseStore>(new LicenseStore(this.LicenseCacheFilePattern)); //Get all encrypted licenses and // Decrypt them, grouping by normalized domain name var licenses = RemovedExpired(DecryptAll(s.GetLicenses())); //Fix all possible pendingFeatures using existing license data. UpdateFeatureStatus(licenses); if (pendingFeatures.Count > 0) { //Send off https request based on appId and pendingFeatures pairs. //Get List<byte> in return. var newLicenses = DecryptAll(RequestLicenses(pendingFeatures)); if (newLicenses.Count > 0) { //Update cached feature statuses UpdateFeatureStatus(newLicenses); s.SetLicenses(ExportLicenses(Merge(licenses, newLicenses))); } } } finally { lastEndedVerification = DateTime.UtcNow; } } }
public WhenPendingFeaturesStillExistAfterUpdatingFromLocalCacheTests() { featureOne = Guid.NewGuid(); featureTwo = Guid.NewGuid(); featureThree = Guid.NewGuid(); var httpClient = Substitute.For <IHttpClient>(); string keyPair = Helpers.GenerateKeyPairXml(); var domainLicense = Helpers.GenerateDomainLicense(new List <Guid> { featureOne, featureThree }); httpClient.Send(Arg.Any <HttpRequest>()).Returns(new HttpResponse { Content = Helpers.GenerateValidXmlResponseFromKeyHub(keyPair, new List <DomainLicense> { domainLicense }) }); licenseStore = Substitute.For <ILicenseStore>(); licenseStore.GetLicenses().Returns(new List <byte[]>()); var featureStates = new Dictionary <string, Dictionary <Guid, FeatureState> > { { "domain.com", new Dictionary <Guid, FeatureState> { { featureOne, FeatureState.Pending }, { featureTwo, FeatureState.Pending }, { featureThree, FeatureState.Pending } } } }; var pendingFeatures = new Dictionary <string, List <Guid> > { { "domain.com", new List <Guid> { featureOne, featureTwo, featureThree } } }; verifyAction = new VerifyAction(httpClient, keyPair, Guid.NewGuid(), licenseStore, featureStates, pendingFeatures); verifyAction.Finished += verifyAction_Finished; }
protected override void PerformBackgroundAction() { var licenses = RemovedExpired(DecryptAll(licenseStore.GetLicenses())); // Fix all possible pendingFeatures using existing license data. UpdateFeatureStatus(licenses, true); // If we still have pending features, retrieve license info from KeyHub if (pendingFeatures.Count > 0) { var newLicenses = DecryptAll(RequestLicenses()); if (newLicenses.Count > 0) { UpdateFeatureStatus(newLicenses, false); licenseStore.SetLicenses(ExportLicenses(Merge(licenses, newLicenses))); } } }
public WhenLocalCacheContainsLicenseInformationTests() { featureOne = Guid.NewGuid(); featureTwo = Guid.NewGuid(); featureThree = Guid.NewGuid(); featureFour = Guid.NewGuid(); featureFive = Guid.NewGuid(); featureSix = Guid.NewGuid(); featureSeven = Guid.NewGuid(); var httpClient = Substitute.For <IHttpClient>(); string keyPair = Helpers.GenerateKeyPairXml(); // featureOne and featureThree belong to an expired license var expiredDomainLicense = new DomainLicense( "expired.com", "John Doe", DateTime.UtcNow.AddYears(-1), DateTime.UtcNow.AddHours(24).AddYears(-1), new List <Guid> { featureOne, featureThree } ); var issued = DateTime.UtcNow; var expires = DateTime.UtcNow.AddHours(24); // featureTwo and featureFive have already been verified var cachedDomainLicense = new DomainLicense( "domain.com", "John Doe", issued, expires, new List <Guid> { featureTwo, featureFive } ); // featureSix and featureSeven are Pending, but only featureSix will be enabled var keyHubDomainLicense = new DomainLicense( "domain.com", "John Doe", issued, expires, new List <Guid> { featureTwo, featureFour, // Rejected in the past is now enabled featureFive, featureSix // Pending new feature } ); httpClient.Send(Arg.Any <HttpRequest>()).Returns(new HttpResponse { Content = Helpers.GenerateValidXmlResponseFromKeyHub(keyPair, new List <DomainLicense> { keyHubDomainLicense }) }); licenseStore = Substitute.For <ILicenseStore>(); licenseStore.GetLicenses().Returns(new List <byte[]> { expiredDomainLicense.SerializeAndEncrypt(keyPair), cachedDomainLicense.SerializeAndEncrypt(keyPair) }); var featureStates = new Dictionary <string, Dictionary <Guid, FeatureState> > { { "expired.com", new Dictionary <Guid, FeatureState> { { featureOne, FeatureState.Enabled }, { featureThree, FeatureState.Enabled } } }, { "domain.com", new Dictionary <Guid, FeatureState> { { featureTwo, FeatureState.Enabled }, { featureFour, FeatureState.Rejected }, { featureFive, FeatureState.Enabled }, { featureSix, FeatureState.Pending }, { featureSeven, FeatureState.Pending } } } }; var pendingFeatures = new Dictionary <string, List <Guid> > { { "domain.com", new List <Guid> { featureSix, featureSeven } } }; verifyAction = new VerifyAction(httpClient, keyPair, Guid.NewGuid(), licenseStore, featureStates, pendingFeatures); verifyAction.Finished += verifyAction_Finished; }