示例#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);
        }
示例#2
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);
        }