LicenseManager 类

提供属性和方法,用以将许可证添加到组件和管理 LicenseProvider。无法继承此类。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
Public NotInheritable Class LicenseManager
用法
Dim instance As LicenseManager
public sealed class LicenseManager
public ref class LicenseManager sealed
public final class LicenseManager
public final class LicenseManager

备注

LicenseManager 类提供以下 static 属性:CurrentContextUsageMode。该类还提供以下 static 方法:CreateWithContextIsValidValidate

当创建要授权的组件时,您必须执行以下操作:

  1. 使用 LicenseProviderAttribute 来标记该组件,从而指定 LicenseProvider

  2. 在组件的构造函数中调用 ValidateIsValid。当 Validate 试图在没有有效许可证的情况下创建实例时,将引发一个 LicenseExceptionIsValid 不引发异常。

  3. 当释放或完成组件后,请对任何已授权的许可证调用 Dispose

有关授权的更多信息,请参见 如何:授予组件和控件许可权限

提示

应用于此类的 HostProtectionAttribute 属性 (Attribute) 的 Resources 属性 (Property) 值如下:ExternalProcessMgmtHostProtectionAttribute 不影响桌面应用程序(这些应用程序通常通过双击图标、键入命令或在浏览器中输入 URL 来启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护属性

示例

下面的代码示例使用 Validate 方法创建授权控制。它使用由 LicFileLicenseProvider 类实现的 LicenseProvider

Imports System
Imports System.ComponentModel
Imports System.Windows.Forms

' Adds the LicenseProviderAttribute to the control.
<LicenseProvider(GetType(LicFileLicenseProvider))> _
Public Class MyControl
    Inherits Control
    
    ' Creates a new, null license.
    Private license As License = Nothing    
    
    Public Sub New()        
    
        ' Adds Validate to the control's constructor.
        license = LicenseManager.Validate(GetType(MyControl), Me)

        ' Insert code to perform other instance creation tasks here.
        
    End Sub
    
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)

        If disposing Then
            If Not (license Is Nothing) Then
                license.Dispose()
                license = Nothing
            End If
        End If

    End Sub    
    
End Class
using System;
using System.ComponentModel;
using System.Windows.Forms;


// Adds the LicenseProviderAttribute to the control.
[LicenseProvider(typeof(LicFileLicenseProvider))]
public class MyControl : Control 
{
 
   // Creates a new, null license.
   private License license = null;
 
   public MyControl () 
   {
 
      // Adds Validate to the control's constructor.
      license = LicenseManager.Validate(typeof(MyControl), this);
 
      // Insert code to perform other instance creation tasks here.
   }
 
   protected override void Dispose(bool disposing) 
   {
      if(disposing)
      {
         if (license != null) 
         {
            license.Dispose();
            license = null;
         }
      }
   }
 
}
// Adds the LicenseProviderAttribute to the control.

[LicenseProvider(LicFileLicenseProvider::typeid)]
public ref class MyControl: public Control
{
   // Creates a new, null license.
private:
   License^ license;

public:
   MyControl()
   {
      
      // Adds Validate to the control's constructor.
      license = LicenseManager::Validate( MyControl::typeid, this );

      // Insert code to perform other instance creation tasks here.
   }

public:
   ~MyControl()
   {
      if ( license != nullptr )
      {
         delete license;
         license = nullptr;
      }
   }
};
import System.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;


// Adds the LicenseProviderAttribute to the control.
/** @attribute LicenseProvider(LicFileLicenseProvider.class)
 */
public class MyControl extends Control
{
    // Creates a new, null license.
    private License license = null;

    public MyControl()
    {
        // Adds Validate to the control's constructor.
        license = LicenseManager.Validate(MyControl.class.ToType(), this);

        // Insert code to perform other instance creation tasks here.
    } 
    
    protected void Dispose(boolean disposing)
    {
        if (disposing) {
            if (license != null) {
                license.Dispose();
                license = null;
            }
        }
    } 
} 

继承层次结构

System.Object
  System.ComponentModel.LicenseManager

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

LicenseManager 成员
System.ComponentModel 命名空间
License 类
LicenseContext 类
LicenseException 类
LicenseProvider
LicenseProviderAttribute
LicFileLicenseProvider
LicenseUsageMode