优化AutoCAD .NET 程序的加载——Through the Interface
2013-10-23 21:26
399 查看
原文:Optimizing the loading of AutoCAD .NET applications
我以前的一个帖子中,我描述了如何使用Autodesk.AutoCAD.Runtime.IExtensionApplication接口在实现.NET模块的初始化代码。在此基础上,我们现在要看看如何通过Autodesk.AutoCAD.Runtime.IExtensionApplication接口来优化托管模块的架构能更快的加载到AutoCAD中。
首先,是Using .NET for AutoCAD documentation中的一些信息(这些可以在ObjectARX开发指南中找到):
在AutoCAD加载托管应用程序,它先在查询程序的组件中查找ExtensionApplication这个自定义属性,如果发现这个属性,AutoCAD会把属性相关的类型设置为程序的入口,如果没发现这个属性,AutoCAD就会跳过特定于应用程序的初始化步骤。
…
除了寻找一个IExtensionApplication的实现,AutoCAD还会在查询程序的组件中查找CommandClass属性。如果发现有此属性的实例,AutoCAD只搜索相关类型作为命令对应的方法。否则,它会搜索所有的导出类型。
我在这篇博客中所提到例子以及大部分在ObjectARX SDK中的例子,它们不会告诉你在代码中如何使用ExtensionApplication或者CommandClass属性,因为实现它们对于让你的程序工作起来并不是必须的,但是但如果你有一个庞大大的.NET模块要加载到AutoCAD,AutoCAD检查该组件中的各对象来找出哪些是ExtensionApplication哪些是各种命令类就需要花费一些时间了。
你需要实现的属性都是非常简单的:
C#:
VB .NET
这些组件级别的属性只是告诉AutoCAD在哪里寻找各种对象,否则就需要通过搜来确定。以下是一些关于如何使用这些属性的文档:
该ExtensionApplication属性只能附加到一种类型。它所附加的类型必须实现IExtensionApplication接口。
CommandClass属性可以为任何定义了AutoCAD命令处理程序的函数声明。如果应用程序使用commandClass属性,它必须对每种包含AutoCAD命令处理程序方法的实例声明此属性。
为了优化昨天的代码减少加载时间,我也稍微改变了下结构使得它更合乎逻辑。上述属性也在命名空间中关联类,我决定把初始化代码(Initialization类)从命令的实现代码(Commands类)中分离出来,但是把他们都放在(“ManagedApplication”)命名空间中
这里是代码…:
C#
VB .NET
我以前的一个帖子中,我描述了如何使用Autodesk.AutoCAD.Runtime.IExtensionApplication接口在实现.NET模块的初始化代码。在此基础上,我们现在要看看如何通过Autodesk.AutoCAD.Runtime.IExtensionApplication接口来优化托管模块的架构能更快的加载到AutoCAD中。
首先,是Using .NET for AutoCAD documentation中的一些信息(这些可以在ObjectARX开发指南中找到):
在AutoCAD加载托管应用程序,它先在查询程序的组件中查找ExtensionApplication这个自定义属性,如果发现这个属性,AutoCAD会把属性相关的类型设置为程序的入口,如果没发现这个属性,AutoCAD就会跳过特定于应用程序的初始化步骤。
…
除了寻找一个IExtensionApplication的实现,AutoCAD还会在查询程序的组件中查找CommandClass属性。如果发现有此属性的实例,AutoCAD只搜索相关类型作为命令对应的方法。否则,它会搜索所有的导出类型。
我在这篇博客中所提到例子以及大部分在ObjectARX SDK中的例子,它们不会告诉你在代码中如何使用ExtensionApplication或者CommandClass属性,因为实现它们对于让你的程序工作起来并不是必须的,但是但如果你有一个庞大大的.NET模块要加载到AutoCAD,AutoCAD检查该组件中的各对象来找出哪些是ExtensionApplication哪些是各种命令类就需要花费一些时间了。
你需要实现的属性都是非常简单的:
C#:
[assembly: ExtensionApplication(typeof(InitClass))] [assembly: CommandClass(typeof(CmdClass))]
VB .NET
[assembly: ExtensionApplication(typeof(InitClass))] [assembly: CommandClass(typeof(CmdClass))]</
这些组件级别的属性只是告诉AutoCAD在哪里寻找各种对象,否则就需要通过搜来确定。以下是一些关于如何使用这些属性的文档:
该ExtensionApplication属性只能附加到一种类型。它所附加的类型必须实现IExtensionApplication接口。
CommandClass属性可以为任何定义了AutoCAD命令处理程序的函数声明。如果应用程序使用commandClass属性,它必须对每种包含AutoCAD命令处理程序方法的实例声明此属性。
为了优化昨天的代码减少加载时间,我也稍微改变了下结构使得它更合乎逻辑。上述属性也在命名空间中关联类,我决定把初始化代码(Initialization类)从命令的实现代码(Commands类)中分离出来,但是把他们都放在(“ManagedApplication”)命名空间中
这里是代码…:
C#
using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using System; [assembly: ExtensionApplication( typeof(ManagedApplication.Initialization) ) ] [assembly: CommandClass( typeof(ManagedApplication.Commands) ) ] namespace ManagedApplication { public class Initialization : Autodesk.AutoCAD.Runtime.IExtensionApplication { public void Initialize() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("Initializing - do something useful."); } public void Terminate() { Console.WriteLine("Cleaning up..."); } } public class Commands { [CommandMethod("TST")] public void Test() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("This is the TST command."); } } }
VB .NET
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.EditorInput Imports System <Assembly: _ ExtensionApplication( _ GetType(ManagedApplication.Initialization))> <Assembly: _ CommandClass( _ GetType(ManagedApplication.Commands))> Namespace ManagedApplication Public Class Initialization Implements Autodesk.AutoCAD.Runtime.IExtensionApplication Public Sub Initialize() Implements _ IExtensionApplication.Initialize Dim ed As Editor = _ Application.DocumentManager.MdiActiveDocument.Editor ed.WriteMessage("Initializing - do something useful.") End Sub Public Sub Terminate() Implements _ IExtensionApplication.Terminate Console.WriteLine("Cleaning up...") End Sub End Class Public Class Commands <CommandMethod("TST")> _ Public Sub Test() Dim ed As Editor = _ Application.DocumentManager.MdiActiveDocument.Editor ed.WriteMessage("This is the TST command.") End Sub End Class End Namespace
相关文章推荐
- Through the Interface——.NET 和 AutoCAD
- 获取AutoCAD中.Net程序定义的命令——Through the Interface
- 替换AutoCAD的OPEN命令——Through the Interface
- 在.Net程序中调用ObjectARX函数——Through the Interface
- 调试AutoCAD .Net程序加载时出现System.Windows.Markup.XamlParseException的解决办法
- 在AutoCAD中使用Python——Through the Interface
- 支持多个版本的AutoCAD——C#中的条件编译——Through the Interface
- 在autocad.net中加载lisp程序的方法
- AutoCAD .Net 程序自动加载 AutoLoader
- 关于 未能加载文件或程序集“ImageMagickNet”或它的某一个依赖项。试图加载格式不正确的程序 的解决办法
- ASP.NET 程序优化 小结
- ASP.NET程序性能优化(一)
- AutoCAD.Net/C#.Net QQ群:193522571 多个框架共一套代码在进行迁移时的问题,properties,resource,未能加载文件或程序集“System.Drawing, Version=4.0.0.0
- Asp.net程序性能优化的七个方面之七(性能测试)
- asp.net程序性能优化的七个方面(转)
- Hibernate 延迟加载导致的问题 net.sf.json.JSONException: There is a cycle in the hierarchy!
- asp.net 计划任务管理程序实现,多线程任务加载
- 博客园---ASP.NET程序优化---文章链接
- 【转载】ASP.Net程序开发性能优化---数据库优化
- 无法为具有固定名称“System.Data.SqlClient”的 ADO.NET 提供程序加载在应用程序配置文件中注册的实体框架提供程序类