发布于 2016-06-26 02:27:02 | 240 次阅读 | 评论: 0 | 来源: 网友投递
.NET Framework
.NET 是 Microsoft XML Web services 平台。你可以理解为.NET Framework ,XML Web services 允许应用程序通过 Internet 进行通讯和共享数据,而不管所采用的是哪种操作系统、设备或编程语言。Microsoft .NET 平台提供创建 XML Web services 并将这些服务集成在一起之所需。对个人用户的好处是无缝的、吸引人的体验。
在使用第三方类库时,经常会看到它自带的演示程序中,包含有这样的Demo许可文件
Infragistics.Win.Misc.UltraButton, Infragistics2.Win.Misc.v11.1, Version=11.1.20111.2009, Culture=neutral, PublicKeyToken=f8b58b62b52fdf31
Infragistics.Win.Misc.UltraLabel, Infragistics2.Win.Misc.v11.1, Version=11.1.20111.2009, Culture=neutral, PublicKeyToken=f8b58b62b52fdf31
Infragistics.Win.Printing.UltraPrintPreviewDialog, Infragistics2.Win.UltraWinPrintPreviewDialog.v11.1, Version=11.1.20111.2009, Culture=neutral, PublicKeyToken=f8b58b62b52fdf31
Infragistics.Win.UltraWinDataSource.UltraDataSource, Infragistics2.Win.UltraWinDataSource.v11.1, Version=11.1.20111.2009, Culture=neutral, PublicKeyToken=f8b58b62b52fdf31
控件名称, 程序集全名称
首先根据需要,写一个需要被授权的控件列表,格式如上所示。例如,HostApp.exe 的应用程序要引用Samples.DLL 中的授权控件 MyCompany.Samples.LicControl1,则可以创建包含以下内容的 HostAppLic.txt。 MyCompany.Samples.LicControl1, Samples.DLL。
再调用下面的命令创建名为 HostApp.exe.licenses 的 .licenses 文件。 lc /target:HostApp.exe /complist:hostapplic.txt /i:Samples.DLL /outdir:c:\bindir
生成将 .licenses 文件作为资源嵌入在HostApp.exe的资源中。如果生成的是 C# 应用程序,则应使用下面的命令生成应用程序。
csc /res:HostApp.exe.licenses /out:HostApp.exe *.cs
.NET Framework SDK目录中的LC.EXE文件是由.NET语言编写的,它的功能就是为了根据许可文件的内容,生成资源文件。在编译的最后时刻,由CSC编译器把生成的资源文件嵌入到执行文件中。
用.NET Reflector载入LC.EXE,开始源代码分析之旅。
if (!ProcessArgs(args))
{
return num;
}
if ((!flag3 && (str2.Length > 7)) && str2.Substring(0, 7).ToUpper(CultureInfo.InvariantCulture).Equals("TARGET:"))
{
targetPE = str2.Substring(7);
flag3 = true;
}
if ((!flag3 && (str2.Length > 8)) && str2.Substring(0, 9).ToUpper(CultureInfo.InvariantCulture).Equals("COMPLIST:"))
{
string str3 = str2.Substring(9);
if ((str3 != null) && (str3.Length > 1))
{
if (compLists == null)
{
compLists = new ArrayList();
}
compLists.Add(str3);
flag3 = true;
}
}
if ((!flag3 && (str2.Length > 2)) && str2.Substring(0, 2).ToUpper(CultureInfo.InvariantCulture).Equals("I:"))
{
string str4 = str2.Substring(2);
if (str4.Length > 0)
{
if (assemblies == null)
{
assemblies = new ArrayList();
}
assemblies.Add(str4);
}
flag3 = true;
}
ResolveEventHandler handler = new ResolveEventHandler(LicenseCompiler.OnAssemblyResolve);
AppDomain.CurrentDomain.AssemblyResolve += handler;
DesigntimeLicenseContext creationContext = new DesigntimeLicenseContext();
foreach (string str in compLists)
{
key = reader.ReadLine(); hashtable[key] = Type.GetType(key); LicenseManager.CreateWithContext((Type) hashtable[key], creationContext);
}
string path = null;
if (outputDir != null)
{
path = outputDir + @"\" + targetPE.ToLower(CultureInfo.InvariantCulture) + ".licenses";
}
else
{
path = targetPE.ToLower(CultureInfo.InvariantCulture) + ".licenses";
}
Stream o = null;
try
{
o = File.Create(path);
DesigntimeLicenseContextSerializer.Serialize(o, targetPE.ToUpper(CultureInfo.InvariantCulture), creationContext);
}
finally
{
if (o != null)
{
o.Flush();
o.Close();
}
}
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace ComponentArt.Licensing.Providers
{
#region RedistributableLicenseProvider
public class RedistributableLicenseProvider : System.ComponentModel.LicenseProvider
{
const string strAppKey = "This edition of ComponentArt Web.UI is licensed for XYZ application only.";
public override System.ComponentModel.License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
{
if (context.UsageMode == LicenseUsageMode.Designtime)
{
// We are not going to worry about design time Issue a license
return new ComponentArt.Licensing.Providers.RedistributableLicense(this, "The App");
}
else
{
string strFoundAppKey;
// During runtime, we only want this control to run in the application
// that it was packaged with.
HttpContext ctx = HttpContext.Current;
strFoundAppKey = (string)ctx.Application["ComponentArtWebUI_AppKey"];
if(strAppKey == strFoundAppKey)
return new ComponentArt.Licensing.Providers.RedistributableLicense(this, "The App");
else
return null;
}
}
}
#endregion
#region RedistributableLicense Class
public class RedistributableLicense : System.ComponentModel.License
{
private ComponentArt.Licensing.Providers.RedistributableLicenseProvider owner;
private string key;
public RedistributableLicense(ComponentArt.Licensing.Providers.RedistributableLicenseProvider owner, string key)
{
this.owner = owner;
this.key = key;
}
public override string LicenseKey
{
get
{
return key;
}
}
public override void Dispose()
{
}
}
#endregion
}
[LicenseProvider(typeof(RedistributableLicenseProvider))]
public class MyControl : Control {
// Insert code here.
protected override void Dispose(bool disposing) {
/* All components must dispose of the licenses they grant.
* Insert code here to dispose of the license. */
}
}