Example #1
0
        private bool WriteToStore(Guid tenantId, Uri url, XmlNode[] rac, XmlNode[] clc, byte version)
        {
            bool     flag      = clc == null;
            DateTime dateTime  = RMUtil.GetRacExpirationTime(rac[0]);
            DateTime dateTime2 = flag ? DateTime.MaxValue : RMUtil.GetClcExpirationTime(clc[0]);

            if (RmsClientManager.AppSettings.RacClcStoreExpirationInterval.TotalMinutes != 0.0)
            {
                DateTime dateTime3 = DateTime.UtcNow.Add(RmsClientManager.AppSettings.RacClcStoreExpirationInterval);
                dateTime  = ((dateTime3 > dateTime) ? dateTime : dateTime3);
                dateTime2 = ((dateTime3 > dateTime2) ? dateTime2 : dateTime3);
            }
            string text  = DrmClientUtils.ConvertXmlNodeArrayToCertificateChain(rac);
            string text2 = flag ? null : DrmClientUtils.ConvertXmlNodeArrayToCertificateChain(clc);
            string text3 = null;
            string text4 = null;

            try
            {
                text3 = DrmClientUtils.AddCertToLicenseStore(text, true);
                if (flag)
                {
                    this.perfCounters.FileWrite(1);
                }
                else
                {
                    text4 = DrmClientUtils.AddCertToLicenseStore(text2, false);
                    this.perfCounters.FileWrite(2);
                }
            }
            catch (IOException arg)
            {
                RmsLicenseStoreManager.Tracer.TraceError <Guid, Uri, IOException>(0L, "License Store Manager failed to write RAC-CLC to store for tenant ({0}) and URL ({1}). IOException - {2}.", tenantId, url, arg);
                return(false);
            }
            catch (UnauthorizedAccessException arg2)
            {
                RmsLicenseStoreManager.Tracer.TraceError <Guid, Uri, UnauthorizedAccessException>(0L, "License Store Manager failed to write RAC-CLC to store for tenant ({0}) and URL ({1}). UnauthorizedAccessException - {2}.", tenantId, url, arg2);
                return(false);
            }
            if (string.IsNullOrEmpty(text3) || (!flag && string.IsNullOrEmpty(text4)))
            {
                RmsLicenseStoreManager.Tracer.TraceError <Guid, Uri>(0L, "License Store Manager failed to write RAC-CLC to store for tenant ({0}) and URL ({1}).", tenantId, url);
                return(false);
            }
            RmsLicenseStoreInfo rmsLicenseStoreInfo = new RmsLicenseStoreInfo(tenantId, url, text3, text4, dateTime, dateTime2, version);

            this.licenseMap.Add(rmsLicenseStoreInfo);
            this.cache.TryAdd(new MultiValueKey(new object[]
            {
                rmsLicenseStoreInfo.TenantId,
                rmsLicenseStoreInfo.Url
            }), new TenantLicensePair(rmsLicenseStoreInfo.TenantId, rac, (clc != null) ? clc[0] : null, text, text2, rmsLicenseStoreInfo.RacExpire, rmsLicenseStoreInfo.ClcExpire, version, RmsClientManager.EnvironmentHandle, RmsClientManager.LibraryHandle));
            return(true);
        }
Example #2
0
 private static bool TryWriteValues(MultiValueKey key, RmsLicenseStoreInfo value, out string[] values)
 {
     if (key == null || value == null)
     {
         RmsLicenseStoreInfoMap.Tracer.TraceDebug(0L, "Rms License Store Info Map failed to write values.");
         values = null;
         return(false);
     }
     values = value.ToStringArray();
     return(true);
 }
Example #3
0
 private static bool TryReadValues(string[] values, out MultiValueKey key, out RmsLicenseStoreInfo value)
 {
     if (RmsLicenseStoreInfo.TryParse(values, out value))
     {
         key = new MultiValueKey(new object[]
         {
             value.TenantId,
             value.Url
         });
         return(true);
     }
     key = null;
     return(false);
 }
Example #4
0
        public void Add(RmsLicenseStoreInfo entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }
            MultiValueKey key = new MultiValueKey(new object[]
            {
                entry.TenantId,
                entry.Url
            });

            this.dictionary.Add(key, entry);
            this.serializer.TryWriteToDisk(this.dictionary);
        }
Example #5
0
        public bool TryGet(MultiValueKey key, out RmsLicenseStoreInfo entry)
        {
            if (key == null)
            {
                entry = null;
                return(false);
            }
            if (!this.dictionary.TryGetValue(key, out entry))
            {
                return(false);
            }
            DateTime utcNow = DateTime.UtcNow;

            if (entry.RacExpire < utcNow || entry.ClcExpire < utcNow)
            {
                RmsLicenseStoreInfoMap.Tracer.TraceDebug <MultiValueKey>(0L, "Rms License Store Info Map removed expired entry for key ({0}).", key);
                this.Remove(key);
                entry = null;
                return(false);
            }
            return(true);
        }
Example #6
0
        public static bool TryParse(string[] values, out RmsLicenseStoreInfo value)
        {
            value = null;
            if (values == null || values.Length != RmsLicenseStoreInfo.ColumnNames.Length)
            {
                RmsLicenseStoreInfo.Tracer.TraceError(0L, "Rms License Store Info failed to parse values.");
                return(false);
            }
            Guid tenantId;

            if (!GuidHelper.TryParseGuid(values[0], out tenantId))
            {
                RmsLicenseStoreInfo.Tracer.TraceError <string>(0L, "Rms License Store Info failed to parse tenantId ({0}).", values[0]);
                return(false);
            }
            Uri uri;

            if (!Uri.TryCreate(values[5], UriKind.Absolute, out uri))
            {
                RmsLicenseStoreInfo.Tracer.TraceError <string>(0L, "Rms License Store Info failed to parse URL ({0}).", values[5]);
                return(false);
            }
            string text = values[1];

            if (string.IsNullOrEmpty(text))
            {
                RmsLicenseStoreInfo.Tracer.TraceError(0L, "Rms License Store Info failed to parse null racFile.");
                return(false);
            }
            string text2 = values[2];

            if (string.IsNullOrEmpty(text2) && RmsLicenseStoreInfo.DefaultUri == uri)
            {
                RmsLicenseStoreInfo.Tracer.TraceError(0L, "Rms License Store Info failed to parse null clcFile.");
                return(false);
            }
            long num;

            if (!long.TryParse(values[3], out num) || num <DateTime.MinValue.Ticks || num> DateTime.MaxValue.Ticks)
            {
                RmsLicenseStoreInfo.Tracer.TraceError <string>(0L, "Rms License Store Info failed to parse rac expire time ({0}).", values[3]);
                return(false);
            }
            DateTime dateTime = new DateTime(num);

            if (!long.TryParse(values[4], out num) || num <DateTime.MinValue.Ticks || num> DateTime.MaxValue.Ticks)
            {
                RmsLicenseStoreInfo.Tracer.TraceError <string>(0L, "Rms License Store Info failed to parse clc expire time ({0}).", values[4]);
                return(false);
            }
            DateTime dateTime2 = new DateTime(num);
            byte     version;

            if (!byte.TryParse(values[6], out version))
            {
                RmsLicenseStoreInfo.Tracer.TraceError <string>(0L, "Rms License Store Info failed to parse rac/clc version ({0}).", values[6]);
                return(false);
            }
            DateTime utcNow = DateTime.UtcNow;

            if (dateTime > utcNow && dateTime2 > utcNow)
            {
                value = new RmsLicenseStoreInfo(tenantId, uri, text, text2, dateTime, dateTime2, version);
                return(true);
            }
            RmsLicenseStoreInfo.Tracer.TraceDebug(0L, "Rms License Store Info failed to parse RmsLicenseStoreInfo as it is expired.");
            return(false);
        }