使用C#中的Portable.License向客户添加“公司”

时间:2018-11-05 10:25:28

标签: c# licensing

我目前正在使用以下Portable.Licensing(https://github.com/dnauck/Portable.Licensing)代码构建许可证:

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

对于LicensedTo()函数,有一个附加定义,它带有一个附加参数:

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

如何使用此附加参数将“公司名称”以及名称和电子邮件包括在内?

1 个答案:

答案 0 :(得分:1)

为此使用WithAdditionalAttributes

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);

并从生成的许可证中获取它:

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