Cracker 's Blog

Now, flutter and fly For own goal. No longer be puerility.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

授权组件设计 - LicenseControlProject

Posted on 2006-09-28 19:11  Cracker  阅读(2212)  评论(0编辑  收藏  举报

授权组件设计使用到的主要类型 - System.ComponentModel.License
核心代码:
public class LicenseControl
{
    private License license = null;
    public LicenseControl()
    {
          license = LicenseManager.Validate(typeof(LicenseControl), this);        
          InitializeComponent();
    }
    protected override void Dispose(bool disposing)
    {
        //释放资源
        if (disposing && (license != null))
        {
          license.Dispose();
          license = null;
        }

        if (disposing && (components != null))
        {
          components.Dispose();
        }
        base.Dispose(disposing);
    }
}

一、以下是组件主要代码:

 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Drawing;
 5using System.Data;
 6using System.Text;
 7using System.Windows.Forms;
 8
 9namespace LicenseControlProject
10{
11    public partial class LicenseControl : UserControl
12    {
13        private License license = null;
14
15        public LicenseControl()
16        {
17            license = LicenseManager.Validate(typeof(LicenseControl), this);
18            InitializeComponent();
19        }

20
21        /// <summary>
22        /// 清理所有正在使用的资源。
23        /// </summary>
24        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>

25        protected override void Dispose(bool disposing)
26        {
27            //释放资源
28            if (disposing && (license != null))
29            {
30                license.Dispose();
31                license = null;
32            }

33
34            if (disposing && (components != null))
35            {
36                components.Dispose();
37            }

38            base.Dispose(disposing);
39        }

40    }

41}

二、用户使用本组件时需获得一个NameSpace.Class.LIC授权文件。
  文件格式:"NameSpace.Class 是一个授权组件。"
  例如:"LicenseControlProject.LicenseControl 是一个授权组件。"

项目文件:http://cracker.blog.ccidnet.com/job.php?action=download&pid=&tid=91928&aid=10108