Exemple #1
0
        /// <summary>
        /// It verifies whether your app is genuinely activated or not. The verification is
        /// done locally by verifying the cryptographic digital signature fetched at the time of activation.
        ///
        /// After verifying locally, it schedules a server check in a separate thread. After the
        /// first server sync it periodically does further syncs at a frequency set for the license.
        ///
        /// In case server sync fails due to network error, and it continues to fail for fixed
        /// number of days (grace period), the function returns LA_GRACE_PERIOD_OVER instead of LA_OK.
        ///
        /// This function must be called on every start of your program to verify the activation
        /// of your app.
        /// </summary>
        /// <returns>LA_OK, LA_EXPIRED, LA_SUSPENDED, LA_GRACE_PERIOD_OVER, LA_FAIL</returns>
        public int IsLicenseGenuine()
        {
            int status = IsLicenseValid();

            if (LexValidator.ValidateSuccessCode(status) && _activationPayload.ServerSyncInterval != 0)
            {
                StartTimer(LexConstants.SERVER_SYNC_DELAY, _activationPayload.ServerSyncInterval);
            }
            switch (status)
            {
            case LexStatusCodes.LA_OK:
                return(LexStatusCodes.LA_OK);

            case LexStatusCodes.LA_EXPIRED:
                return(LexStatusCodes.LA_EXPIRED);

            case LexStatusCodes.LA_SUSPENDED:
                return(LexStatusCodes.LA_SUSPENDED);

            case LexStatusCodes.LA_GRACE_PERIOD_OVER:
                return(LexStatusCodes.LA_GRACE_PERIOD_OVER);

            case LexStatusCodes.LA_FAIL:
                return(LexStatusCodes.LA_FAIL);

            default:
                throw new LexActivatorException(status);
            }
        }
Exemple #2
0
        /// <summary>
        /// Activates the license by contacting the Cryptlex servers. It
        /// validates the key and returns with encrypted and digitally signed token
        /// which it stores and uses to activate your application.
        ///
        /// This function should be executed at the time of registration, ideally on
        /// a button click.
        /// </summary>
        /// <returns>LA_OK, LA_EXPIRED, LA_SUSPENDED, LA_FAIL</returns>
        public int ActivateLicense()
        {
            if (String.IsNullOrEmpty(this._productId))
            {
                throw new LexActivatorException(LexStatusCodes.LA_E_PRODUCT_ID);
            }
            if (String.IsNullOrEmpty(this._rsaPublicKey))
            {
                throw new LexActivatorException(LexStatusCodes.LA_E_RSA_PUBLIC_KEY);
            }

            _licenseKey = LexDataStore.GetValue(this._productId, LexConstants.KEY_LICENSE_KEY);
            if (String.IsNullOrEmpty(_licenseKey))
            {
                throw new LexActivatorException(LexStatusCodes.LA_E_LICENSE_KEY);
            }

            _activationPayload = new ActivationPayload();
            var meterAttributes = new List <ActivationMeterAttribute>();
            int status          = LexActivationService.ActivateFromServer(_productId, _licenseKey, _rsaPublicKey, _activationPayload, meterAttributes);

            if (LexValidator.ValidateSuccessCode(status))
            {
                StartTimer(_activationPayload.ServerSyncInterval, _activationPayload.ServerSyncInterval);
                return(status);
            }
            throw new LexActivatorException(status);
        }
Exemple #3
0
        /// <summary>
        /// Gets the license type (node-locked or hosted-floating).
        /// </summary>
        /// <returns>Returns the license type.</returns>
        public string GetLicenseType()
        {
            int status = IsLicenseValid();

            if (LexValidator.ValidateSuccessCode(status))
            {
                return(_activationPayload.Type);
            }
            throw new LexActivatorException(status);
        }
Exemple #4
0
        /// <summary>
        /// Gets the license expiry date timestamp.
        /// </summary>
        /// <returns>Returns the timestamp.</returns>
        public long GetLicenseExpiryDate()
        {
            int status = IsLicenseValid();

            if (LexValidator.ValidateSuccessCode(status))
            {
                return(_activationPayload.ExpiresAt);
            }
            throw new LexActivatorException(status);
        }
Exemple #5
0
        /// <summary>
        /// Resets the meter attribute uses consumed by the activation.
        /// </summary>
        /// <param name="name">name of the meter attribute</param>
        public void ResetActivationMeterAttributeUses(string name)
        {
            long currentUses = GetActivationMeterAttributeUses(name);
            List <ActivationMeterAttribute> meterAttributes = _activationPayload.ActivationMeterAttributes;
            int status = UpdateMeterAttributeUses(name, meterAttributes, 0);

            if (!LexValidator.ValidateSuccessCode(status))
            {
                throw new LexActivatorException(status);
            }
        }
Exemple #6
0
        /// <summary>
        /// Deactivates the license activation and frees up the corresponding activation
        /// slot by contacting the Cryptlex servers.
        ///
        /// This function should be executed at the time of de-registration, ideally on
        /// a button click.
        /// </summary>
        /// <returns>LA_OK</returns>
        public int DeactivateLicense()
        {
            int status = IsLicenseValid();

            if (LexValidator.ValidateSuccessCode(status))
            {
                status = LexActivationService.DeactivateFromServer(_productId, _activationPayload);
                if (status == LexStatusCodes.LA_OK)
                {
                    return(status);
                }
            }
            throw new LexActivatorException(status);
        }
Exemple #7
0
        /// <summary>
        /// Gets the metadata associated with the license user.
        /// </summary>
        /// <param name="key">key to retrieve the value</param>
        /// <returns>Returns the value of metadata for the key.</returns>
        public string GetLicenseUserMetadata(string key)
        {
            int status = IsLicenseValid();

            if (LexValidator.ValidateSuccessCode(status))
            {
                string value = LexActivationService.GetMetadata(key, _activationPayload.UserMetadata);
                if (value == null)
                {
                    throw new LexActivatorException(LexStatusCodes.LA_E_METADATA_KEY_NOT_FOUND);
                }
                return(value);
            }
            throw new LexActivatorException(status);
        }
Exemple #8
0
        /// <summary>
        /// Gets the license meter attribute allowed uses and total uses.
        /// </summary>
        /// <param name="name">name of the meter attribute</param>
        /// <returns>Returns the values of meter attribute allowed and total uses.</returns>
        public LicenseMeterAttribute GetLicenseMeterAttribute(string name)
        {
            int status = IsLicenseValid();

            if (LexValidator.ValidateSuccessCode(status))
            {
                var licenseMeterAttribute = LexActivationService.GetLicenseMeterAttribute(name, _activationPayload.LicenseMeterAttributes);
                if (licenseMeterAttribute == null)
                {
                    throw new LexActivatorException(LexStatusCodes.LA_E_METER_ATTRIBUTE_NOT_FOUND);
                }
                return(licenseMeterAttribute);
            }
            throw new LexActivatorException(status);
        }
Exemple #9
0
        /// <summary>
        /// Decrements the meter attribute uses of the activation.
        /// </summary>
        /// <param name="name">name of the meter attribute</param>
        /// <param name="decrement">the decrement value</param>
        public void DecrementActivationMeterAttributeUses(string name, uint decrement)
        {
            long currentUses = GetActivationMeterAttributeUses(name);

            if (decrement > currentUses)
            {
                decrement = (uint)currentUses;
            }
            long uses = currentUses - decrement;
            List <ActivationMeterAttribute> meterAttributes = _activationPayload.ActivationMeterAttributes;
            int status = UpdateMeterAttributeUses(name, meterAttributes, uses);

            if (!LexValidator.ValidateSuccessCode(status))
            {
                throw new LexActivatorException(status);
            }
        }
Exemple #10
0
        /// <summary>
        /// Gets the meter attribute uses consumed by the activation.
        /// </summary>
        /// <param name="name"></param>
        /// <returns>Returns the value of meter attribute uses by the activation.</returns>
        public long GetActivationMeterAttributeUses(string name)
        {
            int status = IsLicenseValid();

            if (LexValidator.ValidateSuccessCode(status))
            {
                bool exists = false;
                exists = LexActivationService.MeterAttributeExists(name, _activationPayload.LicenseMeterAttributes);
                if (!exists)
                {
                    throw new LexActivatorException(LexStatusCodes.LA_E_METER_ATTRIBUTE_NOT_FOUND);
                }
                var activationMeterAttribute = LexActivationService.GetActivationMeterAttribute(name, _activationPayload.ActivationMeterAttributes);
                if (activationMeterAttribute == null)
                {
                    return(0);
                }
                return(activationMeterAttribute.Uses);
            }
            throw new LexActivatorException(status);
        }