Ejemplo n.º 1
0
        /// <summary>
        /// Checks the database to see if the key has already been used, and if it's a multi-use capable key
        /// the number of valid activations will be check to ensure it doesn't exceed the maximum activation
        /// count. If the key is hardware based it will check the existing key's fingerprint against the one
        /// saved to see if it matches.
        /// </summary>
        /// <param name="licenseKey"></param>
        /// <param name="licenseSetId"></param>
        /// <param name="hardwareFingerprint"></param>
        /// <returns></returns>
        public bool IsKeyAvialable(string licenseKey, int licenseSetId, string hardwareFingerprint)
        {
            ServiceLicenseSet ls = _serviceProductsRepository.GetServiceLicenseSetById(licenseSetId);
            ServiceLicenseKey lk = _serviceProductsRepository.GetServiceLicenseKeyByKeyLicenseSet(licenseKey, licenseSetId);
            LicenseActivation la = _clientRepository.GetLicenseActivationByKeyAndSetId(licenseKey, licenseSetId);

            if (la == null)
            {
                return(true);
            }

            Debug.WriteLine(ls.LicenseType.ToString());

            // Enterprise and Unlimited keys have no activation restrictions
            if (ls.LicenseType.IsSet(LicenseKeyTypeFlag.Unlimited) || ls.LicenseType.IsSet(LicenseKeyTypeFlag.Enterprise))
            {
                return(true);
            }

            // If the key is multi-user, ensure that they are under the MaxUsers count
            if (ls.LicenseType.IsSet(LicenseKeyTypeFlag.MultiUser))
            {
                if (ls.MaxUsers.HasValue && ((lk.ActivationCount + 1) <= ls.MaxUsers.Value))
                {
                    return(true);
                }
            }

            // Hardware keys can activate as many times as they want, provided the hardware fingerprints match.
            if (ls.LicenseType.IsSet(LicenseKeyTypeFlag.HardwareLock))
            {
                if (la != null)
                {
                    if (la.HardwareHash == hardwareFingerprint)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }