1. 在VS2005中新建Class Libiary项目,就叫MyCustomId
2. 添加安装目录Program Files/Microsoft BizTalk Server 2006/Developer Tools里的Microsoft.BizTalk.BaseFunctoids.dll的引用,引用名字空间:
using Microsoft.BizTalk.BaseFunctoids;
using System.Reflection;
using System.Globalization;
using System.Resources;
3. 把默认的Class1改为MyCustomIdClass并继承BaseFunctoid public class MyCustomIdClass : BaseFunctoid { }
4. 项目里添加新项中添加资源文件:CustomFuncRes.resx,添加名称
并添加一个16*16的图像,叫MyImg
5. FunctoId执行代码
static ResourceManager resmgr = new ResourceManager("MyCustomId.CustomFuncRes", Assembly.GetExecutingAssembly());
public MyCustomIdClass()
{
int functoidID;
functoidID = System.Convert.ToInt32(resmgr.GetString("MyFunctoId_ID"));
this.ID = functoidID;
SetupResourceAssembly("MyCustomId.CustomFuncRes", Assembly.GetExecutingAssembly());
//FunctoId的设置
SetName("MyFunctoId_Name");
SetTooltip("MyFunctoId_Tips");
SetDescription("MyFunctoId_Desc");
SetBitmap("MyImg");
this.SetMinParams(2);
this.SetMaxParams(2);
SetExternalFunctionName(GetType().Assembly.FullName, "MyCustomId.MyCustomIdClass", "GetPerime");
this.Category = FunctoidCategory.Math;
this.OutputConnectionType = ConnectionType.AllExceptRecord;
AddInputConnectionType(ConnectionType.AllExceptRecord);
}
6. FunctoId的逻辑代码:
public string GetPerime(string RectangleLength, string RectangleBreadth)
{
int ilength = 0;
int ibreadth = 0;
int iPerimeter = 0;
ResourceManager resmgr = new ResourceManager("MyCustomId.CustomFuncRes", Assembly.GetExecutingAssembly());
RectangleLength = RectangleLength.Trim();
RectangleBreadth = RectangleBreadth.Trim();
if (IsNumeric(RectangleLength) && IsNumeric(RectangleBreadth))
{
try
{
ilength = Convert.ToInt32(RectangleLength,
System.Globalization.CultureInfo.InvariantCulture);
ibreadth = Convert.ToInt32(RectangleBreadth,
System.Globalization.CultureInfo.InvariantCulture);
iPerimeter = 2 * (ilength + ibreadth);
}
catch
{
throw new Exception(string.Format(resmgr.GetString(
"MyFunctoId_Exception"),
RectangleLength + " " +
RectangleBreadth));
}
}
return iPerimeter.ToString();
}
7. 给项目属性里设置签名,或执行C:/ sn -k MyFuncID.snk 生成密钥,编译项目。
8. 添加生成的dll文件到GAC,并copy到BizTalk安装目录Program Files/Microsoft BizTalk Server 2006/Developer Tools/Mapper Extensions下
9. 这样自定义的FunctoId就可以测试了。