방법: 구성 요소 및 컨트롤 라이센스

.NET Framework에서는 Windows Forms 컨트롤 및 ASP.NET 서버 컨트롤을 비롯하여 모든 구성 요소와 컨트롤에 대해 동일하고, Microsoft ActiveX® 컨트롤 라이선스와도 완전하게 호환되는 라이선스 모델을 제공합니다.

라이선스를 사용하면 구성 요소 또는 컨트롤 작성자가 개발자에게 해당 구성 요소 또는 컨트롤을 사용할 수 있는 권한이 있는지 확인하여 지적 재산권을 보호할 수 있습니다. 이러한 확인은 런타임보다는, 개발자가 구성 요소 또는 컨트롤을 응용 프로그램에 병합하는 디자인 타임에 더욱 중요합니다. 개발자가 디자인 타임에 라이선스가 있는 구성 요소나 컨트롤을 합법적으로 사용하면 개발자의 응용 프로그램에서는 개발자가 자유롭게 배포할 수 있는 런타임 라이선스를 가져옵니다.

라이선스 모델에서는 여러 가지 수준의 라이선스가 지원됩니다. 라이선스 모델은 구성 요소나 컨트롤에서 유효성 검사 논리를 분리합니다. 라이선스 공급자는 라이선스를 부여하고 유효성 검사 논리를 수행합니다. 공급자는 LicenseProvider에서 파생되는 클래스입니다. 라이선스를 사용하는 방법은 간단합니다.

LicFileLicenseProvider에서 제공하는 LicenseProvider의 기본 구현을 사용하면 다음과 같은 방식으로 라이선스 파일의 서식이 지정됩니다.

  • 파일 이름은 네임스페이스를 포함하며 파일 확장명이 .LIC인 클래스의 정규화된 이름이어야 합니다. 예를 들면 다음과 같습니다.

    Namespace1.Class1.LIC

  • 라이선스 파일의 내용에는 다음과 같은 텍스트 문자열이 포함되어야 합니다.

    "myClassName is a licensed component."

    여기서 myClassName은 클래스의 정규화된 이름입니다. 예를 들면 다음과 같습니다.

    "Namespace1.Class1 is a licensed component."

다음 코드 예제에서는 간단한 라이선스를 구현하는 Windows Forms 컨트롤과 ASP.NET 서버 컨트롤을 보여 줍니다.

구성 요소 또는 컨트롤에 대해 라이선스를 사용하려면

  1. 클래스에 LicenseProviderAttribute를 적용합니다.

  2. 생성자에서 Validate 또는 IsValid를 호출합니다.

  3. 부여된 모든 라이선스에 대해 Dispose를 클래스의 종료자에서 호출하거나 종료자가 호출되기 전에 호출합니다.

다음 코드 예제에서는 기본 제공되는 라이선스 공급자 클래스인 LicFileLicenseProvider가 사용되는데 이 클래스를 사용하면 텍스트 라이선스 파일을 사용하고 COM(ActiveX) 라이선스의 동작을 모방할 수 있습니다. 구성 요소의 인스턴스 수를 제한하기 위해 XML Web services를 호출하는 등의 복잡한 라이선스 시나리오를 사용하려면 다른 종류의 라이선스 공급자가 필요합니다.

예제

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 (license IsNot 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;
      }
   }
};
Imports System
Imports System.ComponentModel
Imports System.Web.UI

' Adds the LicenseProviderAttribute to the control.
<LicenseProvider(GetType(LicFileLicenseProvider))> Public Class MyControl
    Inherits Control

    ' Creates a new, null license. 
    Private license As License

    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 

    Public Overrides Sub Dispose()
        If (license IsNot Nothing) Then
            license.Dispose()
            license = Nothing 
        End If 
        MyBase.Dispose()
    End Sub 
End Class
using System;
using System.ComponentModel;
using System.Web.UI;

// Adds the LicenseProviderAttribute to the control. 
public class MyServerControl : Control 
{
    // Creates a new, null license. 
    private License license = null;

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

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

    public override void Dispose() 
    {      
        if (license != null) 
        {
            license.Dispose();
            license = null;
        }

        base.Dispose();
    }    
}

참고 항목

참조

LicenseProviderAttribute

LicenseProvider

기타 리소스

구성 요소 제작