Ejemplo n.º 1
0
        /// <summary>Load method override which initializes the <see cref="LicenseIDIdentifier"/> after loading new license content.</summary>
        /// <param name="data">The license content being loaded.</param>
        /// <returns>Returns true if successful.  If false is returned, check the <see cref="License.LastError"/> property for details.</returns>
        public override bool Load(string data)
        {
            bool result = base.Load(data);

            //Initialize the identifier needed to validate the volume license.
            LicenseIDIdentifierAlgorithm algorithm = new LicenseIDIdentifierAlgorithm();

            CurrentIdentifiers.Add(algorithm.GetIdentifier(LicenseID)[0]);

            return(result);
        }
        /// <summary>Validates the license.</summary>
        /// <returns>Returns true if validation is successful and the license is valid.  If false is returned, check the <see cref="License.LastError"/> property for details.</returns>
        internal bool Validate()
        {
            //Make sure the option type is supported.
            if (ProductOption.OptionType == LicenseProductOption.ProductOptionType.DownloadableLicenseWithTriggerCodeValidation)
            {
                LastError = new LicenseError(LicenseError.ERROR_INVALID_LICENSE_TYPE);
                return(false);
            }

            //TODO: If you wish to have your volume licenses automatically refresh with SOLO Server, you may
            //      enable this by removing the second expression in the 'if' statement immediately below.
            if (IsRefreshLicenseAttemptDue &&
                ProductOption.OptionType != LicenseProductOption.ProductOptionType.VolumeLicense)
            {
                //If a refresh attempt should be made, try to perform a license refresh with SOLO Server.
                if (!RefreshLicense() &&
                    (LastError.ErrorNumber != LicenseError.ERROR_WEBSERVICE_CALL_FAILED || IsRefreshLicenseRequired))
                {
                    //The refresh failed and was required, or SOLO Server returned an error.
                    return(false);
                }
            }

            //Create a list of validations to perform.
            List <SystemValidation> validations = new List <SystemValidation>();

            //Add a validation to make sure there is no active system clock tampering taking place.
            validations.Add(new SystemClockValidation());

            //Validate the Product ID authorized in the license to make sure the license file was issued for this application.
            validations.Add(new LicenseProductValidation(this, ThisProductID));

            //Validate the current identifiers by default.
            List <SystemIdentifier> validationIdentifiers = CurrentIdentifiers;

            if (ProductOption.OptionType == LicenseProductOption.ProductOptionType.VolumeLicense)
            {
                //This is a volume license, so only validate a single identifier for the License ID.
                LicenseIDIdentifierAlgorithm alg = new LicenseIDIdentifierAlgorithm();
                validationIdentifiers = alg.GetIdentifier(LicenseID);
            }

            //Add a validation to make sure this system is authorized to use the activated license.  (This implements copy-protection.)
            validations.Add(new SystemIdentifierValidation(
                                AuthorizedIdentifiers,
                                validationIdentifiers,
                                SystemIdentifierValidation.REQUIRE_EXACT_MATCH));

            if (TypeOfLicense == LicenseTypes.TimeLimited)
            {
                //If the license is time-limited, make sure it is within its effective date/time period.
                validations.Add(new LicenseEffectiveDateValidation(this));
            }

            //Run all of the validations (in the order they were added), and make sure all of them succeed.
            foreach (SystemValidation validation in validations)
            {
                if (!validation.Validate())
                {
                    LastError = validation.LastError;
                    return(false);
                }
            }

            //If we got this far, all validations were successful, so return true to indicate success and a valid license.
            return(true);
        }