Example #1
0
        public virtual bool DetermineLicenseCompliance(out bool systemShouldNagUser, out string nagMessage)
        {
            systemShouldNagUser = false;
            bool compliant          = true;
            var  message            = new ParagraphBuilder();
            var  licenseInformation = LicenseServices.LicenseInformation;

            if (licenseInformation.HasLicenseOverrideCommand && licenseInformation.LicenseOverrideCommand.Action != ProductLicenseAction.Enable)
            {
                // License override is present, so use it's message
                message.AppendSentence(licenseInformation.LicenseOverrideCommand.NoticationMessage);
                systemShouldNagUser = true;
                if (licenseInformation.LicenseOverrideCommand.Action == ProductLicenseAction.DisableSoftware)
                {
                    compliant = false;
                }
            }
            else
            {
                if (Rights.FeatureRights == ProductFeatureRights.None)
                {
                    message.AppendSentence(DisabledVersionNagText);
                    systemShouldNagUser = true;
                }
                else if (Rights.FeatureRights == ProductFeatureRights.Partial || Rights.HasFiniteDays || Rights.HasFiniteUses)
                {
                    message.AppendSentence(TrialVersionNagText);
                    systemShouldNagUser = true;
                }
                else
                {
                    message.AppendSentences(FullVersionText);
                    systemShouldNagUser = false;
                }
                if (Rights.AppliesToVersion && Rights.Version != GetProductMajorVersion())
                {
                    message.Clear();
                    message.AppendSentence(string.Format(WrongVersion, Rights.Version, GetProductMajorVersion()));
                    compliant           = false;
                    systemShouldNagUser = true;
                }
                else
                {
                    if (Rights.ExpiresAfterDate)
                    {
                        if (DateTime.UtcNow > Rights.ExpirationDateUTC)
                        {
                            message.AppendSentence(string.Format(DateExpiredText, Rights.ExpirationDateUTC));
                            compliant = false;
                        }
                        else
                        {
                            message.AppendSentence(string.Format(DateExpiresText, Rights.ExpirationDateUTC));
                        }
                    }
                    if (Rights.HasFiniteDays)
                    {
                        if (Rights.DaysRemaining == 0)
                        {
                            message.AppendSentence(DaysExpiredText);
                            compliant = false;
                        }
                        message.AppendSentence(string.Format(NumDaysUsedText, ProductUsageServices.ProductUsageInformation.DaysUsedBySystem, Rights.TotalDaysAllowed));
                        systemShouldNagUser = true;
                    }

                    if (Rights.HasFiniteInstances)
                    {
                        if (Rights.InstancesRemaining == 0)
                        {
                            message.AppendSentence(InstancesExpiredText);
                            compliant           = false;
                            systemShouldNagUser = true;
                        }
                        else
                        {
                            message.AppendSentence(string.Format(NumInstancesUsed, Rights.InstancesRemaining - 1, Rights.TotalInstancesAllowed));
                        }
                    }

                    if (Rights.HasFiniteUses)
                    {
                        if (Rights.UsesRemaining == 0)
                        {
                            message.AppendSentence(UsesExpiredText);
                            compliant = false;
                        }
                        message.AppendSentence(string.Format(NumUsesText, ProductUsageServices.ProductUsageInformation.NumberOfUsesBySystem, Rights.TotalUsesAllowed));
                        systemShouldNagUser = true;
                    }

                    if (systemShouldNagUser)
                    {
                        switch (Rights.FeatureRights)
                        {
                        case ProductFeatureRights.None:
                            message.AppendSentence(PleasePurchaseText);
                            break;

                        case ProductFeatureRights.Partial:
                            message.AppendSentence(PleaseUpgradeToUnlockText);
                            break;

                        case ProductFeatureRights.Full:
                            message.AppendSentence(PleaseUpgradeBeforeExpiration);
                            break;
                        }
                    }
                }
            }

            nagMessage = message.ToString();
            return(compliant);
        }