Esempio n. 1
0
        public void LoadSaveLicense()
        {
            string publicXmlKey = KeyHelpers.GetPrivateKey();
            ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey,
                                                                             new MockLicenseStore(),
                                                                             new MachineIdentifierProviderMock(),
                                                                             new UserInformationProviderMock()
            {
                Username = "******",
                Company  = "Company",
                Email    = "*****@*****.**"
            });
            ProductLicense license = licenseManager.LoadLicense("MyProductName");

            string productKey       = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**");
            var    licenseActivated = GetProductActivated(productKey);

            Assert.AreEqual(LicenseStatus.NotFound, license.Status, license.StatusReason);

            license = licenseManager.ActivateProduct(licenseActivated);
            licenseManager.SaveLicense("MyProductName", license);
            license = licenseManager.LoadLicense("MyProductName");

            Assert.AreEqual(LicenseStatus.Licensed, license.Status, license.StatusReason);
            Assert.AreEqual(123, license.ProductID);
            Assert.AreEqual(456, license.ProductFeatures);
            Assert.AreEqual(0, license.TrialDays);
        }
Esempio n. 2
0
        /// <summary>
        /// Check the license information if we have a valid license either trial or real the application
        /// will continue to work. If there is no valid license and the warehouse was created less than 30 days before
        /// the application will work.
        /// </summary>
        public static void InitializeLicenseManager()
        {
            Nullable <LicenseStatus> previous;
            Nullable <short>         previousProductFeatures;

            if (productLicense != null)
            {
                previous = productLicense.Status;
                previousProductFeatures = productLicense.ProductFeatures;
            }
            else
            {
                previous = null;
                previousProductFeatures = null;
            }
            string publicXmlKey = RetrievePublicKey(@"RSAKeys\PublicKey.xml");

            productLicenseManager = new ProductLicenseManager(publicXmlKey);
            if (!Directory.Exists(licensePath))
            {
                CreatePath(licensePath);
            }
            productLicenseManager.SaveMachineKey(Path.Combine(licensePath, "EasyBuilder"));
            productLicense = productLicenseManager.LoadLicense(Path.Combine(licensePath, "EasyBuilder"));
            StringBuilder licenseText = new StringBuilder();

            if (CheckProduct(productLicense))
            {
                licenseText = SwitchLicenseStatus(licenseText);
            }
            else
            {
                LicenseProperties.IsActivated = false;
                licenseText.AppendLine("LIC_WrongProductLicense");
            }

            if (LicenseProperties.ActivatedFeatures.HasFlag(LicenseFeatures.Normal))
            {
                licenseText.Append("LIC_DevelopementFeature");
            }

            if (productLicense.ProductFeatures == 5)
            {
                licenseText.Append("LIC_APPSSTANDARDDEVELOPER");
            }

            LicenseProperties.LicenseTextResult = licenseText.ToString();
            if ((previous.HasValue && previous.Value != productLicense.Status) || (previousProductFeatures.HasValue && previousProductFeatures.Value != productLicense.ProductFeatures))
            {
                EventHandler handler = LicenseChanged;
                if (handler != null)
                {
                    handler(null, EventArgs.Empty);
                }
            }
        }
Esempio n. 3
0
        public void LoadSaveLicenseRealHash()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture   = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");

            string publicXmlKey = KeyHelpers.GetPrivateKey();
            ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey,
                                                                             new MockLicenseStore(),
                                                                             new MachineIdentifierProvider(null, new Security.Activation.MachineIdentifiers.VolumeInfoIdentifier(null)),
                                                                             new UserInformationProviderMock()
            {
                Username = "******",
                Company  = "Company",
                Email    = "*****@*****.**"
            });

            var hash = licenseManager.GetMachineHash();

            ProductLicense license = licenseManager.LoadLicense("MyProductName");

            string productKey       = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**");
            var    licenseActivated = GetProductActivatedRealHash(productKey, hash);

            try
            {
                using (StreamWriter writer = new StreamWriter("out.ksk", false))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ProductLicenseInfo));
                    serializer.Serialize(writer, licenseActivated);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
                return;
            }

            Assert.AreEqual(LicenseStatus.NotFound, license.Status, license.StatusReason);

            KProcess.Ksmed.Security.Activation.ProductLicenseInfo licenseInfo = null;
            try
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader("out.ksk"))
                {
                    var serializer = new System.Xml.Serialization.XmlSerializer(typeof(KProcess.Ksmed.Security.Activation.ProductLicenseInfo));
                    licenseInfo = (KProcess.Ksmed.Security.Activation.ProductLicenseInfo)serializer.Deserialize(reader);
                }
                license = licenseManager.ActivateProduct(licenseInfo);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }

            license = licenseManager.ActivateProduct(licenseInfo);
            licenseManager.SaveLicense("MyProductName", license);
            license = licenseManager.LoadLicense("MyProductName");

            Assert.AreEqual(LicenseStatus.Licensed, license.Status, license.StatusReason);
            Assert.AreEqual(123, license.ProductID);
            Assert.AreEqual(456, license.ProductFeatures);
            Assert.AreEqual(0, license.TrialDays);
        }