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(); } }
/// <summary> /// The button create license click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void ButtonCreateLicClick(object sender, RoutedEventArgs e) { /* * 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> { { this.TextBoxAttributeName.Text, this.TextBoxAttributeValue.Text } }; var productFeatureDictionarty = new Dictionary <string, string> { { "Sales", this.CheckBoxSales.IsChecked.ToString() }, { "Billing", this.CheckBoxBilling.IsChecked.ToString() } }; var licenseId = Guid.NewGuid(); var datetime = DatePickerExpiration.SelectedDate; if (datetime != null) { this.ulicense = License.New().WithUniqueIdentifier(licenseId) .As(this.GetLicenseType()) .WithMaximumUtilization(int.Parse(this.TextBoxUsers.Text)) .WithAdditionalAttributes(attributesDictionarty) .WithProductFeatures(productFeatureDictionarty) .LicensedTo(this.TextBoxCustomer.Text, this.TextBoxEMail.Text) .ExpiresAt(datetime.Value.AddDays(int.Parse(TextBoxDays.Text))) .CreateAndSignWithPrivateKey(this.privateKey, this.TextBoxPassword.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(this.ulicense.ToString()); sw.Close(); sw.Dispose(); } ButtonOpenLic.IsEnabled = true; TestApp.IsEnabled = true; }