Custom Functoids(翻译)

Functoids 就像消费电器一样:不在乎有多少,而且好像永远不够。虽然BizTalk提供了相当齐全的functoids工具,但是你有时仍然会找不到你合适的符合你需要的functoids。这时候就要求自定义functoids(Custom Functoids)。自定义functoids是依赖于.Net程序集的类库工程。你可以通过继承Microsoft.BizTalk.BaseFunctoid类并且覆盖相应的函数来创建自定义Functoids(这个类位于Developer Tools目录下的Microsoft.BizTalk.BaseFunctoids.dll文件中)。我们通过文档或者通过在Visual Studio中添加引用来查看这个基类,发现他有相当多的接口(interface)。幸运的是,对于具体的functoid工程我们只需要覆盖有限的几个方法。

1.部署选择
在早期版本的BizTalk中Functoids是Com组件,通过暴露大块的Script脚本来工作,比如说VBScript或者JScript,并且在Mapper中把这些脚本拷贝到map中。BizTalk Server 2004 的functoids是.Net 程序集,他提供了两种选择来部署。一种和以前的老的方式很类似。一个functoid可能会提供任何一种.Net兼容的.Net源代码(VB,C#)。通过这种方式,Mapper将会接收到源代码并且合并到Map中,这种方式的优势就是可以使Map在运行时不依赖于具体的functoids组件。你的Custom functoid到时候不需要每台机器部署。很明显的缺点就是他很容易暴露你的源代码。

 如果你不希望暴露你的.Net源代码,你可以选择在map在运行时引用functoid组件。这样你必须在每台需要执行map的机器上将functoid的程序集部署到GAC中。

2.Functoid 基础

你的functoid必须执行两个准备工作。首先,必须向Mapper描述自己,然后,当测试和执行map的时候,必须提供一些自定义的function函数实现。就像我们看到的一样,要么是一大段的源代码字符串要么就是一个public的函数,BizTalk通过名字来调用。

你要做的最重要的事情就是覆盖构造函数,你可以调用到BaseFunctoid构造函数,但是你也必须提供自己的类构造函数。这里将会告诉Mapper必须的信息,让Mapper了解如何使用你的functoid。最少你必须提供以下的一些信息:

(1) 指定程序集资源的位置,比如说图片或文本等,使用SetupResourceAssembly函数。
(2) 指定资源ID来设置你的functoid的名字,使用SetName函数。
(3) 指定资源ID来设置你的functoid的ToolTip,使用SetTooltip。
(4) 指定资源ID来设置functoid的描述信息,使用SetDescription。
(5) 指定资源ID设置function的16x16位图,SetBitmap。
(6) 指定输入节点的类型,比如可以传入枚举类型等,AddInputConnectionType方法
(7) 为你的functoid设置一个ID,设定类里的ID属性
(8) 标记functoid的类型()
(9) 标记输出节点的类型,设定OutputConnectionType属性

依赖于具体的function的特性,还有其他的方法可供调用。如果你打算将你的程序集部署到GAC中供BizTalk调用,你必须调用SetExternalFunctionName函数。


-----------------------------------------
---摘自Sams-Microsoft BizTalk Server 2004 Unleashed
Custom Functoids
Functoids are like consumer electronic devices: no matter how many you have, it never seems to be enough. Although BizTalk provides a fairly full toolbox of functoids, you will encounter occasions where you can't find just the right operation for your needs. That is where custom functoids come in. Custom functoids are class library projects that reside in a .NET assembly. You create a custom functoid by deriving from the Microsoft.BizTalk.BaseFunctoid class (implemented by Microsoft.BizTalk.BaseFunctoids.dll in the Developer Tools folder) and overriding certain methods. If you inspect this base class in the documentation or by creating a reference to the assembly in Visual Studio, you will see that it has an extensive interface. Happily, the number of methods you will have to override is fairly limited for the typical functoid project.

Deployment Choices
Functoids in earlier versions of BizTalk were COM components that worked by exposing a chunk of script code, either VBScript or JScript, which Mapper copied into the body of a map. BizTalk Server 2004 functoids are .NET components, and they offer two choices for deployment. One is very similar to the old method. A functoid may offer .NET source code in any .NET-compliant language. In that case, Mapper will retrieve the source code and incorporate it into the map. This has the advantage of making the map independent of the functoid component at runtime. Your custom functoid, then, need not be deployed to every machine in the BizTalk cluster. It has the disadvantage, however, of revealing your source code.

If you don't want to expose .NET source code, you may elect to have the map reference the functoid component at runtime. If your functoid is so referenced, you will need to deploy the functoid assembly to the global assembly cache of every server expected to process the map.

Functoid Basics
Your functoid must perform two prime tasks. First, it has to describe itself to Mapper. Later, during map testing or runtime mapping, it must provide some implementation of your functionality. As we've seen, this is either a chunk of source code as a string or a public function BizTalk can call by name.

The most important thing you will do is override the class constructor. You'll call the BaseFunctoid class constructor, but you must also provide your own class constructor. This is where you tell Mapper everything it needs to know to use your functoid. At a minimum, you need to provide the following information:

Specify the location of the assembly resources, such as bitmaps and strings, with a call to SetupResourceAssembly.

Specify the resource ID of the string that provides the name of your functoid with a call to SetName.

Specify the resource ID of the string containing the ToolTip for your functoid with a call to SetTooltip.

Specify the resource ID of the string describing your functoid through a call to SetDescription.

Specify the resource ID of the 16x16 pixel bitmap Mapper should place in the toolbox through a call to SetBitmap.

Specify the kinds of nodes that can be connected as inputs to the functoid by passing an enumerated value or a bitwise combination of enumerated values in a call to AddInputConnectionType.

Set an ID for your functoid by setting the ID property of the class.

Indicate which functoid category (from the existing toolbox palettes) your functoid belongs to by setting the Category property of the class.

Indicate which types of nodes can be connected to the functoid to accept its output by setting the OutputConnectionType property of the class.

There are other methods you can call, depending on the nature of your functoid. If you opt to deploy your assembly to the GAC and have BizTalk call into it, you must call SetExternalFunctionName.

posted @ 2007-02-08 11:27  upzone  阅读(578)  评论(1编辑  收藏  举报