Difference between revisions of "Using the ADE Server/zh"

(Created page with "试用ADE服务器")
 
 
(141 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:ADE User Guide]]
 
[[Category:ADE User Guide]]
 
<languages />
 
<languages />
[[ADE User Guide]] >
+
[[ADE User Guide/zh|ADE用户指南]] >
  
This chapter describes the Analytica Decision Engine server classes [[CAEngine]], [[CALicense]], [[CAObject]], [[CATable]], [[CAIndex]], and [[CARenderingStyle]], and the server class architecture.
+
此章描述了Analytica决策引擎服务器类型[[CAEngine/zh|CAEngine]][[CALicense/zh|CALicense]][[CAObject/zh|CAObject]][[CATable/zh|CATable]][[CAIndex/zh|CAIndex]][[CARenderingStyle/zh|CARenderingStyle]],以及服务器类型构架。
  
==ADE Classes==
+
==ADE 类型==
ADE uses the following six classes:
+
ADE使用一下六种类型:
*The [[CAEngine]] class contains methods and properties that allow you to open and close existing models, create new models, create new Analytica objects, and access Analytica objects contained in your model.
+
*[[CAEngine/zh|CAEngine]]类型所包含的方法和属性允许你打开和关闭现有模型、建立新模型、建立新的Analytica对象,以及访问你模型中所包含的Analytica对象。
*The [[CALicense]] class contains methods that allow you to instantiate a [[CAEngine]], to use a special application license code, to examine certain restrictions on your ADE license, and to access details about why a [[CAEngine]] failed to instantiate.
+
*[[CALicense/zh|CALicense]]类型所包含的方法允许你实例化[[CAEngine/zh|CAEngine]]、允许你使用一种特殊应用程序许可证代码、允许你检查ADE许可证上的某种限制、以及获取关于为什么[[CAEngine/zh |CAEngine]]未能成功实例化的详细信息。
*The [[CAObject]] class contains methods and properties that allow you to set and obtain information about the Analytica objects (such as variables or modules) that you obtain from the [[CAEngine]] class.
+
*[[CAObject]]类型所包含的方法和属性允许你设置和获取从[[CAEngine/zh|CAEngine]]获取的Analytica 对象(例如变量模块)的相关信息。
*The [[CATable]] class is used to examine multi-dimensional results or to view and modify multidimensional definition tables (also called edit tables).
+
*[[CATable/zh | CATable]]类型用来检查多维结果或者查看和修改多维定义表格(也称为编辑表)。
*A [[CAIndex]] object provides access to one dimension of a multi-dimensional [[CATable]].
+
*一个[[CAIndex/zh|CAIndex]]对象 允许你访问一个多维[[CATable/zh | CATable]]的一个维度。
*The [[CARenderingStyle]] class is new in ADE 4.0, and allows you to control or alter the format in which ADE returns values.
+
*[[CARenderingStyle/zh | CARenderingStyle]]是在ADE 4.0中出现的新特征,允许你控制或改变ADE返回值的格式 。
  
'''''Note:''' “CA” in these class names stands for “Class Analytica.”''  
+
'''''注意:''' 着些类型名称中的“CA”代表“Class Analytica。”''  
  
The following sections describe how to access these Analytica Server objects from Visual Basic or C#.
+
下面的部分描述了如何从Visual Basic或者C#中访问这些Analytica Server对象。
  
==Server Class Architectures==
+
==服务器类型构架==
===COM, Autoation, and .NET===
+
===COM、Autoation、 和.NET===
ADE 4.6 supports two calling conventions: COM and ActiveX Automation. COM is an early-binding convention in which the methods and data types are resolved when your application code is compiled. Automation is a late-binding convention where method calls are resolved at run time. The COM convention is somewhat more efficient, although for most applications, the difference in efficiency is far overshadowed by the time required to compute your model’s results.
+
ADE 4.6支持两种调用约定:COM和ActiveX Automation。COM是一种前期绑定的约定,在此约定中方法和数据类型会在你的应用程序代码被编译时确定。Automation是一种后期绑定的约定,在运行时间内决定方法调用。COM约定稍微有效一点,虽然对于大多数应用程序,该效率上的差异被计算模型结果所需时间远远地盖过。
  
In Visual Basic, the syntax for calling a method using COM or Automation is identical, and which interface is used depends on how you declare your objects. In other languages, such as C# or C++, the method of invocation can look quite different. In C# and C++, it is generally more convenient to use the COM interface. VBScript (used by the Windows Scripting Host and older versions of IIS ASP) supports only the Automation interface.
+
在Visual Basic中,使用COM或Automation的调用语法是相同的,使用哪种结构取决于你如何声明你的对象。在其他语言中,例如C#或C++,调用方法看起来完全不同。在C#或C++中,使用COM结构一般更加方便。VBScript(Windows Scripting Host和更旧的IIS ASP版本使用)只支持Automation接口。
  
The COM interface can be used transparently from a .NET environment such as Visual Studio 2005. The .NET programming environment wraps COM objects with a .NET Interop object, which gives ADE interfaces the appearance of being .NET interfaces.  
+
COM接口可以在.NET环境中,例如Visual Studio 2005,透明地使用。.NET编程环境通过使用.NET互操作对象隐藏了COM对象,这给与了ADE接口.NET接口的外观。
  
In ADE 3.1 and before, the Automation interface was the recommended convention; however, with the ADE 4.6 release, we now recommend the COM interface unless this is not an option in your programming environment (such as VBScript).
+
在ADE 3.1以及以前版本中,Automation接口是推荐使用的约定。但是随着ADE 4.6的发布,我们推荐使用COM接口,除非在你的编程环境(例如VBScript)中没法使用。
  
===In-process vs Out-of-process===
+
===进程内和进程外比较 ===
ADE can be launched either in-process or out-of-process. When launched in-process (ADEW), the <tt>Adew.dll</tt> library is loaded into your application’s process space. When launched out-of-process (ADE), the <tt>ADE.exe</tt> server is launched and runs in a different process. Both types of server use the same class interfaces, so the choice of which type of server to use can usually be changed by editing a single line of code, i.e., the line that instantiates the '''CAEngine'''.
+
ADE可以在进程内或进程外启动。当我们在进程内(ASEW)启动时,<tt>Adew.dll</tt>库被载入到你的应用程序进程空间内。当启动进程外(ADE)时,<tt>ADE.exe</tt>服务器启动,并且在不同进程内运行。两种服务器类型都是用相同的类型接口,所以到底选择使用哪种服务器通常可以通过编辑单独实例化'''CAEngine'''的这一行代码就可以改变选择。
  
In-process servers have a slight performance advantage, but come with several restrictions. First, the ''apartment'' threading model of ADEW must be compatible with your application’s threading model. For example, The Microsoft IIS web server (IIS 5.0 or later) does not allow you to use an apartment-threaded component under its default settings. Also, you are restricted to have only one [[CAEngine]] instance (and thus, only one model) in memory at any one time.
+
进程内服务器性能稍微好一点,但同时有一些限制。首先,ADEW的 ''单元 ''线程模型必须和你的应用程序的线程模型兼容。例如Microsoft IIS web server(IIS 5.0或后期版本)在其默认设置下不允许你使用单元-线程组件。其次,还限制你在任何时候在内存内只有一个[[CAEngine/zh|CAEngine]]实例(因此只有一个模型)。
  
Out-of-process instances of ADE run in a different process, and can be configured to run on a different computer from your application. Because data must be “marshaled” across process boundaries, it is less efficient, but it is far more flexible than the in-process server. Your program can make use of multiple simultaneous instances of ADE, each with a separate model instance loaded. As such, the out-of-process server is almost always preferred for web applications because you can have one ADE instance for each session
+
ADE的进程外实例在不同进程内运行,能够设置让你从你的应用程序上在另一台电脑运行。因为数据必须是跨进程打包。你的程序可以同时使用多个ADE实例,每一个都有单独的载入模型实例。例如,过程外服务器几乎总是更适合web应用程序,因为对于每一个回话,你都可以有一个ADE实例。
  
 
===Typescript===
 
===Typescript===
In addition to the program interface, ADE has a fully functional command interface, known as the ''typescript'' language. This language is described in the [[Analytica Scripting Guide]]. This language allows access to all of ADE’s functionality. The API provides a more convenient, object-oriented set of functions for communication with the engine from Visual Basic and C++ applications. A calling program can use the API functions, or it can pass typescript commands directly to the typescript interface.
+
除了程序接口,ADE还有一个完整的函数命令结构,称为''typescript''语言。该语言在[[Analytica Scripting Guide|Analytica脚本指南]]有描述。该语言允许你获取并使用ADE全部功能。API提供了一个更加方便、定向于对象的一组函数,用来从Visual Basic和C++中与引擎通讯。一个调用程序可以使用API函数,或者可以将typescript指令直接传递给typescript接口。
  
[[File:AnalyticaDecisionEngineArchitecture.jpg|375px]]
+
[[File:AnalyticaDecisionEngineArchitecture.jpg|375px|文件:AnalyticaDecisionEngineArchitecture.jpg|375px]]
  
===Security Permissios under IIS===
+
===IIS下的安全性权限===
When creating a web application that uses ADE from within Microsoft’s Active Server Pages (ASP/ASPX) under Internet Information Server (IIS), you might need to configure permission settings in order to instantiate and access the ADE COM component from your program.
+
当在Internet Information Server (IIS:互联网信息服务器)下的Microsoft Active Server Pages(ASP/ASPX:动态服务器页面)中使用ADE时,你可能需要陪着许可权限设置以便从你的应用程序实例化、访问ADE COM组件。
  
When creating a web application or web service, you should use the out-of-process ADE server. When your ASPX application is executed while serving a web page request, the ADE COM component is launched and accessed from a special internal Windows account name. Even though your programs can create and access ADE when run under your account, the same access might not exist for ASP or ASPX programs. To configure security permissions so that your ASPX application can use ADE, follows these steps:
+
在建立一个web应用程序或者web服务器时,你应该使用进程外ADE服务器。当你的ASPX应用程序在提供页面请求时被执行的情况下,ADE COM
 +
组件将从一个特殊的内部Windows账户名中启动并访问。即使在你的账户下运行时,你的应用程序能够建立并访问ADE,对于ASP或者ASPX来说不存在同样的访问。要配置安全性权限以便你的ASPX应用程序可以使用ADE,按照下面步骤操作:
  
#From the Windows Control Panel, select '''Administrative Tools > Component Services'''.  
+
#从Windows控制面板上选择'''管理员工具 > 组建服务'''.  
#*'''''Note:''' If you are using ADE 32-bit on a Windows 64-bit machine, then you must instead run:'' <tt>mmc comexp.msc /32 </tt>
+
#*'''''注意:'''如果你在一台64位计算机上使用32位版本ADE,那么你必须运行:<tt>mmc comexp.msc /32 </tt>
#In the '''DCOM Config''' folder, locate “Analytica Decision Engine Local Server 4.6.”
+
#'''DCOM Config''' 文件夹中找到“Analytica Decision Engine Local Server 4.6。”
#Select '''Properties''' from the right mouse menu, and select the Security tab.
+
#从右鼠标快捷菜单上选择'''Properties'''(属性) ,再选择 Security(安全性)标签。
#Set '''Launch and Activation Permissions''' to '''Customize''', then click '''Edit'''.
+
#'''Launch and Activation Permissions'''(启动并激活许可) 设置成'''Customize'''(自定义)然后点击'''Edit'''(编辑)
#Grant local launch and local activation permissions for the account used by IIS. In IIS 5 this is usually <tt>{computer_name}\ASPNET</tt>. In IIS 6 & 7 this is usually <tt>NETWORKSERVICES</tt> or <tt>IIS_IUSRS</tt>. In IIS 7.5, these should be set for the Application Pool name, which is usually “<tt>IIS AppPool\DefaultAppPool</tt>”.
+
#授予IIS使用账户本地启动以及本地激活许可。在 IIS 5通常是<tt>{computer_name}\ASPNET</tt>。在IIS 6 & 7通常为<tt>NETWORKSERVICES</tt>或者 <tt>IIS_IUSRS</tt>,在  IIS 7.5,应该设置应用程序池名称上相应的这些设置。,通常为“<tt>IIS AppPool\DefaultAppPool</tt>”。
#Save these settings. You might need to reboot of the machine to finalize these changes.
+
#保存这些设置。你可能需要重启你的机器才能完成这些改变。
  
When these permissions are not properly configured, a “security exception” occurs on the line of your program that attempts to instantiate the [[CAEngine]].
+
当这些许可配置不正确时,在你尝试实例化的 [[CAEngine/zh|CAEngine]]的程序上将出现一条“security exception” (安全故障)信息。
  
==The ADE Test Program==
+
==ADE测试程序==
ADE 4.6 ships with a sample program called <tt>AdeTest.exe</tt>. The executable can be found in the <tt>Examples/AdeTest/bin directory</tt>. You can use AdeTest to exercise the functionality of either the in-process (<tt>Adew.dll</tt>) or the local process (<tt>ADE.exe</tt>) versions of ADE 4.6. Using AdeTest, you can send script commands to the engine, create ADE objects, and set or call virtually any of the properties and methods of the ADE objects. If you have Visual Studio 2005 installed, you can step through the code in the Visual Studio Debugger to observe the methods being called.
+
ADE 4.6和名称为<tt>AdeTest.exe</tt>的示例程序一同安装。可执行文件位于<tt>Examples/AdeTest/bin 目录</tt>。你可以使用AdeTest来联系内部进程(<tt>Adew.dll</tt>)或者AD4.6E的本地进程(<tt>ADE.exe</tt>)版本的功能。通过使用AdeTest,你可以将脚本指令发送给引擎,建立ADE对象,实际上设置或调用ADE对象的任何属性和方法。如果你安装了Visual Studio 2005,你可以逐句调试Visual Studio Debugger中的代码以观察调用的方法。
  
The image below shows the AdeTest program dialog. The left-hand pane shows a list of ADE objects that the program is currently holding. The right side shows details of one of those objects. In the figure, there are three [[CAEngine]] instances, each with a different model open. The first [[CAEngine]] is an inprocess (<tt>Adew.dll</tt>) instance, while the second two are out-of-process local servers (<tt>ADE.exe</tt>) instances. The two buttons above the left pane can be used to create additional [[CAEngine]] instances, while the '''Release''' button at the lower-right corner of the right-hand panel releases an instance. The right-hand panel shows information about the third [[CAEngine]] instance. The current values for the [[CAEngine]] properties '''ErrorCode''', '''ErrorText''', '''CurrentModule''', '''OutputBuffer''', and '''Photo''' are displayed. You can execute a typescript command by typing the command into the text box and clicking the '''Send''' button. Or you can execute any of the method of [[CAEngine]] by selecting the method in the drop-down '''Method''' box, filling in the parameters, and clicking the '''Execute Method''' button.
+
下面的图像显示了AdeTest程序对话窗口。左手边的窗体显示了一个当前程序所包含的ADE对象列表。右边显示了其中一个对象的详细信息。在此图中,有三个[[CAEngine/zh|CAEngine]]实例,每一个都有一个打开的不同模型,第一个[[CAEngine/zh|CAEngine]]是一个个进程内实例(<tt>Adew.dll</tt),而其他两个是进程外服务器实例(<tt>ADE.exe</tt)。当右手边窗体右下角的'''Release'''按钮释放一个实例时,左边窗体上方的两个按钮可以用来建立其他的[[CAEngine/zh|CAEngine]]实例。右边窗体显示了第三个[[CAEngine/zh|CAEngine]]实例的相关信息。[[CAEngine/zh|CAEngine]]相关属性:'''ErrorCode''''''ErrorText''''''CurrentModule''''''OutputBuffer''',和 '''Photo''' 的当前值将显示。通过将指令输入进文本框并点击'''Send''' (发送)按钮,你可以执行一个typescript指令。或者通过选择'''Method''' (方法)下拉框中的方法,填写参数并点击'''Execute Method'''(执行方法)按钮,你可以[[CAEngine/zh|CAEngine]]的任何一种方法。
  
[[File:ADETestDialog.jpg]]
+
[[File:ADETestDialog.jpg|文件:ADETestDialog.jpg]]
  
If you click an object in the left-hand pane, the properties for that object are displayed on the righthand side and you can set its properties or call its methods. Thus, you can simulate a series of steps your program might execute through the graphical interface.
+
如果你点击右手边窗体中的一个对象,其对象属性将显示在收邮编,你可以设置其属性或者调用其方法。因此,你可以模拟你的程序在一个图形接口界面可能执行的一系列的步骤。
  
When a method returns an object, for example, as with '''CAEngine::GetObjectByName''', the returned object is added to the tree on the left as a child of the object that created it. After executing a method from a class other than [[CAEngine]], it is a good idea to glance at the corresponding [[CAEngine]]’s panel to check the '''ErrorCode''', '''ErrorText''', and '''OutputBuffer''' properties.
+
当一种方法返回一个对象时,例如,就'''CAEngine::GetObjectByName'''来说,返回对象被添加到左手边的关系树上成为创建它的对象的子对象。在从一个类型而非[[CAEngine/zh|CAEngine]]执行一种方法后,浏览一下相应的[[CAEngine/zh|CAEngine]]面板检查''ErrorCode''''''ErrorText''',和'''OutputBuffer''' 等属性是一个不错的习惯。
  
The '''Photo''' checkbox in the Analytica window is mirrored by the '''Photo''' property of the [[CAEngine]] class. By default the '''Photo''' property is False, so typescript communications between the client and ADE are not copied to the Analytica log window. Setting the '''Photo''' property to True copies all subsequent typescript communications between the client and ADE. In Visual Basic, this would be done as follows: <tt>
+
Analytica窗口上的'''Photo'''复选框是[[CAEngine/zh|CAEngine]]类型'''Photo''' 属性的映射。默认情况下'''Photo'''的属性是 False(假),因此用户和ADE之间的typescript通讯不会被复制到Analytica日志窗口中。将'''Photo'''属性设置成True(真)将复制用户和ADE之间的所有后继的typescript通讯。在Visual Basic中,实现此过程如下所示:
  
 
:ADE.Photo=True
 
:ADE.Photo=True
 
:ADE.Photo=False </tt>
 
:ADE.Photo=False </tt>
  
Turning on the '''Photo''' property significantly slows down communication with ADE.
+
打开'''Photo'''属性将明显减慢与ADE之间的通讯。
  
==Sample application in Excel's Visual Basic==
+
== Excel中Visual Basic样本应用程序==
Another example program called <tt>excel_exam</tt> is also included in the ADE package. The program, <tt>Analytica.xls</tt>, in the <tt>excel_exam</tt> directory can be loaded into Microsoft Excel and executed as a macro. This program demonstrates the use of Visual Basic for Applications in Excel for ADE communications. This sample makes use of the local server version of ADE.
+
另一个名称为<tt>excel_exam</tt>的示例应用程序也包含到ADE程序包中。在<tt>excel_exam</tt>目录下的 <tt>Analytica.xls</tt>程序可以载入到Microsoft Excel中,作为一个宏来运行。该程序演示了Visual Basic如何用来在Excel中应用程序里面和ADE通讯。该示例使用了ADE本地服务器版本。
  
==Sample ASP web application==
+
==ASP web 应用程序示例==
The example in <tt>asp_exam</tt> demonstrates the use of ADE from an Active Server Pages web application. This application produces a hierarchical outline of your model structure in HTML. The <tt>readme.txt</tt> file in that directory contains instructions for configuring the web server to run the example.
+
<tt>asp_exam</tt>中的示例演示了如何从一个动态服务器页面web应用程序中使用ADE。该应用程序生成了一个使用HTML语言编写的你的模型结构的分层大纲。该目录中的<tt>readme.txt</tt>文件包含配置运行该示例的web服务器的说明。
  
  When using Microsoft’s ASP, we recommend that you use the local server. By using the local server (<tt>ADE.exe</tt>), you can ensure that each web application, or even each session, uses a different version of <tt>ADE.exe</tt>. Currently, there is a limitation in ADE that prevents creation of two or more in-process server objects at the same time. Therefore, if you expect to have more than one session of ADE active at one time (as is almost always the case in web-based applications), always use the local server of ADE.
+
  在使用Microsoft的ASP(动态服务器网页)时,我们推荐使用本地服务器。通过使用本地服务器(<tt>ADE.exe</tt>),你可以确保每一个web应用程序,或者甚至每一个会话使用<tt>ADE.exe</tt>的不同版本。当前,在ADE中有一个限制阻止同时建立两个或者多个进程内服务器对象。因此,如果你想同时有多个ADE会话(同基于web的应用程序基本完全一样),总是使用ADE本地服务器。
  
==Using the ADE COM interface==
+
===在Visual Studio 2005中的.NET项目中===
===From a .NET project in Visual Studio 2005===
+
==使用ADE COM 接口==
From a Visual Basic, C#, J#, ASP.NET, or C++/CLR project in Visual Studio 2005, you gain access to ADE by adding a reference to it in your project. The same technique holds with slight variations in older (pre-.NET) versions of Visual Basic and several other non-Microsoft development environments.  
+
在Visual Studio 2005中的Visual Basic、C#、J#、ASP.NET、或者 C++/CLR项目中,你可以通过在你项目中向其添加一个引用来访问ADE。旧的Visual Basic版本(pre-.NET)和少数其他非Microsoft开发环境该方法稍微有点变化。
  
In Visual Studio 2005, select '''Add reference or References''' from the '''Project''' menu, and in the dialog that appears, select the '''COM''' tab (in VC++ you need to click the '''Add new reference''' button to get to the '''COM''' tab). In the list of components, locate and select one of the following: <tt>
+
在Visual Studio 2005中,选择'''Project''' (项目)菜单上选择 '''Add reference or References'''(添加引用),在出现的对话框中,选择'''COM'''标签(在VC++中你必须点击'''Add new reference'''按钮来获得'''COM'''标签)。在组件列表中,找到并选择下面其中的一个:<tt>
 
:Analytica Decision Engine Local Server 4.6  
 
:Analytica Decision Engine Local Server 4.6  
 
:Analytica Decision Engine Server 4.6 </tt>
 
:Analytica Decision Engine Server 4.6 </tt>
  
For out-of-process <tt>ADE.exe</tt> servers, select the Local server. To use <tt>Adew.dll</tt>, select the (nonlocal) server. It is also possible to add both references into a project (the AdeTest example does this), although the need for this would be rare.
+
对于进程外 <tt>ADE.exe</tt>服务器,选择Local server(本地服务器)。要使用<tt>Adew.dll</tt>,选择nonlocal server(非本地服务器)。当然也可能对一个项目添加这两个引用(示例AdeTest就是这样做的),但是这很少见。
  
The ADE classes are exposed in the name space ADE or ADEW for the local server and in-process server, respectively. For convenience, you can add a <tt>using</tt> declaration to the top of your source files, like this: <tt>
+
对于本地服务器和进程内服务器,ADE类型出现在同一名称空间。为了方便起见,你可以添加<tt>using</tt>声明到你的源文件的顶部,如下所示<tt>
 
:Imports ADE ’ Visual basic  
 
:Imports ADE ’ Visual basic  
 
:using ADE; // C#  
 
:using ADE; // C#  
Line 97: Line 98:
 
:import ADE.*; // J#</tt>
 
:import ADE.*; // J#</tt>
  
Of course, when using the in-process server you would type <tt>ADEW</tt> in place of <tt>ADE</tt> above. These declarations allow you to refer to [[CAEngine]], [[CAObject]], etc., in your code, rather than '''ADE.CAEngine''', '''ADE.CAObject''', etc., which makes it easy to convert from the local to the in-process ADE server should the need arise.
+
当然,在使用进程内服务器时,你将在上面的<tt>ADE</tt>的地方输入<tt>ADEW</tt> 。这些声明允许你在你的代码证引用[[CAEngine/zh|CAEngine]][[CAObject/zh|CAObject]]等等,而非'''ADE.CAEngine''''''ADE.CAObject'''等,这使从本地ADE服务器装换成进程内服务器非常容易。
  
To begin using ADE, you need to obtain a first instantiation of [[CAEngine]]. This is done with one of the following lines: <tt>
+
在开始使用ADE之前,你必须先先安装[[CAEngine/zh|CAEngine]],按照如下所示完成:<tt>:dim ADE as [[CAEngine/zh|CAEngine]] = new CAEngineClass ’ VB
:dim ADE as [[CAEngine]] = new CAEngineClass ’ VB
+
:[[CAEngine/zh|CAEngine]] ADE = new CAEngineClass(); // C#, J#  
:[[CAEngine]] ADE = new CAEngineClass(); // C#, J#  
+
:[[CAEngine/zh|CAEngine]]^ pAde = gcnew CAEngineClass();  // C++/CLR </tt>
:[[CAEngine]]^ pAde = gcnew CAEngineClass();  // C++/CLR </tt>
 
  
[[CAEngine]] is the name of a particular abstract interface, while '''ADEW.CAEngineClass''' and '''ADE.CAEngineClass''' are the names of two particular object classes that implement that interface. The [[CAEngineClass]] object is the only object that you can create directly; all other ADE object instances are obtained by calling methods on existing objects.
+
[[CAEngine/zh|CAEngine]]是一个特殊抽象接口的名称,而'''ADEW.CAEngineClass''''''ADE.CAEngineClass'''是执行该结构的两个特殊对象的名称。[[CAEngine/zh|CAEngineClass]]是唯一你能直接建立的对象;所有其他ADE对象实例是通过调用现有对象上的方法来获取的。
  
To keep the use of the COM interface, always declare your variables with the class names [[CAEngine]], [[CAObject]], [[CATable]], [[CAIndex]], and [[CARenderingStyle]]. Avoid assigning object instances to variables declared as '''System.Object'''. This allows the compiler to perform early binding and type checking.
+
要继续使用COM接口,你得使用[[CAEngine/zh|CAEngine]][[CAObject/zh|CAObject]][[CATable/zh|CATable]][[CAIndex/zh|CAIndex]][[CARenderingStyle/zh|CARenderingStyle]]等类型名称声明你的变量。避免分配对象实例给声明为'''System.Object'''的变量。这允许编译器执行初期绑定和类型检查。
  
===Releasing objects in .NET===
+
===.释放NET中的对象===
In pre-.NET Visual Basic and scripting languages, the programming environment automatically ensures that COM objects are released immediately. This is not the case in VB.NET, ASP.NET, or other .NET programs. From .NET, it is important that your program explicitly releases each COM object when it is through with it. Setting a pointer to Null (or Nothing) is not sufficient, since the actual release doesn’t occur until the next garbage collection.  
+
在pre-.NET Visual Basic和脚本语言中,编程环境自动确保COM对象立即释放。这和在VB.NET、ASP.NET、或其他.NET程序中情况不一样。当释放对象贯穿真个程序时,程序从.NET明确释放每一个COM对象非常重要。将一个指针设置成Null(或者Nothing)是不够的,因为实际释放知道下一个垃圾回收菜发生。
  
To release a COM object from a .NET program, you need to execute code similar to the following (C# syntax shown):<tt>
+
要想从.NET程序释放一个COM对象的话,你必须执行下面相似的代码(C# 语法):<tt>
 
:System.Runtime.InteropServices.Marshal.ReleaseComObject(ADE);  
 
:System.Runtime.InteropServices.Marshal.ReleaseComObject(ADE);  
 
:ADE = null; </tt>
 
:ADE = null; </tt>
  
Releasing objects in this fashion is especially important when you are using an out-of-process COM server (e.g., '''ADE.CAEngine'''). In this case, the memory resources are predominantly consumed in the ADE process, not in your program’s process. This can cause the ADE process to run out of memory before your program’s process uses enough memory to cause an automatic garbage collection to occur. From a .NET-based web application, old <tt>ADE.exe</tt> processes linger long after a session has finished unless you explicitly release the [[CAEngine]] object.
+
在你使用一个进程外COM服务器(例如:'''ADE.CAEngine''')时,以这种方式释放对象尤其重要。在此情况下,内存资源主要被ADE进程消耗,而不是被你的程序进程。这可能导致在你的程序使用足够的内存之前,ADE进程用完内存,导致自动垃圾回收发生。基于.NET的web应用程序的<tt>ADE.exe</tt>旧进程在一个会话完成后将长时间存在,除非你明确释放[[CAEngine/zh|CAEngine]]对象。
  
This need to release COM objects is not unique to ADE. You must take care to release any COM object, including those provided by Microsoft, especially when those COM objects are out-of-process.
+
需要释放COM对象不是ADE特有的。你必须处理释放所有COM对象,包括Microsoft提供的,尤其是当这些COM对象时进程外的时候。
  
Because of this absence of deterministic destruction in .NET, it can be tedious to ensure that every COM object is released. Therefore, you might want to occasionally force an explicit garbage collection in your code, which releases all unused objects. This can be accomplished by calling: <tt>
+
因为.NET中缺少这种确定性资源回收,所以确保所有COM对象都被释放让人感到很厌烦。一次,你可能偶尔想在你的代码中执行明确的垃圾回收,以此释放所有无用对象。可以通过调用下面的函数完成:<tt>
 
:System.GC.Collect()</tt>
 
:System.GC.Collect()</tt>
  
===From an ATL Project in C++===
+
===在C++ATL项目中===
To use ADE 4.6 from a non-.NET C++ project, place the following two lines at the top of your source file: <tt>
+
如果要在一个非.NET C++项目中使用ADE 4.6,将下面两行放在源文件的顶部:<tt>
 
:<nowiki>#</nowiki>import "ADE.exe"  
 
:<nowiki>#</nowiki>import "ADE.exe"  
 
:using namespace ADE; </tt>
 
:using namespace ADE; </tt>
  
Or to use the in-process server, use these lines: <tt>
+
或者如果你想使用进程内服务器时,可以使用下面的语句:<tt>
 
:<nowiki>#</nowiki>import "Adew.dll"  
 
:<nowiki>#</nowiki>import "Adew.dll"  
 
using namespace ADEW; </tt>
 
using namespace ADEW; </tt>
  
You need to include the ADE home directory in your include path in the project settings, or spell out the complete path in the <tt>#import</tt> declaration.
+
你必须将ADE根目录包含到项目设置中的包含路径中,或者在<tt>#import</tt>声明中清楚说明完整路径。
  
Next, obtain the first instance to an ADE engine using this code:<tt>
+
接下来,使用下面的代码获取第一个ADE引擎实例:<tt>
 
:CoInitialize(NULL);  
 
:CoInitialize(NULL);  
 
:CAEnginePtr pAde(__uuidof(_CAEngine));  
 
:CAEnginePtr pAde(__uuidof(_CAEngine));  
Line 141: Line 141:
 
:CoUninitialize(); </tt>
 
:CoUninitialize(); </tt>
  
'''CoInitialize()''' is a Windows system call that is required before the COM system can be used.
+
'''CoInitialize()'''是一个Windows系统调用,在COM系统能够使用之前必须调用。
  
If your project spans multiple code files, use this in each of your source files (or once in <tt>stdafx.h</tt>): <tt>
+
如果你的项目跨越多个代码文件,在你的每个源文件中使用以下代码:<tt>
 
:<nowiki>#</nowiki>import "ADE.exe" no_implementation </tt>
 
:<nowiki>#</nowiki>import "ADE.exe" no_implementation </tt>
  
And then in one file only (e.g., stdafx.cpp), include this line:
+
然后只在一个文件中(比如所stdafx.cpp)包含以下代码:<nowiki>#</nowiki>import "ADE.exe" implementation_only</tt>
:<nowiki>#</nowiki>import "ADE.exe" implementation_only</tt>
 
  
==Using the ADE Automation Interface==
+
==使用ADE自动化接口==
VBScript is an example of a scripting language, usable from Windows Scripting Host (<tt>CScript.exe</tt> or <tt>WScript.exe</tt>), pre-.NET versions of Active Server Pages, Internet Explorer, and so on. JScript is another, and many other scripting OLE-Automation compliant scripting languages are available including Perl.
+
VBScript是一个脚本语言示例,可以在Windows脚本主机(<tt>CScript.exe</tt><tt>WScript.exe</tt>)、动态服务器页面pre-.NET版本、Internet Explorer等环节下使用。JScript是另一种可以使用的脚本语言,还有其他许多脚本 OLE(对象链接和嵌入)自动化编译脚本语言可以使用,其中包含Perl语言。
  
These scripting languages support ActiveX Automation scripting, but not COM interfaces. Using the Automation interface, ADE can be used from these, often with no additional tools beyond a simple text editor.
+
这些脚本语言支持ActiveX自动化脚本,但是不支持COM接口。通过使用自动化接口,ADE能够在这些语言中使用,通常不需要其他工具,只需要一个简单的文本编辑器。
  
For ADE releases prior to 4.6, the Automation interface was the preferred convention to use. For languages that support direct COM calls, the COM convention is now recommended in ADE 4.6. Using Automation from C++ or C# is rather tedious and not covered here.
+
对于ADE4.6之前的版本,自动化接口是使用首选。对于支持直接调用COM的语言,ADE4.6中推荐首选COM接口。在C++或C#使用自动化接口是相当单调乏味的,在此我们没有叙述。
  
===From Visual Basic or VBScript===
+
===在Visual Basic或 VBScript中使用===
To use the Automation interface, it is not necessary to add a reference to your Visual Basic project. The syntax here is similar in other scripting languages. In Visual Basic, the code to instantiate a [[CAEngine]] is: <tt>
+
要使用自动化接口,没有必要给你的Visual Basic项目添加参考。下面的语法和其他脚本语言中使用情况相似。在Visual Basic中,实例化[[CAEngine]]的代码如下:<tt>
 
:dim ADE as Object  
 
:dim ADE as Object  
 
:ADE = CreateObject("ADE4.CAEngine") </tt>
 
:ADE = CreateObject("ADE4.CAEngine") </tt>
  
In VBScript, and some older versions of Visual Basic, the set keyword is required: <tt>
+
在VBScript和更早的Visual Basic版本,set关键字是必须的:<tt>
 
:dim ADE  
 
:dim ADE  
 
:set ADE = CreateObject("ADE4.CAEngine") </tt>
 
:set ADE = CreateObject("ADE4.CAEngine") </tt>
  
For the in-process server, you send the parameter '''ADEW4.CAEngine''' to the [[CreateObject]] call.
+
对于进程内服务器,将参数'''ADEW4.CAEngine'''发送给[[CreateObject/zh| CreateObject]]调用。
  
==ADE Typescript: Command Language Communication==
+
==ADE Typescript语言:指令语言通讯==
The '''[[CAEngine::Command|Command]]''' property and '''[[CAEngine::Send|Send]]''' method of the [[CAEngine]] class allow you to use typescript commands, sent as ASCII strings to the engine, and receive the resulting output as another ASCII string. You might want to use a typescript command instead of an API method if:
+
[[CAEngine/zh|CAEngine]]类型的'''[[CAEngine::Command/zh|Command]]'''属性和'''[[CAEngine::Send/zh|Send]]'''方法允许你使用typeScript指令,作为ASCII字符串发送给引擎,并获取同为ASCII字符串的输出结果。在以下情况中,你可能更偏向于使用typescript指令:
*You want to perform your own parsing on ADE output (e.g., on tabular data that are output from the Analytica Decision Engine as text strings of comma-delimited text).
+
*你想自己对来自Analytica决策引擎,以逗号隔开的文本字符串形式的ADE输出(例如一个列表数据)执行解析。
*No appropriate API method exists.
+
*不存在合适的API方法。
  
You perform these steps to send a typescript command to ADE:
+
你可以通过执行以下操作将typescript指令发送给ADE:
!Assign a text string containing the command to the Command property of your [[CAEngine]] object.
+
!将包含该指令的一个文本字符串赋值给你的[[CAEngine/zh|CAEngine]]对象的Command(指令)属性。
#Use the [[CAEngine::Send|Send]] method to send the command to the Engine. If the [[CAEngine::Send|Send]] method returns <tt>True</tt>, then the command was processed without error by ADE.
+
#使用 [[CAEngine::Send/zh|Send]]方法将指令发送给引擎。如果[[CAEngine::Send/zh|Send]]方法返回<tt>True</tt>,那么ADE处理的指令没有错误。
#Store the error code and error text (if the return code is nonzero). These two pieces of information are stored in the [[CAEngine]] properties [[CAEngine::ErrorCode]] and [[CAEngine::ErrorText|ErrorText]].
+
#如果返回代码为非零,将错误代码和错误文本存储起来。这两条信息分别存储在[[CAEngine/zh|CAEngine]]属性[[CAEngine::ErrorCode]] [[CAEngine::ErrorText/zh|ErrorText]]中。
#Get the output by calling the [[CAEngine::OutputBuffer|OutputBuffer]] function in the [[CAEngine]] class.
+
#通过调用[[CAEngine::Send/zh|Send]]类型中的[[CAEngine::OutputBuffer/zh|OutputBuffer]]函数获取输出。
  
'''''Note:''' You can also combine the first two steps by calling <tt>CAEngine.[[CAEngine::SendCommand|SendCommand]](cmd)</tt>.''  
+
'''''注意:'''你也可以通过调用<tt>CAEngine.[[CAEngine::SendCommand/zh|SendCommand]](cmd)</tt>''将前两步合并到其中。
  
These steps are demonstrated below for various programming languages. After these simple examples, subsequent examples are given using a Visual Basic syntax, but you should have no problem extrapolating the syntax to your language of choice.
+
这些步骤在下面各种编程语言中有演示说明。在这些简单示例后面,跟了几个使用Visual Basic语法的例子,你应该能够推断使用了何种语言。
  
===In Visual Basic===
+
===在Visual Basic中===  
 
<tt>
 
<tt>
 
:Imports ADE
 
:Imports ADE
Line 191: Line 190:
 
::Dim ErrCode as Integer
 
::Dim ErrCode as Integer
  
::dim ADE as [[CAEngine]] = new [[CAEngineClass]]  
+
:dim ADE as [[CAEngine/zh|CAEngine]] = new [[CAEngine/zh|CAEngineClass]]  
 
::ADE.Command = "news" ’any typescript command  
 
::ADE.Command = "news" ’any typescript command  
::dim SendCode as Boolean = ADE.[[CAEngine::Send|Send]]  
+
::dim SendCode as Boolean = ADE.[[CAEngine::Send/zh|Send]]  
 
::If SendCode = False Then  
 
::If SendCode = False Then  
:::ErrCode = ADE.[[CAEngine::ErrorCode|ErrorCode]]  
+
:::ErrCode = ADE.[[CAEngine::ErrorCode/zh|ErrorCode]]  
:::ErrT = ADE.[[CAEngine::ErrorText|ErrorText]]  
+
:::ErrT = ADE.[[CAEngine::ErrorText/zh|ErrorText]]  
 
::Else  
 
::Else  
:::Result = ADE.[[CAEngine::OutputBuffer|OutputBuffer]]  
+
:::Result = ADE.[[CAEngine::OutputBuffer/zh|OutputBuffer]]  
 
::End If  
 
::End If  
 
:End Sub  
 
:End Sub  
 
:End Module </tt>
 
:End Module </tt>
  
===In VBScript===
+
===在VBScript中===  
 
<tt>
 
<tt>
 
:set ADE = CreateObject("ADE4.CAEngine")  
 
:set ADE = CreateObject("ADE4.CAEngine")  
 
:ADE.Command = “news”  
 
:ADE.Command = “news”  
 
:If ADE.Send = False Then  
 
:If ADE.Send = False Then  
::ErrCode = ADE.[[CAEngine::ErrorCode|ErrorCode]]  
+
::ErrCode = ADE.[[CAEngine::ErrorCode/zh|ErrorCode]]  
::ErrT = ADE.[[CAEngine::ErrorText|ErrorText\\
+
::ErrT = ADE.[[CAEngine::ErrorText/zh|ErrorText]]
 
:Else  
 
:Else  
::Result = ADE.[[CAEngine::OutputBuffer|OutputBuffer]]
+
::Result = ADE.[[CAEngine::OutputBuffer/zh|OutputBuffer]]
 
:End if </tt>
 
:End if </tt>
  
===In C#===
+
===在C#===  
 
<tt>
 
<tt>
 
:using System;  
 
:using System;  
Line 226: Line 225:
 
::::String errT, result;  
 
::::String errT, result;  
 
::::int errCode;  
 
::::int errCode;  
::::[[CAEngine]] ADE = new [[CAEngineClass]]();  
+
::::[[CAEngine/zh|CAEngine]] ADE = new [[CAEngine/zh|CAEngineClass]]();  
::::ADE.[[CAEngine::Command|Command]] = "[[News]]";
+
::::ADE.[[CAEngine::Command/zh|Command]] = "[[News]]";
::::if (!ADE.[[CAEngine::Send|Send]]()) {  
+
::::if (!ADE.[[CAEngine::Send/zh|Send]]()) {  
:::::errCode = ADE.[[CAEngine::ErrorCode|ErrorCode]];  
+
:::::errCode = ADE.[[CAEngine::ErrorCode/zh|ErrorCode]];  
:::::errT = ADE.[[CAEngine::ErrorText|ErrorText]];  
+
:::::errT = ADE.[[CAEngine::ErrorText/zh|ErrorText]];  
 
::::} else {  
 
::::} else {  
:::::result = ADE.[[CAEngine::OutputBuffer|OutputBuffer]];  
+
:::::result = ADE.[[CAEngine::OutputBuffer/zh|OutputBuffer]];  
 
::::}
 
::::}
 
:::}
 
:::}
Line 238: Line 237:
 
:}</tt>
 
:}</tt>
  
===In J#===
+
===在J#===  
 
<tt>
 
<tt>
 
:import ADE.*;  
 
:import ADE.*;  
Line 247: Line 246:
 
:::String errT, result;  
 
:::String errT, result;  
 
:::int errCode;  
 
:::int errCode;  
:::ADE.[[CAEngine]] ADE = new ADE.CAEngineClass();  
+
:::ADE.[[CAEngine/zh|CAEngine]] ADE = new ADE.CAEngineClass();  
:::ADE.[[CAEngine::Command|set_Command]]("[[News]]");  
+
:::ADE.[[CAEngine::Command/zh|set_Command]]("[[News]]");  
:::boolean sendRes = ADE.[[CAEngine::Send|Send]]();  
+
:::boolean sendRes = ADE.[[CAEngine::Send/zh|Send]]();  
 
:::if (!sendRes) {  
 
:::if (!sendRes) {  
::::errCode = ADE.[[CAEngine::ErrorCode|get_ErrorCode]]();  
+
::::errCode = ADE.[[CAEngine::ErrorCode/zh|get_ErrorCode]]();  
::::errT = ADE.[[CAEngine::ErrorText|get_ErrorText]]();  
+
::::errT = ADE.[[CAEngine::ErrorText/zh|get_ErrorText]]();  
 
:::} else {  
 
:::} else {  
::::result = ADE.[[CAEngine::OutputBuffer|get_OutputBuffer]]();  
+
::::result = ADE.[[CAEngine::OutputBuffer/zh|get_OutputBuffer]]();  
 
:::}  
 
:::}  
 
::}  
 
::}  
 
:} </tt>
 
:} </tt>
  
===In C++/CLR===
+
===在C++/CLR中===
 
<tt>
 
<tt>
 
:using namespace System;  
 
:using namespace System;  
Line 267: Line 266:
 
::String ^result, ^errT;  
 
::String ^result, ^errT;  
 
::int errCode;  
 
::int errCode;  
::[[CAEngine]]^ ADE = gcnew [[CAEngineClass]]();  
+
::[[CAEngine/zh|CAEngine]]^ ADE = gcnew [[CAEngine/zh|CAEngineClass]]();  
::ADE->[[CAEngine::Command|Command]] = "[[News]]";  
+
::ADE->[[CAEngine::Command/zh|Command]] = "[[News]]";  
::if (!ADE->[[CAEngine::Send|Send]]()) {  
+
::if (!ADE->[[CAEngine::Send/zh|Send]]()) {  
:::errCode = ADE->[[CAEngine::ErrorCode|ErrorCode]];  
+
:::errCode = ADE->[[CAEngine::ErrorCode/zh|ErrorCode]];  
:::errT = ADE->[[CAEngine::ErrorText|ErrorText]];  
+
:::errT = ADE->[[CAEngine::ErrorText/zh|ErrorText]];  
 
::} else {  
 
::} else {  
:::result = ADE->[[CAEngine::OutputBuffer|OutputBuffer]];  
+
:::result = ADE->[[CAEngine::OutputBuffer/zh|OutputBuffer]];  
 
::}  
 
::}  
 
:} </tt>
 
:} </tt>
  
===In VC++ (without .NET)===
+
===在VC++中 (不带 .NET)===
 
<tt>
 
<tt>
 
:<nowiki>#</nowiki>import "ADE.exe"  
 
:<nowiki>#</nowiki>import "ADE.exe"  
Line 287: Line 286:
 
::int errCode;  
 
::int errCode;  
 
::_CAEnginePtr pAde(__uuidof(_CAEngine));  
 
::_CAEnginePtr pAde(__uuidof(_CAEngine));  
::pAde->[[CAEngine::Command|Command]] = "[[News]]";  
+
::pAde->[[CAEngine::Command/zh|Command]] = "[[News]]";  
 
::if (!pAde->Send()) {  
 
::if (!pAde->Send()) {  
:::errT = pAde->[[CAEngine::ErrorText|ErrorText]];  
+
:::errT = pAde->[[CAEngine::ErrorText/zh|ErrorText]];  
:::errCode = pAde->[[CAEngine::ErrorCode|ErrorCode]];  
+
:::errCode = pAde->[[CAEngine::ErrorCode/zh|ErrorCode]];  
 
::} else {  
 
::} else {  
:::result = pAde->[[CAEngine::OutputBuffer|OutputBuffer]];  
+
:::result = pAde->[[CAEngine::OutputBuffer/zh|OutputBuffer]];  
 
::}  
 
::}  
 
::CoUninitialize();
 
::CoUninitialize();
 
:}</tt>
 
:}</tt>
  
==Errors and Error Handling==
+
==错误与错误处理==
The [[CAEngine]] properties [[ErrorCode]] and [[ErrorText]] should be queried after any operation with ADE whenever an error is possible. Reading a value of a property from an ADE object does not change the error code. Setting the value of a property might result in an error, usually indicating an illegal value for that property. All method calls reset ErrorCode to zero if there is no error, or to a value indicating the error.
+
在进行任何ADE操作后,只要可能存在错误,就必须查询[[CAEngine/zh|CAEngine]][[CAEngine::ErrorCode/zh|ErrorCode]][[CAEngine::ErrorText/zh|ErrorText]]属性。读取ADE对象属性的一个值不会改变错误代码。设置属性值可能导致错误发生,通常说明该属性的值不合理。如果不存在错误所有方法调用都将ErrorCode设置为0,或者设置成表示该错误的值。
  
To get additional information on an error, check the [[OutputBuffer]] property of [[CAEngine]]. Any error messages that a user of Analytica would have seen appear in the output buffer.
+
要获取关于一个错误的额外信息,检查[[CAEngine/zh|CAEngine]][[CAEngine::OutputBuffer/zh|OutputBuffer]]属性即可。任何Analytica用户中的错误信息
  
==See Also==
+
==另请参考==
 
{| style="margin: 1em auto 1em auto;width: 100%;border:0;table-layout: fixed;" cellpadding=5
 
{| style="margin: 1em auto 1em auto;width: 100%;border:0;table-layout: fixed;" cellpadding=5
 
|- style="text-align: center"
 
|- style="text-align: center"
|  [[The ADE Tutorial]] <- ||  [[Using the ADE Server]] || -> [[Working with Models, Modules, and Files in ADE]]
+
|  [[The ADE Tutorial/zh|ADE入门教程]] <- ||  [[Using the ADE Server/zh|使用ADE服务器]] || -> [[Working with Models, Modules, and Files in ADE/zh|在ADE中处理模型、模块和文件]]
 
|}
 
|}

Latest revision as of 02:52, 22 October 2015

Other languages:
English • ‎中文 • ‎中文(中国大陆)‎

ADE用户指南 >

此章描述了Analytica决策引擎服务器类型CAEngineCALicenseCAObjectCATableCAIndexCARenderingStyle,以及服务器类型构架。

ADE 类型

ADE使用一下六种类型:

  • CAEngine类型所包含的方法和属性允许你打开和关闭现有模型、建立新模型、建立新的Analytica对象,以及访问你模型中所包含的Analytica对象。
  • CALicense类型所包含的方法允许你实例化CAEngine、允许你使用一种特殊应用程序许可证代码、允许你检查ADE许可证上的某种限制、以及获取关于为什么CAEngine未能成功实例化的详细信息。
  • CAObject类型所包含的方法和属性允许你设置和获取从CAEngine获取的Analytica 对象(例如变量模块)的相关信息。
  • CATable类型用来检查多维结果或者查看和修改多维定义表格(也称为编辑表)。
  • 一个CAIndex对象 允许你访问一个多维 CATable的一个维度。
  • CARenderingStyle是在ADE 4.0中出现的新特征,允许你控制或改变ADE返回值的格式 。

注意: 着些类型名称中的“CA”代表“Class Analytica。”

下面的部分描述了如何从Visual Basic或者C#中访问这些Analytica Server对象。

服务器类型构架

COM、Autoation、 和.NET

ADE 4.6支持两种调用约定:COM和ActiveX Automation。COM是一种前期绑定的约定,在此约定中方法和数据类型会在你的应用程序代码被编译时确定。Automation是一种后期绑定的约定,在运行时间内决定方法调用。COM约定稍微有效一点,虽然对于大多数应用程序,该效率上的差异被计算模型结果所需时间远远地盖过。

在Visual Basic中,使用COM或Automation的调用语法是相同的,使用哪种结构取决于你如何声明你的对象。在其他语言中,例如C#或C++,调用方法看起来完全不同。在C#或C++中,使用COM结构一般更加方便。VBScript(Windows Scripting Host和更旧的IIS ASP版本使用)只支持Automation接口。

COM接口可以在.NET环境中,例如Visual Studio 2005,透明地使用。.NET编程环境通过使用.NET互操作对象隐藏了COM对象,这给与了ADE接口.NET接口的外观。

在ADE 3.1以及以前版本中,Automation接口是推荐使用的约定。但是随着ADE 4.6的发布,我们推荐使用COM接口,除非在你的编程环境(例如VBScript)中没法使用。

进程内和进程外比较

ADE可以在进程内或进程外启动。当我们在进程内(ASEW)启动时,Adew.dll库被载入到你的应用程序进程空间内。当启动进程外(ADE)时,ADE.exe服务器启动,并且在不同进程内运行。两种服务器类型都是用相同的类型接口,所以到底选择使用哪种服务器通常可以通过编辑单独实例化CAEngine的这一行代码就可以改变选择。

进程内服务器性能稍微好一点,但同时有一些限制。首先,ADEW的 单元 线程模型必须和你的应用程序的线程模型兼容。例如Microsoft IIS web server(IIS 5.0或后期版本)在其默认设置下不允许你使用单元-线程组件。其次,还限制你在任何时候在内存内只有一个CAEngine实例(因此只有一个模型)。

ADE的进程外实例在不同进程内运行,能够设置让你从你的应用程序上在另一台电脑运行。因为数据必须是跨进程打包。你的程序可以同时使用多个ADE实例,每一个都有单独的载入模型实例。例如,过程外服务器几乎总是更适合web应用程序,因为对于每一个回话,你都可以有一个ADE实例。

Typescript

除了程序接口,ADE还有一个完整的函数命令结构,称为typescript语言。该语言在Analytica脚本指南有描述。该语言允许你获取并使用ADE全部功能。API提供了一个更加方便、定向于对象的一组函数,用来从Visual Basic和C++中与引擎通讯。一个调用程序可以使用API函数,或者可以将typescript指令直接传递给typescript接口。

文件:AnalyticaDecisionEngineArchitecture.jpg

IIS下的安全性权限

当在Internet Information Server (IIS:互联网信息服务器)下的Microsoft Active Server Pages(ASP/ASPX:动态服务器页面)中使用ADE时,你可能需要陪着许可权限设置以便从你的应用程序实例化、访问ADE COM组件。

在建立一个web应用程序或者web服务器时,你应该使用进程外ADE服务器。当你的ASPX应用程序在提供页面请求时被执行的情况下,ADE COM 组件将从一个特殊的内部Windows账户名中启动并访问。即使在你的账户下运行时,你的应用程序能够建立并访问ADE,对于ASP或者ASPX来说不存在同样的访问。要配置安全性权限以便你的ASPX应用程序可以使用ADE,按照下面步骤操作:

  1. 从Windows控制面板上选择管理员工具 > 组建服务.
    • 注意:如果你在一台64位计算机上使用32位版本ADE,那么你必须运行:mmc comexp.msc /32
  2. DCOM Config 文件夹中找到“Analytica Decision Engine Local Server 4.6。”
  3. 从右鼠标快捷菜单上选择Properties(属性) ,再选择 Security(安全性)标签。
  4. Launch and Activation Permissions(启动并激活许可) 设置成Customize(自定义)然后点击Edit(编辑)
  5. 授予IIS使用账户本地启动以及本地激活许可。在 IIS 5通常是{computer_name}\ASPNET。在IIS 6 & 7通常为NETWORKSERVICES或者 IIS_IUSRS,在 IIS 7.5,应该设置应用程序池名称上相应的这些设置。,通常为“IIS AppPool\DefaultAppPool”。
  6. 保存这些设置。你可能需要重启你的机器才能完成这些改变。

当这些许可配置不正确时,在你尝试实例化的 CAEngine的程序上将出现一条“security exception” (安全故障)信息。

ADE测试程序

ADE 4.6和名称为AdeTest.exe的示例程序一同安装。可执行文件位于Examples/AdeTest/bin 目录。你可以使用AdeTest来联系内部进程(Adew.dll)或者AD4.6E的本地进程(ADE.exe)版本的功能。通过使用AdeTest,你可以将脚本指令发送给引擎,建立ADE对象,实际上设置或调用ADE对象的任何属性和方法。如果你安装了Visual Studio 2005,你可以逐句调试Visual Studio Debugger中的代码以观察调用的方法。

下面的图像显示了AdeTest程序对话窗口。左手边的窗体显示了一个当前程序所包含的ADE对象列表。右边显示了其中一个对象的详细信息。在此图中,有三个CAEngine实例,每一个都有一个打开的不同模型,第一个CAEngine是一个个进程内实例(Adew.dll</tt),而其他两个是进程外服务器实例(ADE.exe</tt)。当右手边窗体右下角的Release按钮释放一个实例时,左边窗体上方的两个按钮可以用来建立其他的CAEngine实例。右边窗体显示了第三个CAEngine实例的相关信息。CAEngine相关属性:ErrorCodeErrorTextCurrentModuleOutputBuffer,和 Photo 的当前值将显示。通过将指令输入进文本框并点击Send (发送)按钮,你可以执行一个typescript指令。或者通过选择Method (方法)下拉框中的方法,填写参数并点击Execute Method(执行方法)按钮,你可以CAEngine的任何一种方法。

文件:ADETestDialog.jpg

如果你点击右手边窗体中的一个对象,其对象属性将显示在收邮编,你可以设置其属性或者调用其方法。因此,你可以模拟你的程序在一个图形接口界面可能执行的一系列的步骤。

当一种方法返回一个对象时,例如,就'CAEngine::GetObjectByName来说,返回对象被添加到左手边的关系树上成为创建它的对象的子对象。在从一个类型而非CAEngine执行一种方法后,浏览一下相应的CAEngine面板检查ErrorCodeErrorText,和OutputBuffer 等属性是一个不错的习惯。

Analytica窗口上的Photo复选框是CAEngine类型Photo 属性的映射。默认情况下Photo的属性是 False(假),因此用户和ADE之间的typescript通讯不会被复制到Analytica日志窗口中。将Photo属性设置成True(真)将复制用户和ADE之间的所有后继的typescript通讯。在Visual Basic中,实现此过程如下所示:

ADE.Photo=True
ADE.Photo=False

打开Photo属性将明显减慢与ADE之间的通讯。

Excel中Visual Basic样本应用程序

另一个名称为excel_exam的示例应用程序也包含到ADE程序包中。在excel_exam目录下的 Analytica.xls程序可以载入到Microsoft Excel中,作为一个宏来运行。该程序演示了Visual Basic如何用来在Excel中应用程序里面和ADE通讯。该示例使用了ADE本地服务器版本。

ASP web 应用程序示例

asp_exam中的示例演示了如何从一个动态服务器页面web应用程序中使用ADE。该应用程序生成了一个使用HTML语言编写的你的模型结构的分层大纲。该目录中的readme.txt文件包含配置运行该示例的web服务器的说明。

在使用Microsoft的ASP(动态服务器网页)时,我们推荐使用本地服务器。通过使用本地服务器(ADE.exe),你可以确保每一个web应用程序,或者甚至每一个会话使用ADE.exe的不同版本。当前,在ADE中有一个限制阻止同时建立两个或者多个进程内服务器对象。因此,如果你想同时有多个ADE会话(同基于web的应用程序基本完全一样),总是使用ADE本地服务器。 

在Visual Studio 2005中的.NET项目中

使用ADE COM 接口

在Visual Studio 2005中的Visual Basic、C#、J#、ASP.NET、或者 C++/CLR项目中,你可以通过在你项目中向其添加一个引用来访问ADE。旧的Visual Basic版本(pre-.NET)和少数其他非Microsoft开发环境该方法稍微有点变化。

在Visual Studio 2005中,选择Project (项目)菜单上选择 Add reference or References(添加引用),在出现的对话框中,选择COM标签(在VC++中你必须点击Add new reference按钮来获得COM标签)。在组件列表中,找到并选择下面其中的一个:

Analytica Decision Engine Local Server 4.6
Analytica Decision Engine Server 4.6

对于进程外 ADE.exe服务器,选择Local server(本地服务器)。要使用Adew.dll,选择nonlocal server(非本地服务器)。当然也可能对一个项目添加这两个引用(示例AdeTest就是这样做的),但是这很少见。

对于本地服务器和进程内服务器,ADE类型出现在同一名称空间。为了方便起见,你可以添加using声明到你的源文件的顶部,如下所示

Imports ADE ’ Visual basic
using ADE; // C#
using namespace ADE; // C++/CLR
import ADE.*; // J#

当然,在使用进程内服务器时,你将在上面的ADE的地方输入ADEW 。这些声明允许你在你的代码证引用CAEngineCAObject等等,而非ADE.CAEngineADE.CAObject等,这使从本地ADE服务器装换成进程内服务器非常容易。

在开始使用ADE之前,你必须先先安装CAEngine,按照如下所示完成::dim ADE as CAEngine = new CAEngineClass ’ VB

CAEngine ADE = new CAEngineClass(); // C#, J#
CAEngine^ pAde = gcnew CAEngineClass(); // C++/CLR

CAEngine是一个特殊抽象接口的名称,而ADEW.CAEngineClassADE.CAEngineClass是执行该结构的两个特殊对象的名称。CAEngineClass是唯一你能直接建立的对象;所有其他ADE对象实例是通过调用现有对象上的方法来获取的。

要继续使用COM接口,你得使用CAEngineCAObjectCATableCAIndexCARenderingStyle等类型名称声明你的变量。避免分配对象实例给声明为System.Object的变量。这允许编译器执行初期绑定和类型检查。

.释放NET中的对象

在pre-.NET Visual Basic和脚本语言中,编程环境自动确保COM对象立即释放。这和在VB.NET、ASP.NET、或其他.NET程序中情况不一样。当释放对象贯穿真个程序时,程序从.NET明确释放每一个COM对象非常重要。将一个指针设置成Null(或者Nothing)是不够的,因为实际释放知道下一个垃圾回收菜发生。

要想从.NET程序释放一个COM对象的话,你必须执行下面相似的代码(C# 语法):

System.Runtime.InteropServices.Marshal.ReleaseComObject(ADE);
ADE = null;

在你使用一个进程外COM服务器(例如:ADE.CAEngine)时,以这种方式释放对象尤其重要。在此情况下,内存资源主要被ADE进程消耗,而不是被你的程序进程。这可能导致在你的程序使用足够的内存之前,ADE进程用完内存,导致自动垃圾回收发生。基于.NET的web应用程序的ADE.exe旧进程在一个会话完成后将长时间存在,除非你明确释放CAEngine对象。

需要释放COM对象不是ADE特有的。你必须处理释放所有COM对象,包括Microsoft提供的,尤其是当这些COM对象时进程外的时候。

因为.NET中缺少这种确定性资源回收,所以确保所有COM对象都被释放让人感到很厌烦。一次,你可能偶尔想在你的代码中执行明确的垃圾回收,以此释放所有无用对象。可以通过调用下面的函数完成:

System.GC.Collect()

在C++ATL项目中

如果要在一个非.NET C++项目中使用ADE 4.6,将下面两行放在源文件的顶部:

#import "ADE.exe"
using namespace ADE;

或者如果你想使用进程内服务器时,可以使用下面的语句:

#import "Adew.dll"

using namespace ADEW;

你必须将ADE根目录包含到项目设置中的包含路径中,或者在#import声明中清楚说明完整路径。

接下来,使用下面的代码获取第一个ADE引擎实例:

CoInitialize(NULL);
CAEnginePtr pAde(__uuidof(_CAEngine));
.
.
.
CoUninitialize();

CoInitialize()是一个Windows系统调用,在COM系统能够使用之前必须调用。

如果你的项目跨越多个代码文件,在你的每个源文件中使用以下代码:

#import "ADE.exe" no_implementation

然后只在一个文件中(比如所stdafx.cpp)包含以下代码:#import "ADE.exe" implementation_only

使用ADE自动化接口

VBScript是一个脚本语言示例,可以在Windows脚本主机(CScript.exeWScript.exe)、动态服务器页面pre-.NET版本、Internet Explorer等环节下使用。JScript是另一种可以使用的脚本语言,还有其他许多脚本 OLE(对象链接和嵌入)自动化编译脚本语言可以使用,其中包含Perl语言。

这些脚本语言支持ActiveX自动化脚本,但是不支持COM接口。通过使用自动化接口,ADE能够在这些语言中使用,通常不需要其他工具,只需要一个简单的文本编辑器。

对于ADE4.6之前的版本,自动化接口是使用首选。对于支持直接调用COM的语言,ADE4.6中推荐首选COM接口。在C++或C#使用自动化接口是相当单调乏味的,在此我们没有叙述。

在Visual Basic或 VBScript中使用

要使用自动化接口,没有必要给你的Visual Basic项目添加参考。下面的语法和其他脚本语言中使用情况相似。在Visual Basic中,实例化CAEngine的代码如下:

dim ADE as Object
ADE = CreateObject("ADE4.CAEngine")

在VBScript和更早的Visual Basic版本,set关键字是必须的:

dim ADE
set ADE = CreateObject("ADE4.CAEngine")

对于进程内服务器,将参数ADEW4.CAEngine发送给 CreateObject调用。

ADE Typescript语言:指令语言通讯

CAEngine类型的Command属性和Send方法允许你使用typeScript指令,作为ASCII字符串发送给引擎,并获取同为ASCII字符串的输出结果。在以下情况中,你可能更偏向于使用typescript指令:

  • 你想自己对来自Analytica决策引擎,以逗号隔开的文本字符串形式的ADE输出(例如一个列表数据)执行解析。
  • 不存在合适的API方法。

你可以通过执行以下操作将typescript指令发送给ADE: !将包含该指令的一个文本字符串赋值给你的CAEngine对象的Command(指令)属性。

  1. 使用 Send方法将指令发送给引擎。如果Send方法返回True,那么ADE处理的指令没有错误。
  2. 如果返回代码为非零,将错误代码和错误文本存储起来。这两条信息分别存储在CAEngine属性CAEngine::ErrorCodeErrorText中。
  3. 通过调用Send类型中的OutputBuffer函数获取输出。

注意:你也可以通过调用CAEngine.SendCommand(cmd)将前两步合并到其中。

这些步骤在下面各种编程语言中有演示说明。在这些简单示例后面,跟了几个使用Visual Basic语法的例子,你应该能够推断使用了何种语言。

在Visual Basic中

Imports ADE
Module Module1
Sub Main()
Dim Result,ErrT As String
Dim ErrCode as Integer
dim ADE as CAEngine = new CAEngineClass
ADE.Command = "news" ’any typescript command
dim SendCode as Boolean = ADE.Send
If SendCode = False Then
ErrCode = ADE.ErrorCode
ErrT = ADE.ErrorText
Else
Result = ADE.OutputBuffer
End If
End Sub
End Module

在VBScript中

set ADE = CreateObject("ADE4.CAEngine")
ADE.Command = “news”
If ADE.Send = False Then
ErrCode = ADE.ErrorCode
ErrT = ADE.ErrorText
Else
Result = ADE.OutputBuffer
End if

在C#中

using System;
using ADE;
namespace ADE_from_Csharp
{
class Program
{
static void Main()
{
String errT, result;
int errCode;
CAEngine ADE = new CAEngineClass();
ADE.Command = "News";
if (!ADE.Send()) {
errCode = ADE.ErrorCode;
errT = ADE.ErrorText;
} else {
result = ADE.OutputBuffer;
}
}
}
}

在J#中

import ADE.*;
public class Program
{
public static void main( )
{
String errT, result;
int errCode;
ADE.CAEngine ADE = new ADE.CAEngineClass();
ADE.set_Command("News");
boolean sendRes = ADE.Send();
if (!sendRes) {
errCode = ADE.get_ErrorCode();
errT = ADE.get_ErrorText();
} else {
result = ADE.get_OutputBuffer();
}
}
}

在C++/CLR中

using namespace System;
using namespace ADE;
void main( )
{
String ^result, ^errT;
int errCode;
CAEngine^ ADE = gcnew CAEngineClass();
ADE->Command = "News";
if (!ADE->Send()) {
errCode = ADE->ErrorCode;
errT = ADE->ErrorText;
} else {
result = ADE->OutputBuffer;
}
}

在VC++中 (不带 .NET)

#import "ADE.exe"
using namespace ADE;
void main( )
{
CoInitialize(NULL);
_bstr_t errT, result;
int errCode;
_CAEnginePtr pAde(__uuidof(_CAEngine));
pAde->Command = "News";
if (!pAde->Send()) {
errT = pAde->ErrorText;
errCode = pAde->ErrorCode;
} else {
result = pAde->OutputBuffer;
}
CoUninitialize();
}

错误与错误处理

在进行任何ADE操作后,只要可能存在错误,就必须查询CAEngineErrorCodeErrorText属性。读取ADE对象属性的一个值不会改变错误代码。设置属性值可能导致错误发生,通常说明该属性的值不合理。如果不存在错误所有方法调用都将ErrorCode设置为0,或者设置成表示该错误的值。

要获取关于一个错误的额外信息,检查CAEngineOutputBuffer属性即可。任何Analytica用户中的错误信息

另请参考

ADE入门教程 <- 使用ADE服务器 -> 在ADE中处理模型、模块和文件
Comments


You are not allowed to post comments.