tailieunhanh - Wrox Professional Web Parts and Custom Controls with ASP.NET 2.0 phần 6
Ví dụ bạn có thể dùng một lớp C# kế thừa từ một đối tượng COM C++/ATL, lớp này lại có thể bắt lỗi từ một chương trình Vbasic. Nhờ có sự hỗ trợ từ cấp hệ thống cho phép tích hợp đa ngôn ngữ, bạn có thể chạy từng bước để bẫy lỗi qua cả 3 ngôn ngữ trong cùng một môi trường phát triển ứng dụng . | Chapter 7 The LicenseProvider is passed a number of parameters context This object provides information about the environment that the control is executing in. The UsageMode property in this object for instance allows you to check whether the control is in design or run time mode. type The datatype of the control. instance A reference to the control. allowExceptions When set to True it indicates that a LicenseException is to be thrown if licensing fails. Now that your license and license provider are built you need to attach the license provider to your custom control. Follow these steps 1. Add the LicenseProviderAttribute to your class declaration and pass the attribute a reference to your license provider. This Visual Basic 2005 example uses the license provider created in the previous section LicenseProvider GetType MyLicensingProvider _ ToolboxData 0 MyControl1 runat server 0 MyControl1 _ Public Class MyControl In C LicenseProvider typeof MyLicensingProvider ToolboxData 0 MyControl1 runat server 0 MyControl1 public class MyControl 2. In your control s constructor your control should call the Validate method of the LicenseManager object the LicenseManager automatically references the LicenseProvider referenced by the attribute on the class . If the licensing fails a LicenseException error is raised terminating the control s processing. This Visual Basic 2005 code demonstrates how the Validate method is used Dim lic As Public Sub New lic GetType MyControl Me End Sub In C public class MyControl lic public MyControl lic typeof MyControl this 198 Developer Tools 3. In the Dispose method of your control call the Dispose method of any license that you retrieved in your control s constructor and haven t already disposed Public Overloads Overrides Sub Dispose If lic IsNot Nothing Then lic Nothing End If End Sub In C public override void Dispose if lic
đang nạp các trang xem trước