C# 给程序添加许可

实现许可提供程序:

using System;
using System.ComponentModel;
using System.IO;
public class MyLicenseProvider : LicenseProvider
{
    public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
    {
        if (context.UsageMode == LicenseUsageMode.Designtime)
        {
            return new MyLicense(this"OK");
        }
        else
        {
            string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "test.lic";
            if (File.Exists(licenseFile))
            {
                return new MyLicense(this"OK");
            }
            else
            {
                throw new LicenseException(type);
            }
        }
    }
}

 

许可证:

using System.ComponentModel;
public class MyLicense : License
{
    private MyLicenseProvider licenseProvider;
    private string licenseKey;

    public MyLicense(MyLicenseProvider licenseProvider, string licenseKey)
    {
        this.licenseProvider = licenseProvider;
        this.licenseKey = licenseKey;
    }
 
    public override string LicenseKey
    {
        get
        {
            return licenseKey;
        }
    }

    public override void Dispose()
    {
        this.licenseProvider = null;
        this.licenseKey = null;
    }

 

给组件添加许可:

using System;
using System.ComponentModel;
[LicenseProvider(typeof(MyLicenseProvider))]
public static class Business1
{
    static Business1()
    {
        LicenseManager.Validate(typeof(Business1), null);
    }

    public static string TestString = "test ok";
}

 

标签: 许可

posted on 2011-12-28 16:28 大豆男生 阅读(248) 评论(2) 编辑 收藏

评论

#1楼 2011-12-30 17:47 深邃的狮子座      

test.lic是什么文件?  回复 引用 查看   

#2楼[楼主] 2011-12-31 12:10 大豆男生      

@深邃的狮子座
自己创建test.lic文件,内容自定,用于验证
 回复 引用 查看   

导航

公告


励志照亮人生,创业改变命运!

Blog 访问量,点击这里查看如何添加访问计数器。
昵称:大豆男生
园龄:6年
粉丝:20
关注:3
<2011年12月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

统计

搜索

 

常用链接

最新随笔

我的标签

随笔分类(166)

随笔档案(182)

我的连接

积分与排名

最新评论

阅读排行榜

评论排行榜

推荐排行榜