[ComRegisterFunction]
static void RegisterServer(Type t)
{
// 1. COM 分類登錄
// 2. DTS 任務快取登錄
// 3. 任務描述寫入
}
[ComUnregisterFunction]
static void UnregisterServer(Type t)
{
// 從 DTS 快取移除:HKEY_CURRENT_USER\...\Tasks\{GUID}
}
所有 DTS 自訂任務必須實作 CustomTask 介面:
Name / Description 屬性Properties 集合Execute 方法[assembly: ClassInterface(ClassInterfaceType.AutoDual)]
namespace DTS
{
[Guid("38ED4F80-9EF4-4752-8478-65D2DB3BA7DD"), ComVisible(true)]
[ProgId("DTS.SimpleCustomTask")]
public class SimpleCustomTask : CustomTask
{
private string name;
private string description;
public SimpleCustomTask()
{
name = "";
description = "SimpleCustomTask description";
}
public void Execute(object pPackage, object pPackageEvents,
object pPackageLog, ref DTSTaskExecResult pTaskResult)
{
pTaskResult = DTSTaskExecResult.DTSTaskExecResult_Failure;
try
{
Package2 pkg = (Package2)pPackage;
PackageEvents pkgEvents = (PackageEvents)pPackageEvents;
PackageLog pkgLog = (PackageLog)pPackageLog;
MessageBox.Show(description); // 示範功能
pTaskResult = DTSTaskExecResult.DTSTaskExecResult_Success;
}
catch (COMException e) { Console.WriteLine(e); }
catch (Exception e) { Console.WriteLine(e); }
}
public string Description { get { return description; } set { description = value; } }
public string Name { get { return name; } set { name = value; } }
public Properties Properties { get { return null; } }
[ComVisible(false)]
public override string ToString() { return base.ToString(); }
// RegisterServer / UnregisterServer 完整實作見原文
}
}
dtspkg.dll 的 RCW (Runtime Callable Wrapper):tlbimp.exe dtspkg.dll /out:Microsoft.SQLServer.DTSPkg80.dll /keyfile:DTSPkg.snksn.exe -k DTSPkg.snkgacutil.exe /i Microsoft.SQLServer.DTSPkg80.dllCustomTaskUI 介面提供自訂設計介面