Licenseable

Namespace: Babel.Licensing Assembly: Babel.Licensing.dll

Provides a set of static (Shared in Visual Basic) methods for objects that implement .

public static class Licenseable

Inheritance

objectLicenseable

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Methods

AddLicense<T>(T, ILicense)

An extension method that adds a license to the current license builder.

public static T AddLicense<T>(this T builder, ILicense license) where T : ILicenseBuilder

Parameters

NameDescription

builder T

The license builder to act on.

license ILicense

The license to add.

Returns

Type Parameters

NameDescription

T

Generic type parameter.

Examples

Dim ecdsa As New ECDsaSignature()
ecdsa.CreateKeyPair()

' Creates a composite XML license
Dim xml As String = New XmlLicense() _
	.WithUniqueId() _
	.ForAssembly(Me.[GetType]().Assembly) _
	.Build() _
	.AddLicense(
		New XmlLicense() _
		.WithUniqueId() _
		.ForAssembly("DataLayer, version=1.0.0.0") _
		.WithComponents("*")
	).AddLicense(
		New XmlLicense() _
		.WithUniqueId() _
		.ForAssembly("ViewModels, version=1.0.0.0") 
	).SignWith(ecdsa) _
	.ValidateSignature() _
	.ToReadableString()

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Build(ILicense)

An extension method that converts the input license to a object.

public static ILicenseBuilder Build(this ILicense license)

Parameters

NameDescription

license ILicense

The license to act on.

Returns

NameDescription

A that represents the input license object.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

CopyFrom<T>(T, T)

An ILicense extension method that copies ILicense objects.

public static T CopyFrom<T>(this T license, T other) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

other T

Another instance to copy.

Returns

Type Parameters

NameDescription

T

Generic type parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

ExpiresAt<T>(T, DateTime?)

An extension method that is used to assign an expiration date to the license object.

public static T ExpiresAt<T>(this T license, DateTime? expireDate) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

expireDate DateTime?

The expire date.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

ForAnyAssembly<T>(T)

An extension method that is used to license all assemblies

public static T ForAnyAssembly<T>(this T license) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

Returns

Type Parameters

NameDescription

T

Generic type parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

ForAnyComponent<T>(T)

An extension method used to license any component.

public static T ForAnyComponent<T>(this T license) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

Returns

Type Parameters

NameDescription

T

Generic type parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

ForAssembly<T>(T, Assembly)

An extension method that is used to partially fill the objects with the information provided by the given .

public static T ForAssembly<T>(this T license, Assembly assembly) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

assembly Assembly

The assembly from which the license information are retrieved.

Returns

Type Parameters

NameDescription

T

Generic type parameter .

Exceptions

NameDescription

Thrown when one or more required arguments are null.

ForAssembly<T>(T, string)

An extension method that is used to partially fill the objects with the information provided by the full assembly name.

public static T ForAssembly<T>(this T license, string fullName) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

fullName string

The assembly full name.

Returns

Type Parameters

NameDescription

T

Generic type parameter .

Exceptions

NameDescription

Thrown when one or more required arguments are null.

ForBetaTesters<T>(T, string, string, DateTime?)

An extension method used to add a object to the license.

public static T ForBetaTesters<T>(this T license, string recentChanges, string buildType = "", DateTime? expires = null) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

recentChanges string

Information about recent changes introduced with this beta release.

buildType string

The build type.

expires DateTime?

Defines a period after which this beta expires.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

ForProduct<T>(T, string, string, string, string, string)

An extension method that is used to provide information about the licensed product.

public static T ForProduct<T>(this T license, string name, string version = null, string description = null, string url = null, string copyright = null) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

name string

The product name.

version string

The product version.

description string

A description about the product.

url string

An URL where to find additional product information.

copyright string

Product copyright information.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

IssuedAt<T>(T, DateTime?)

An extension method that is used to assign the license issue date.

public static T IssuedAt<T>(this T license, DateTime? issueDate) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

issueDate DateTime?

The issue date.

Returns

Type Parameters

NameDescription

T

Generic type parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

LicensedTo<T>(T, string, string, string, string, byte[])

An extension method that is used to fill licensee information.

public static T LicensedTo<T>(this T license, string name, string contactInfo = null, string company = null, string url = null, byte[] data = null) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

name string

The licensee name.

contactInfo string

Information describing the contact.

company string

The licensee company.

url string

An URL where to find licensee information.

data byte[]

Custom licensee data.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Load(ILicenseBuilder, string)

An extension method that loads the license from a given file.

public static ILicenseBuilder Load(this ILicenseBuilder builder, string path)

Parameters

NameDescription

The license builder to act on.

path string

The file to be read.

Returns

NameDescription

The input object.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

NotForVirtualEnvironment<T>(T)

An ILicense extension method that is used to prevent the execution of the application in a virtual environment.

public static T NotForVirtualEnvironment<T>(this T license) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Examples

// Creates an XML license valid only for a specified process 
// name that is not executing in a virtual machine

var signer = XmlDigitalSignature.CreateFromKeyFile("Keys.snk");

string licenseXML = new XmlLicense().RestrictedToProcess("MotionCapture")
                                    .NotForVirtualEnvironment()
                                    .SignWith(signer)
                                    .ToReadableString();

//<Licenses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
//  <License>
//    <Restrictions>
//      <Restriction xsi:type="Usage" Id="r4A08" canRunInVirtualEnvironment="false">
//        <ProcessList>MotionCapture</ProcessList>
//      </Restriction>
//    </Restrictions>
//  </License>
//  <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
//    <SignedInfo>
//      <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
//      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
//      <Reference URI="">
//        <Transforms>
//          <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
//        </Transforms>
//        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
//        <DigestValue>ozYWhEYlFubqhRqkIrHA1kwD9sk=</DigestValue>
//      </Reference>
//    </SignedInfo>
//    <SignatureValue>afpb...</SignatureValue>
//  </Signature>
//</Licenses>

Exceptions

NameDescription

Thrown when one or more required arguments are null.

RemoveLicense<T>(T, ILicense)

An extension method that removes the given license object from the current license builder.

public static T RemoveLicense<T>(this T builder, ILicense license) where T : ILicenseBuilder

Parameters

NameDescription

builder T

The license builder to act on.

license ILicense

The license to remove.

Returns

Type Parameters

NameDescription

T

Generic type parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

RestrictedToProcess<T>(T, params string[])

An ILicense extension method that is used to restrict the license usage to a list of process names.

public static T RestrictedToProcess<T>(this T license, params string[] process) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

process string[]

A variable-length parameters list containing the process names.

Returns

Type Parameters

NameDescription

T

Generic type parameter.

Examples

// Creates an XML license valid only for a specified process 
// name that is not executing in a virtual machine

var signer = XmlDigitalSignature.CreateFromKeyFile("Keys.snk");

string licenseXML = new XmlLicense().RestrictedToProcess("MotionCapture")
                                    .NotForVirtualEnvironment()
                                    .SignWith(signer)
                                    .ToReadableString();

//<Licenses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
//  <License>
//    <Restrictions>
//      <Restriction xsi:type="Usage" Id="r4A08" canRunInVirtualEnvironment="false">
//        <ProcessList>MotionCapture</ProcessList>
//      </Restriction>
//    </Restrictions>
//  </License>
//  <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
//    <SignedInfo>
//      <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
//      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
//      <Reference URI="">
//        <Transforms>
//          <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
//        </Transforms>
//        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
//        <DigestValue>ozYWhEYlFubqhRqkIrHA1kwD9sk=</DigestValue>
//      </Reference>
//    </SignedInfo>
//    <SignatureValue>afpb...</SignatureValue>
//  </Signature>
//</Licenses>

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Save<T>(T, string)

An extension method that saves the license to a file.

public static T Save<T>(this T builder, string path) where T : ILicenseBuilder

Parameters

NameDescription

builder T

The license builder to act on.

path string

The file to be saved.

Returns

Type Parameters

NameDescription

T

Generic type parameter.

Examples

' Create a signer from a strong name key pair 
Dim signer As RSASignature = RSASignature.CreateFromKeyFile("Keys.snk")

Dim license = New XmlLicense() _
			  .ForAssembly(Me.[GetType]().Assembly) _
			  .WithId("lic0001") _
			  .WithType("Enterprise") _
			  .WithTrialDays(30) _
			  .SignWith(signer)

' Save to XmlLicense.licenses
license.Save("XmlLicense.licenses")

Exceptions

NameDescription

Thrown when one or more required arguments are null.

SignWith(ILicense, ISignatureProvider)

An ILicense extension method that is used to sign the current license object with the given .

public static ILicenseBuilder SignWith(this ILicense license, ISignatureProvider signature)

Parameters

NameDescription

license ILicense

The license to act on.

The signature provider object.

Returns

NameDescription

The input object.

Examples

This example shows how to sign a license with an RSA signature.

RSASignature rsa = new RSASignature(1024);
rsa.CreateKeyPair();

string licenseXML = new XmlLicense().ForAnyAssembly()
                        .NotForVirtualEnvironment()
                        .SignWith(rsa)
                        .ToReadableString();

//<Licenses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
//  <License>
//    <Assembly name="*" />
//    <Restrictions>
//      <Restriction xsi:type="Usage" Id="rCEA6" canRunInVirtualEnvironment="false" />
//    </Restrictions>
//  </License>
//  <Signature>
//    <Algorithm name="RSA" />
//    <RSAKeys>MIGd...</RSAKeys>
//    <SignatureValue>BNzE...</SignatureValue>
//  </Signature>
//</Licenses>

Exceptions

NameDescription

Thrown when one or more required arguments are null.

SignWith(ILicenseBuilder, ISignatureProvider)

An extension method used to sign the current license state with a given signature provider.

public static ILicenseBuilder SignWith(this ILicenseBuilder builder, ISignatureProvider provider)

Parameters

NameDescription

The license builder to act on.

The signature provider.

Returns

NameDescription

The input object.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

SignWithKeys(ILicense, string, string)

An ILicense extension method that is used to sign the current license object with the given key pair.

public static ILicenseBuilder SignWithKeys(this ILicense license, string publicKey, string privateKey)

Parameters

NameDescription

license ILicense

The license to act on.

publicKey string

The public key.

privateKey string

The private key.

Returns

NameDescription

The input object.

Examples

ECDsaSignature ecdsa = new ECDsaSignature();
ecdsa.CreateKeyPair();

var license = new StringLicense();

string str = license.WithId("101")
	.WithType("Std")
	.WithTrialDays(30)
	.SignWithKeys(ecdsa.PublicKey, ecdsa.PrivateKey)
	.ValidateSignature()
	.ToReadableString();

// 5CQRTBZLOIKSTJJLRSMFNRO2FFQVNEZFCQWYF

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments have unsupported or illegal values.

SignWithKeys(ILicenseBuilder, string, string)

An extension method used to sign the current license state with a given key pair.

public static ILicenseBuilder SignWithKeys(this ILicenseBuilder builder, string publicKey, string privateKey)

Parameters

NameDescription

The license builder to act on.

publicKey string

The public key.

privateKey string

The private key.

Returns

NameDescription

The input object.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments have unsupported or illegal values.

SupportExpiresAt<T>(T, DateTime?)

An extension method that is used to assign the support expiration date to the license object.

public static T SupportExpiresAt<T>(this T license, DateTime? expireDate) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

expireDate DateTime?

The support expire date.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

ToReadableString(ILicenseBuilder, string)

An ILicenseBuilder extension method that converts the current license to a readable string.

public static string ToReadableString(this ILicenseBuilder builder, string format = "")

Parameters

NameDescription

The license builder to act on.

format string

(Optional) Describes the format to use.

Returns

NameDescription

The input object.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments have unsupported or illegal values.

ToRestrictedDomain<T>(T, string, string)

An ILicense extension method used to add a object to the license.

public static T ToRestrictedDomain<T>(this T license, string domain, string role = null) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

domain string

The domain name.

role string

The server role.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Examples

// Creates string license restricted to a given network domain 
var license = new StringLicense();

// Add a beta information
DomainRestriction domain = new DomainRestriction();
domain.Domain = "ACMENET";

license.Restrictions.Add(domain);

// Generate the license key
var signer = RSASignature.CreateFromKeyFile("Keys.snk");
string licenseKey = license.SignWith(signer).ToReadableString();

Exceptions

NameDescription

Thrown when one or more required arguments are null.

UseOnlyAt<T>(T, string)

An ILicense extension method used to add a object to the license.

public static T UseOnlyAt<T>(this T license, string usage) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

usage string

The license usage mode.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

ValidateSignature(ILicenseBuilder)

An extension method that validates the current license signature.

public static ILicenseBuilder ValidateSignature(this ILicenseBuilder builder)

Parameters

NameDescription

The license builder to act on.

Returns

NameDescription

The input object.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments have illegal values or when the signature is not valid.

ValidateWith(ILicense, ISignatureProvider)

An ILicense extension method that validates the current license object with the given .

public static ILicenseBuilder ValidateWith(this ILicense license, ISignatureProvider signature)

Parameters

NameDescription

license ILicense

The license to act on.

The signature provider object.

Returns

NameDescription

The input object.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments have unsupported or illegal values.

ValidateWithPublicKey(ILicense, string)

An ILicense extension method that validates the current license object with the given public key.

public static ILicenseBuilder ValidateWithPublicKey(this ILicense license, string publicKey)

Parameters

NameDescription

license ILicense

The license to act on.

publicKey string

The public key.

Returns

NameDescription

The input object.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments have unsupported or illegal values.

WithComponents<T>(T, params string[])

An extension method used to add component information.

public static T WithComponents<T>(this T license, params string[] components) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

components string[]

A variable-length parameters list containing the components.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

WithFeature<T>(T, string, string, byte[], DateTime?, byte[])

An extension method that add a feature to the license.

public static T WithFeature<T>(this T license, string name, string description, byte[] data, DateTime? expires = null, byte[] key = null) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

name string

The feature name.

description string

A description about the feature.

data byte[]

Custom feature data.

expires DateTime?

The feature expire date.

key byte[]

The feature key.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Examples

ECDsaSignature ecdsa = new ECDsaSignature(ECDsaKeySize.KeySize112bit);
ecdsa.CreateKeyPair();

string licenseKey = new StringLicense()
                        .ForAnyAssembly()
                        .WithFeature("Statistics", "Statistical analysis", File.ReadAllBytes("Statistics.dll"))
                        .WithFeature("Reports", "PDF Reports", File.ReadAllBytes("Reports.dll"))
                        .SignWith(ecdsa)
                        .ToReadableString();

StringLicenseManager manager = new StringLicenseManager();
StringLicense license = manager.Validate(licenseKey);

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when the feature with the given name is already present in the features collection.

WithFeature<T>(T, Feature)

An extension method that add a feature to the license.

public static T WithFeature<T>(this T license, Feature feature) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

feature Feature

The feature object to add.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when the feature with the given name is already present in the features collection.

WithFeatures<T>(T, params Feature[])

An extension method that is used to add several license objects.

public static T WithFeatures<T>(this T license, params Feature[] features) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

features Feature[]

A variable-length parameters list containing objects.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when a feature with a given name is already present in the feature collection.

WithField<T>(T, string, string)

An extension method that is used to add license fields.

public static T WithField<T>(this T license, string name, string value) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

name string

The field name.

value string

The field value.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Examples

ECDsaSignature ecdsa = new ECDsaSignature(ECDsaKeySize.KeySize112bit);
ecdsa.CreateKeyPair();

string licenseKey = new StringLicense()
                        .ForAnyAssembly()
                        .WithField("copyright", "Copyright ACME Ltd. All rights reserved.")
                        .WithField("notes", "For resellers.")
                        .WithFields(new Field("country", "it"), new Field("zip code", "00100"))
                        .SignWith(ecdsa)
                        .ToReadableString();

StringLicenseManager manager = new StringLicenseManager();
StringLicense license = manager.Validate(licenseKey);

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when the field with the given name is already present in the collection.

WithFields<T>(T, IDictionary<string, string>)

An extension method that is used to add a dictionary of fields.

public static T WithFields<T>(this T license, IDictionary<string, string> fields) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

The dictionary of license fields to add.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when a field with a given name is already present in the field collection.

WithFields<T>(T, params Field[])

An extension method that is used to add several license fields.

public static T WithFields<T>(this T license, params Field[] fields) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

fields Field[]

The license fields to add.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Examples

ECDsaSignature ecdsa = new ECDsaSignature(ECDsaKeySize.KeySize112bit);
ecdsa.CreateKeyPair();

string licenseKey = new StringLicense()
                        .ForAnyAssembly()
                        .WithField("copyright", "Copyright ACME Ltd. All rights reserved.")
                        .WithField("notes", "For resellers.")
                        .WithFields(new Field("country", "it"), new Field("zip code", "00100"))
                        .SignWith(ecdsa)
                        .ToReadableString();

StringLicenseManager manager = new StringLicenseManager();
StringLicense license = manager.Validate(licenseKey);

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when a field with a given name is already present in the field collection.

WithHardwareKey<T>(T, string)

An extension method used to add a object to the license.

public static T WithHardwareKey<T>(this T license, string hardwareKey) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

hardwareKey string

The hardware key.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Examples

// Creates an XML license for a specific hardware 
var license = new XmlLicense();

// Add the hardware key
// The hardware key can be generated using the 
// Babel.Licensing.HardwareId class
HardwareRestriction hardware = new HardwareRestriction();
hardware.HardwareKey = "EFP76-XAJXI-655MU-JAQVX-LGYL6";

license.Restrictions.Add(hardware);

var signer = XmlDigitalSignature.CreateFromKeyFile("Keys.snk");

string licenseXML = license.SignWith(signer)
                           .ToReadableString();

// The same license can be generated using fluent API
var signer = XmlDigitalSignature.CreateFromKeyFile("Keys.snk");

string licenseXML = new XmlLicense().WithHardwareKey("EFP76-XAJXI-655MU-JAQVX-LGYL6")
                                    .SignWith(signer)
                                    .ToReadableString();

//<Licenses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
//  <License>
//    <Restrictions>
//      <Restriction xsi:type="Hardware">
//        <HardwareKey>EFP76-XAJXI-655MU-JAQVX-LGYL6</HardwareKey>
//      </Restriction>
//    </Restrictions>
//  </License>
//  <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
//    <SignedInfo>
//      <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
//      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
//      <Reference URI="">
//        <Transforms>
//          <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
//        </Transforms>
//        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
//        <DigestValue>vBCBlHCwDoJuU8+hZ5k9b2jRKfk=</DigestValue>
//      </Reference>
//    </SignedInfo>
//    <SignatureValue>CnSM...</SignatureValue>
//  </Signature>
//</Licenses>

Exceptions

NameDescription

Thrown when one or more required arguments are null.

WithId<T>(T, string)

An extension method used to assign an Id to the license.

public static T WithId<T>(this T license, string id) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

The string identifier.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

WithMaxSites<T>(T, int)

Sets the maximum number of floating or activation sites allowed for the license.

public static T WithMaxSites<T>(this T license, int sites) where T : ILicense

Parameters

NameDescription

license T

The license to which the maximum sites will be applied.

sites int

The maximum number of floating or activation sites allowed for the license.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when the provided license is null.

WithMaximumRunCount<T>(T, int?)

Defines a trial license that allow the application to run only for given number of times.

public static T WithMaximumRunCount<T>(this T license, int? runCount) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

runCount int?

The maximum number of times the application can run.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments are outside the required range.

WithMaximumRunningInstances<T>(T, int?)

Defines a trial license that allow only given number of application instances running simultaneously.

public static T WithMaximumRunningInstances<T>(this T license, int? instanceCount) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

instanceCount int?

Number of permitted instances.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments are outside the required range.

WithRestrictions<T>(T, params Restriction[])

An extension method that is used to add several license objects.

public static T WithRestrictions<T>(this T license, params Restriction[] restrictions) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

restrictions Restriction[]

A variable-length parameters list containing objects.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when a restriction with a given name is already present in the restriction collection.

WithTrialDays<T>(T, int?)

Defines a trial license which can be used for a limited number of days.

public static T WithTrialDays<T>(this T license, int? trialDays) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

trialDays int?

The number of trial days.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Examples

// Creates a 30 days trial XML license using fluent API
var signer = XmlDigitalSignature.CreateFromKeyFile("Keys.snk");

string licenseXML = new XmlLicense().ForAssembly("ACME.Web, Version=1.0.0.0")
                                    .WithTrialDays(30)
                                    .SignWith(signer)
                                    .ToReadableString();

//<Licenses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
//  <License>
//    <Assembly name="ACME.Web" version="1.0.0.0" />
//    <Restrictions>
//      <Restriction xsi:type="Trial" Id="rD842" expireDays="30" />
//    </Restrictions>
//  </License>
//  <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
//    <SignedInfo>
//      <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
//      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
//      <Reference URI="">
//        <Transforms>
//          <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
//        </Transforms>
//        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
//        <DigestValue>KOKohrsJWwhuuixC1o/gIv5wUtU=</DigestValue>
//      </Reference>
//    </SignedInfo>
//    <SignatureValue>fcUu...</SignatureValue>
//  </Signature>
//</Licenses>

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Thrown when one or more arguments are outside the required range.

WithTrialRunTime<T>(T, TimeSpan?)

Defines a trial license which can run for a limited time period.

public static T WithTrialRunTime<T>(this T license, TimeSpan? runTime) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

runTime TimeSpan?

The trial run time.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

WithType<T>(T, string)

An extension method that is used to assign the license type.

public static T WithType<T>(this T license, string type) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

type string

The license type.

Returns

Type Parameters

NameDescription

T

Generic type parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

WithUniqueId<T>(T, string, int)

An extension method that is used to assign a unique identifier to a license.

public static T WithUniqueId<T>(this T license, string prefix = "", int length = 5) where T : ILicense

Parameters

NameDescription

license T

The license to act on.

prefix string

An optional identifier prefix.

length int

The id length.

Returns

Type Parameters

NameDescription

T

Generic parameter.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Last updated