Example #1
0
        /// <summary>Creates an evaluation for the specified duration.</summary>
        /// <param name="evaluationDuration">The duration (in days) of the evaluation.</param>
        /// <param name="shouldCheckAliases">Whether or not aliases should be checked before creating the new evaluation license.</param>
        /// <param name="extendExisting">Whether or not any existing trial period should be extended.</param>
        /// <returns>Returns true if successful.  If false is returned, check the <see cref="License.LastError"/> property for details.</returns>
        internal bool CreateEvaluation(int evaluationDuration, bool shouldCheckAliases, bool extendExisting)
        {
            if (shouldCheckAliases)
            {
                //Start by loading and checking all the aliases
                int numAliases, numValidAliases;
                this.CheckAliases(out numAliases, out numValidAliases);

                //If we found any aliases, write the most recent one as the license file
                LicenseAlias mostRecent = LicenseAlias.GetMostCurrentAlias(this.Aliases);
                if (mostRecent.LastUpdated != DateTime.MinValue)
                {
                    this.WriteAliasToLicenseFile(mostRecent, LicenseConfiguration.LicenseFilePath);
                    this.Load(mostRecent.Contents);
                    int aliasesToWrite, aliasesWritten;
                    this.WriteAliases(out aliasesToWrite, out aliasesWritten);
                    return(true);
                }
            }

            //Set the Product ID so this evaluation license cannot be used to update or extend another application's evaluation period.
            Product.ProductID = ThisProductID;

            //Evaluations that are not established through activation should have no License ID, Installation ID, or Installation Name.
            LicenseID        = 0;
            InstallationID   = "";
            InstallationName = "";

            //In the SimpleTextEditor samples, this makes it so all features can be used during the evaluation period.
            UserDefinedNumber1 = Int32.MaxValue;

            if (evaluationDuration > 0)
            {
                //We are creating an evaluation that expires in the future, so set the effective start date to today's date.
                this.EffectiveStartDate = DateTime.UtcNow.Date;
            }
            else
            {
                //If we get into this code block, then we are creating an expired evaluation, and we should just make the start date the same as the end date.
                this.EffectiveStartDate = DateTime.UtcNow.Date.AddDays(evaluationDuration);
            }

            //Now set the evaluation's expiration date.
            this.EffectiveEndDate = CalculateNewEffectiveEndDate(evaluationDuration, extendExisting);

            //Write the aliases.
            int filesToWrite, filesWritten;

            this.WriteAliases(out filesToWrite, out filesWritten);

            //TODO: you can add your own logic here to set your own requirements for how many aliases must be written
            //      ...for this example, we only require 1
            if (filesWritten < 1)
            {
                return(false);
            }

            //Write the new license file.
            return(this.WriteLicenseFile(LicenseConfiguration.LicenseFilePath));
        }
        /// <summary>Creates an evaluation for the specified duration.</summary>
        /// <param name="evaluationDuration">The duration (in days) of the evaluation.</param>
        /// <param name="shouldCheckAliases">Whether or not aliases should be checked before creating the new evaluation license.</param>
        /// <param name="extendExisting">Whether or not any existing trial period should be extended.</param>
        /// <returns>Returns true if successful.  If false is returned, check the <see cref="License.LastError"/> property for details.</returns>
        internal bool CreateEvaluation(int evaluationDuration, bool shouldCheckAliases, bool extendExisting)
        {
            if (shouldCheckAliases)
            {
                //Start by loading and checking all the aliases
                int numAliases, numValidAliases;
                this.CheckAliases(out numAliases, out numValidAliases);

                //If we found any aliases, write the most recent one as the license file
                LicenseAlias mostRecent = LicenseAlias.GetMostCurrentAlias(this.Aliases);
                if (mostRecent.LastUpdated != DateTime.MinValue)
                {
                    this.WriteAliasToLicenseFile(mostRecent, LicenseConfiguration.LicenseFilePath);
                    this.Load(mostRecent.Contents);
                    int aliasesToWrite, aliasesWritten;
                    this.WriteAliases(out aliasesToWrite, out aliasesWritten);
                    return(true);
                }
            }

            //This sample uses the TriggerCode property to determine the type of license issued, so set it accordingly.
            TriggerCode = (int)LicenseTypes.Unlicensed;

            //Set the Product ID so this evaluation license cannot be used to update or extend another application's evaluation period.
            Product.ProductID = ThisProductID;

            //Evaluations that are not established through activation should have no License ID, Installation ID, or Installation Name.
            ClearActivationDetails();

            //TODO: IMPORTANT: Add code to clear-out other license data that is not applicable to evaluations of your license.
            //                 For example, the code below clears the date in which any downloadable license was validated, which
            //                 is stored in the UserDefinedDate1 field for this sample.
            DateDownloadableLicenseValidated = DateTime.MinValue;

            //Creating an evaluation should also remove any prior volume license data.
            RemoveVolumeLicense();

            if (evaluationDuration > 0)
            {
                //We are creating an evaluation that expires in the future, so set the effective start date to today's date.
                this.EffectiveStartDate = DateTime.UtcNow.Date;
            }
            else
            {
                //If we get into this code block, then we are creating an expired evaluation, and we should just make the start date the same as the end date.
                this.EffectiveStartDate = DateTime.UtcNow.Date.AddDays(evaluationDuration);
            }

            //Now set the evaluation's expiration date.
            this.EffectiveEndDate = CalculateNewEffectiveEndDate(evaluationDuration, extendExisting);

            //Write the aliases.
            int filesToWrite, filesWritten;

            this.WriteAliases(out filesToWrite, out filesWritten);

            //TODO: you can add your own logic here to set your own requirements for how many aliases must be written
            //      ...for this example, we only require 1
            if (filesWritten < 1)
            {
                return(false);
            }

            //Write the new license file.
            return(this.WriteLicenseFile(LicenseConfiguration.LicenseFilePath));
        }