示例#1
0
        protected override LicensePublisherResponse GetLicense(CultureInfo cultureInfo, string product, Version version, LicenseKey licenseKey, string category, string userName, string company, string emailAddress, string data)
        {
            if (category == "Distributable")
            {
                AssemblyLicense license = new AssemblyLicense();
                license.Product  = product;
                license.Category = category;
                license.UserName = userName;
                license.Company  = company;
                license.Data     = data;
                license.Items.Add(new LicenseItem(LicenseItems.Feature1));
                license.Items.Add(new LicenseItem(LicenseItems.Feature2));
                license.SetUpgradeExpirationDate(new DateTime(2999, 12, 31));

                return(new LicensePublisherResponse(license));
            }
            else
            {
                MachineLicense license = new MachineLicense();
                license.Product  = product;
                license.Category = category;
                license.UserName = userName;
                license.Company  = company;
                license.Data     = data;
                license.Items.Add(new LicenseItem(LicenseItems.Feature1));
                license.Items.Add(new LicenseItem(LicenseItems.Feature2));
                if (category == "Evaluation")
                {
                    license.SetExpirationDate(DateTime.UtcNow.AddMonths(3));
                }
                license.SetUpgradeExpirationDate(new DateTime(2999, 12, 31));

                return(new LicensePublisherResponse(license));
            }
        }
示例#2
0
        protected override LicensePublisherResponse GetLicense(CultureInfo cultureInfo, string product, Version version, LicenseKey licenseKey, string category, string userName, string company, string emailAddress, string data)
        {
            // Check the product
            if (product != Product)
            {
                return(new LicensePublisherResponse("Invalid product!"));
            }

            // Check the license key and category
            LicenseCategory?licenseCategory = null;

            for (int i = 0; i < s_licenseKeys.Length; i++)
            {
                if (s_licenseKeys[i] == licenseKey)
                {
                    licenseCategory = (LicenseCategory)i;
                    break;
                }
            }
            if (!licenseCategory.HasValue)
            {
                return(new LicensePublisherResponse("Invalid license key!"));
            }
            if (licenseCategory.ToString() != category)
            {
                return(new LicensePublisherResponse("Invalid category!"));
            }

            License license = new MachineLicense();

            license.Product  = Product;
            license.Category = category;
            license.UserName = userName;
            license.Company  = company;
            license.Data     = data;
            license.Items.Add(new LicenseItem(LicenseItems.Feature1, true));  // Feature1's OverrideExpirationDate is true
            license.Items.Add(new LicenseItem(LicenseItems.Feature2));

            if (licenseCategory == LicenseCategory.Evaluation)
            {
                license.SetExpirationDate(DateTime.UtcNow.AddMonths(3));
            }
            else if (licenseCategory == LicenseCategory.ExpiredEvaluation)
            {
                license.SetExpirationDate(DateTime.UtcNow); // Set ExpirationDate to now always expires the license
            }
            return(new LicensePublisherResponse(license));
        }