Adding ‘company’ to a customer using portable.licensing in C#

Viewed 476

I am currently building licenses using the following Portable.Licensing (https://github.com/dnauck/Portable.Licensing) code:

var license = Portable.Licensing.License.New();
license.WithUniqueIdentifier(guid);
license.As(Portable.Licensing.LicenseType.Standard);
license.LicensedTo(textBox_LicenseName.Text, textBox_LicenseEmail.Text);

There is an alternative definition for the function LicensedTo() that takes an additional argument:

LicensedTo(string name, string email, Action<Customer> configureCustomer);

How do I go about using this additional argument to include the 'Company Name' along with the Name and Email?

1 Answers

Use the WithAdditionalAttributes for that:

var license = License.New()
    .WithUniqueIdentifier(Guid.NewGuid())

    //Look here
    .WithAdditionalAttributes(new Dictionary<string, string>
    {
        {"CompanyName", companyName }
    })

    .As(LicenseType.Trial)
    .ExpiresAt(DateTime.Now.AddDays(30))
    .WithMaximumUtilization(numberOfUsers)
    .LicensedTo(licensedTo, contactEmail)
    .CreateAndSignWithPrivateKey(privateKey, passPhrase);

And to retrieve it from the generated license:

var fs = new FileStream("license.lic", FileMode.Open);
var license = License.Load(fs);
var name = license.AdditionalAttributes.Get("CompanyName");
fs.Close();
Related