LicenseManagement Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

A static class that is used to return licenses from the persistent license store.

Inheritance Hierarchy

System.Object
  System.Windows.Media.LicenseManagement

Namespace:  System.Windows.Media
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public NotInheritable Class LicenseManagement
public static class LicenseManagement

The LicenseManagement type exposes the following members.

Properties

  Name Description
Public propertyStatic member VideoOutputConnectors Gets all the data about connector types from the graphics card, and also gets the output protection schemes for which Silverlight can engage each video output.

Top

Methods

  Name Description
Public methodStatic member SelectLicenses(Guid) Returns licenses from the persistent license store on the client based on the provided key identifier.
Public methodStatic member SelectLicenses(Stream) Returns licenses from the persistent license store on the client based on a media stream, which contains a content header.

Top

Remarks

Licenses that are persisted on the client are stored in a persistent license store, which is created on the client during individualization. For more information, see Digital Rights Management (DRM).

NoteNote:

The overloads of the SelectLicense method do not work unless the user is running the Silverlight application out-of-browser and is using elevated trust.

Examples

You can check whether a license or license chain has expired by iterating through all the licenses (MediaLicense objects) on the persistent license store. If any licenses need to be updated, you can add logic to attempt to connect to the licensing server and make necessary updates, prompt the user for payment, and so on.

The following example shows how to check whether a subscription license needs to be renewed.

private void CheckSubscriptionRootForRenewal(Guid parentKeyId,
                                             Uri licenseServerUrl)
{

    DateTime renewalDate = DateTime.Now.AddDays(5);

    // Query the licensemanager to see if we have a usable root license
    IEnumerable<MediaLicense> myLicenses = LicenseManagement.SelectLicenses(parentKeyId);

    bool renewRoot = true;

    foreach (MediaLicense ML in myLicenses)
    {
        // If the license expires within the next 5 days,
        // renew the subscription by requesting a new root license.
        if ((ML.Usable) &&
            (ML.ExpirationDate > renewalDate))
        {
            renewRoot = false;
            break;
        }

    }

    if (renewRoot)
    {
        LicenseAcquirer acquirer = new LicenseAcquirer();
        acquirer.LicenseServerUriOverride = licenseServerUrl;
        acquirer.AcquireLicenseCompleted += new EventHandler<AcquireLicenseCompletedEventArgs>(acquirer_Completed);
        acquirer.AcquireLicenseAsync(parentKeyId, ContentKeyType.Aes128Bit, Guid.Empty);
    }

In this example, you are iterating through all the MediaLicense instances in the persistent license store. A MediaLicense instance can be any of the following:

  • A license chain (leaf plus root).

  • A single simple license.

  • A single leaf license (root does not exist).

  • A single root license (root is queried directly).

The following function can be used to filter the list of content that is shown to the user in a list of possible playback choices, especially if the user is offline and cannot get new licenses. It can also be used to decide whether to get a license before going offline. For a subscription customer, the CheckSubscriptionRootForRenewal function (from the previous example) should be called first if the user is online.

public bool IsUsableLicenseAvailableForContent(System.IO.Stream contentFile)
{
    bool returnValue = false;

    // SelectLicenses works only if the user is running the Silverlight 
    // application offline *and* in elevated trust.
    IEnumerable<MediaLicense> myLicenses = LicenseManagement.SelectLicenses(contentFile);


    foreach (MediaLicense ML in myLicenses)
    {
        if (ML.Usable)
        {
            returnValue = true;
            break;
        }
    }

    return returnValue;
}

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.