Ejemplo n.º 1
0
        private void generateLicense()
        {
            /*
             *  1. define a new Dictionary for the addition attributes and add the attributes.
             *  2. define a new Dictionary for the product features and add the features.
             *  3. create new guid as unique identifier.
             *  4. define the license with the required parameters.
             *  5. select Path and filename to write the license.
             */
            var attributesDictionarty = new Dictionary <string, string>
            {
                {
                    "HID", productid.Text
                }
            };


            var licenseId = Guid.NewGuid();


            ulicense =
                License.New().WithUniqueIdentifier(licenseId)
                .As(GetLicenseType())
                .WithMaximumUtilization(1)
                .WithAdditionalAttributes(attributesDictionarty)
                .LicensedTo(customer.Text, email.Text)
                //.CreateAndSignWithPrivateKey(privateKey, pass.Text);
                .CreateAndSignWithPrivateKey(privatekey.Text, pass.Text);

            var sfdlicense = new SaveFileDialog
            {
                Filter           = "License (*.lic)|*.lic",
                FilterIndex      = 1,
                RestoreDirectory = true,
                FileName         = "lic",
                InitialDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
            };
            var result = sfdlicense.ShowDialog();

            if (result.HasValue && result.Value)
            {
                var sw = new StreamWriter(sfdlicense.FileName, false, Encoding.UTF8);
                sw.Write(ulicense.ToString());
                sw.Close();
                sw.Dispose();
            }
        }