Task.InitializeTask 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化与该任务相关联的属性。 此方法由运行时调用,在代码中未使用。
public:
virtual void InitializeTask(Microsoft::SqlServer::Dts::Runtime::Connections ^ connections, Microsoft::SqlServer::Dts::Runtime::VariableDispenser ^ variableDispenser, Microsoft::SqlServer::Dts::Runtime::IDTSInfoEvents ^ events, Microsoft::SqlServer::Dts::Runtime::IDTSLogging ^ log, Microsoft::SqlServer::Dts::Runtime::EventInfos ^ eventInfos, Microsoft::SqlServer::Dts::Runtime::LogEntryInfos ^ logEntryInfos, Microsoft::SqlServer::Dts::Runtime::ObjectReferenceTracker ^ refTracker);
public virtual void InitializeTask (Microsoft.SqlServer.Dts.Runtime.Connections connections, Microsoft.SqlServer.Dts.Runtime.VariableDispenser variableDispenser, Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents events, Microsoft.SqlServer.Dts.Runtime.IDTSLogging log, Microsoft.SqlServer.Dts.Runtime.EventInfos eventInfos, Microsoft.SqlServer.Dts.Runtime.LogEntryInfos logEntryInfos, Microsoft.SqlServer.Dts.Runtime.ObjectReferenceTracker refTracker);
abstract member InitializeTask : Microsoft.SqlServer.Dts.Runtime.Connections * Microsoft.SqlServer.Dts.Runtime.VariableDispenser * Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents * Microsoft.SqlServer.Dts.Runtime.IDTSLogging * Microsoft.SqlServer.Dts.Runtime.EventInfos * Microsoft.SqlServer.Dts.Runtime.LogEntryInfos * Microsoft.SqlServer.Dts.Runtime.ObjectReferenceTracker -> unit
override this.InitializeTask : Microsoft.SqlServer.Dts.Runtime.Connections * Microsoft.SqlServer.Dts.Runtime.VariableDispenser * Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents * Microsoft.SqlServer.Dts.Runtime.IDTSLogging * Microsoft.SqlServer.Dts.Runtime.EventInfos * Microsoft.SqlServer.Dts.Runtime.LogEntryInfos * Microsoft.SqlServer.Dts.Runtime.ObjectReferenceTracker -> unit
Public Overridable Sub InitializeTask (connections As Connections, variableDispenser As VariableDispenser, events As IDTSInfoEvents, log As IDTSLogging, eventInfos As EventInfos, logEntryInfos As LogEntryInfos, refTracker As ObjectReferenceTracker)
参数
- connections
- Connections
任务使用的连接的集合。
- variableDispenser
- VariableDispenser
一个用来锁定变量的 VariableDispenser 对象。
- events
- IDTSInfoEvents
一个实现 IDTSInfoEvents 接口的对象。
- log
- IDTSLogging
一个实现 IDTSLogging 接口的对象。
- eventInfos
- EventInfos
一个包含要在任务执行期间引发的事件的集合。
- logEntryInfos
- LogEntryInfos
日志项的集合。
- refTracker
- ObjectReferenceTracker
一个对象引用跟踪器。
示例
任务开发人员通过重写 InitializeTask 基类的方法 Task 并创建新的自定义事件来定义自定义 EventInfo事件。 下面的代码示例显示了自定义任务的 InitializeTask 方法,其中创建了两个自定义事件,并将其添加到 eventInfos 集合。
public override void InitializeTask(Connections connections, VariableDispenser variables, IDTSInfoEvents events, IDTSLogging log, EventInfos eventInfos, LogEntryInfos logEntryInfos, ObjectReferenceTracker refTracker)
{
this.eventInfos = eventInfos;
string[] paramNames = new string[1];
TypeCode[] paramTypes = new TypeCode[1]{TypeCode.Int32};
string[] paramDescriptions = new string[1];
paramNames[0] = "InitialValue";
paramDescriptions[0] = "The value before increment.";
this.eventInfos.Add("OnBeforeIncrement","Fires before the task increments the value.",true,paramNames,paramTypes,paramDescriptions);
this.onBeforeIncrement = this.eventInfos["OnBeforeIncrement"];
paramDescriptions[0] = "The value after increment.";
this.eventInfos.Add("OnAfterIncrement","Fires after the initial value is updated.",true,paramNames, paramTypes,paramDescriptions);
this.onAfterIncrement = this.eventInfos["OnAfterIncrement"];
}
Public Overrides Sub InitializeTask(ByVal connections As Connections, ByVal variables As VariableDispenser, ByVal events As IDTSInfoEvents, ByVal log As IDTSLogging, ByVal eventInfos As EventInfos, ByVal logEntryInfos As LogEntryInfos, ByVal refTracker As ObjectReferenceTracker)
Me.eventInfos = eventInfos
Dim paramNames(0) As String
Dim paramTypes(0) As TypeCode = {TypeCode.Int32}
Dim paramDescriptions(0) As String
paramNames(0) = "InitialValue"
paramDescriptions(0) = "The value before increment."
Me.eventInfos.Add("OnBeforeIncrement", "Fires before the task increments the value.", True, paramNames, paramTypes, paramDescriptions)
Me.onBeforeIncrement = Me.eventInfos("OnBeforeIncrement")
paramDescriptions(0) = "The value after increment."
Me.eventInfos.Add("OnAfterIncrement", "Fires after the initial value is updated.", True, paramNames, paramTypes, paramDescriptions)
Me.onAfterIncrement = Me.eventInfos("OnAfterIncrement")
End Sub
注解
对于库存任务,此方法用于设置每个任务的日志事件。
在创建任务后立即调用 InitializeTask 运行时引擎 -- 验证、执行或持久性操作之前。