private static void CacheOnRemoved(object sender, OnRemovedEventArgs <MultiValueKey, TenantLicensePair> e) { TenantLicensePair value = e.Value; if (value != null) { value.Release(); } }
private bool ReadFromCache(MultiValueKey key, out TenantLicensePair tenantLicenses) { if (this.cache.TryGetValue(key, out tenantLicenses) && tenantLicenses != null) { DateTime utcNow = DateTime.UtcNow; if (!(tenantLicenses.RacExpire < utcNow) && !(tenantLicenses.ClcExpire < utcNow)) { return(true); } this.cache.Remove(key); tenantLicenses = null; } RmsLicenseStoreManager.Tracer.TraceDebug <MultiValueKey>(0L, "License Store Manager failed to get certs from cache for key {0}.", key); return(false); }
public static void LogAcquireRacClcResult(RmsClientManagerContext context, TenantLicensePair tenantLicensePair) { if (!RmsClientManagerLog.rmsLogEnabled) { return; } if (context == null) { throw new ArgumentNullException("context"); } RmsClientManagerLog.LogEvent(RmsClientManagerLog.RmsClientManagerFeature.RacClc, RmsClientManagerLog.RmsClientManagerEvent.Success, context.OrgId, context.TransactionId, string.Format(CultureInfo.InvariantCulture, "CLC: {0}; RAC: {1}; Version: {2}", new object[] { (tenantLicensePair.BoundLicenseClc == null) ? RmsClientManagerLog.LicenseEmpty : RmsClientManagerLog.LicenseExists, (tenantLicensePair.Rac == null) ? RmsClientManagerLog.LicenseEmpty : RmsClientManagerLog.LicenseExists, tenantLicensePair.Version }).ToString(NumberFormatInfo.InvariantInfo), context.ContextStringForm); }
public bool ReadFromStore(Guid tenantId, Uri url, byte version, out TenantLicensePair tenantLicenses) { if (null == url) { throw new ArgumentNullException("url"); } MultiValueKey multiValueKey = new MultiValueKey(new object[] { tenantId, url }); RmsLicenseStoreInfo rmsLicenseStoreInfo; if (this.ReadFromCache(multiValueKey, out tenantLicenses)) { this.licenseMap.TryGet(multiValueKey, out rmsLicenseStoreInfo); return(true); } if (!this.licenseMap.TryGet(multiValueKey, out rmsLicenseStoreInfo)) { RmsLicenseStoreManager.Tracer.TraceDebug <MultiValueKey>(0L, "License Store Manager doesn't have entry in map for key ({0}) or certs are expired.", multiValueKey); return(false); } string text = null; string text2 = null; try { text = DrmClientUtils.GetCertFromLicenseStore(rmsLicenseStoreInfo.RacFileName); if (!string.IsNullOrEmpty(rmsLicenseStoreInfo.ClcFileName)) { text2 = DrmClientUtils.GetCertFromLicenseStore(rmsLicenseStoreInfo.ClcFileName); this.perfCounters.FileRead(2); } else { this.perfCounters.FileRead(1); } } catch (IOException arg) { RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey, IOException>(0L, "License Store Manager failed to read certs from store for key ({0}). IOException - {1}.", multiValueKey, arg); return(false); } catch (UnauthorizedAccessException arg2) { RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey, UnauthorizedAccessException>(0L, "License Store Manager failed to read certs from store for key ({0}). UnauthorizedAccessException - {1}.", multiValueKey, arg2); return(false); } catch (SecurityException arg3) { RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey, SecurityException>(0L, "License Store Manager failed to read certs from store for key ({0}). SecurityException - {1}.", multiValueKey, arg3); return(false); } XmlNode[] rac; XmlNode[] array; if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2) && RMUtil.TryConvertAppendedCertsToXmlNodeArray(text, out rac) && RMUtil.TryConvertAppendedCertsToXmlNodeArray(text2, out array)) { tenantLicenses = new TenantLicensePair(tenantId, rac, array[0], null, DrmClientUtils.ConvertXmlNodeArrayToCertificateChain(array), rmsLicenseStoreInfo.RacExpire, rmsLicenseStoreInfo.ClcExpire, rmsLicenseStoreInfo.Version, RmsClientManager.EnvironmentHandle, RmsClientManager.LibraryHandle); this.cache.TryAdd(multiValueKey, tenantLicenses); return(true); } if (!string.IsNullOrEmpty(text) && RMUtil.TryConvertAppendedCertsToXmlNodeArray(text, out rac) && version == rmsLicenseStoreInfo.Version) { tenantLicenses = new TenantLicensePair(tenantId, rac, null, null, null, rmsLicenseStoreInfo.RacExpire, rmsLicenseStoreInfo.ClcExpire, rmsLicenseStoreInfo.Version, RmsClientManager.EnvironmentHandle, RmsClientManager.LibraryHandle); this.cache.TryAdd(multiValueKey, tenantLicenses); return(true); } RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey>(0L, "License Store Manager failed to read certs from store for key ({0}) - certs are empty or invalid.", multiValueKey); this.licenseMap.Remove(multiValueKey); return(false); }
public bool ReadFromStore(Guid tenantId, Uri serviceLocation, Uri publishLocation, byte version, out TenantLicensePair tenantLicenses) { if (!this.ReadFromStore(tenantId, RmsLicenseStoreInfo.DefaultUri, version, out tenantLicenses)) { return(false); } RmsLicenseStoreManager.Tracer.TraceDebug <Uri, Uri, int>(0L, "Verifying ServiceLocation {0}, PublishLocation {1} and Version {2}", serviceLocation, publishLocation, (int)version); if (tenantLicenses.HasConfigurationChanged(serviceLocation, publishLocation, version)) { MultiValueKey key = new MultiValueKey(new object[] { tenantId, RmsLicenseStoreInfo.DefaultUri }); RmsLicenseStoreManager.Tracer.TraceDebug <Guid>(0L, "Failed to match the RAC/CLC distribution point to the tenant's current configuration. Deleting the current entry. TenantId: {0}", tenantId); this.licenseMap.Remove(key); this.cache.Remove(key); return(false); } RmsLicenseStoreManager.Tracer.TraceDebug(0L, "Distribution points and version not changed"); return(true); }