Integration Services 런타임 엔진은 태스크의 유효성을 검사하고 실행할 때 작업의 진행 상태에 대한 상태를 제공하는 이벤트 컬렉션을 제공합니다. 인터페이스는 IDTSComponentEvents 이러한 이벤트를 정의하고 태스크에 해당 및 Validate 메서드에 Execute 대한 매개 변수로 제공됩니다.
인터페이스에 IDTSEvents 정의된 다른 이벤트 집합이 있습니다. 이 이벤트는 작업을 TaskHost대신하여 발생합니다. 유효성 TaskHost 검사 및 실행 전후에 발생하는 이벤트를 발생시키는 반면 태스크는 실행 및 유효성 검사 중에 발생하는 이벤트를 발생합니다.
사용자 지정 이벤트 만들기
사용자 지정 태스크 개발자는 메서드의 재정의 EventInfo 된 구현에서 새 InitializeTask 이벤트를 만들어 새 사용자 지정 이벤트를 정의할 수 있습니다. 만들어진 EventInfo는 EventInfos 메서드를 사용하여 Add 컬렉션에 추가합니다. 메서드의 Add 메서드 서명은 다음과 같습니다.
public void Add(string eventName, string description, bool allowEventHandlers, string[] parameterNames, TypeCode[] parameterTypes, string[] parameterDescriptions);
다음 코드 샘플에서는 두 개의 사용자 지정 이벤트가 만들어지고 해당 속성이 설정된 사용자 지정 작업의 메서드를 보여 InitializeTask 줍니다. 그런 다음 새 이벤트를 EventInfos 컬렉션에 추가합니다.
첫 번째 사용자 지정 이벤트에는 "OnBeforeIncrement"의 eventName과 "초기 값이 업데이트된 후 발생"에 대한 설명이 있습니다. 다음 매개 변수 값 true 은 이 이벤트가 이벤트를 처리하기 위해 이벤트 처리기 컨테이너를 만들 수 있도록 허용해야 임을 나타냅니다. 이벤트 처리기는 패키지, 시퀀스, ForLoop, ForEachLoop 등의 다른 컨테이너와 같이 태스크에 패키지의 구조와 서비스를 제공하는 컨테이너입니다.
allowEventHandlers 매개 변수가 있으면 trueDtsEventHandler 이벤트에 대한 개체가 만들어집니다. 이제 이벤트에 대해 정의된 모든 매개 변수를 변수 컬렉션DtsEventHandler에서 사용할 수 있습니다DtsEventHandler.
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 it is incremented.";
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 it has been incremented.";
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)
Dim paramNames(0) As String
Dim paramTypes(0) As TypeCode = {TypeCode.Int32}
Dim paramDescriptions(0) As String
Me.eventInfos = eventInfos
paramNames(0) = "InitialValue"
paramDescriptions(0) = "The value before it is incremented."
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 it has been incremented."
Me.eventInfos.Add("OnAfterIncrement", _
"Fires after the initial value is updated.", True, _
paramNames, paramTypes, paramDescriptions)
Me.onAfterIncrement = Me.eventInfos("OnAfterIncrement")
End Sub
사용자 지정 이벤트 발생
사용자 지정 이벤트는 메서드를 호출하여 발생합니다 FireCustomEvent . 다음 코드 줄은 사용자 지정 이벤트를 발생시킵니다.
componentEvents.FireCustomEvent(this.onBeforeIncrement.Name,
this.onBeforeIncrement.Description, ref arguments,
null, ref bFireOnBeforeIncrement);
componentEvents.FireCustomEvent(Me.onBeforeIncrement.Name, _
Me.onBeforeIncrement.Description, arguments, _
Nothing, bFireOnBeforeIncrement)
예시
다음 예제에서는 메서드에서 사용자 지정 이벤트를 정의하고 컬렉션에 InitializeTask 사용자 지정 이벤트를 EventInfos 추가한 다음 메서드를 호출 Execute 하여 메서드 FireCustomEvent 중에 사용자 지정 이벤트를 발생시키는 작업을 보여 줍니다.
[DtsTask(DisplayName = "CustomEventTask")]
public class CustomEventTask : Task
{
public override DTSExecResult Execute(Connections connections,
VariableDispenser variableDispenser, IDTSComponentEvents componentEvents,
IDTSLogging log, object transaction)
{
bool fireAgain;
object[] args = new object[1] { "The value of the parameter." };
componentEvents.FireCustomEvent( "MyCustomEvent",
"Firing the custom event.", ref args,
"CustomEventTask" , ref fireAgain );
return DTSExecResult.Success;
}
public override void InitializeTask(Connections connections,
VariableDispenser variableDispenser, IDTSInfoEvents events,
IDTSLogging log, EventInfos eventInfos,
LogEntryInfos logEntryInfos, ObjectReferenceTracker refTracker)
{
string[] names = new string[1] {"Parameter1"};
TypeCode[] types = new TypeCode[1] {TypeCode.String};
string[] descriptions = new string[1] {"Parameter description." };
eventInfos.Add("MyCustomEvent",
"Fires when my interesting event happens.",
true, names, types, descriptions);
}
}
<DtsTask(DisplayName = "CustomEventTask")> _
Public Class CustomEventTask
Inherits Task
Public Overrides Function Execute(ByVal connections As Connections, _
ByVal variableDispenser As VariableDispenser, _
ByVal componentEvents As IDTSComponentEvents, _
ByVal log As IDTSLogging, ByVal transaction As Object) _
As DTSExecResult
Dim fireAgain As Boolean
Dim args() As Object = New Object(1) {"The value of the parameter."}
componentEvents.FireCustomEvent("MyCustomEvent", _
"Firing the custom event.", args, _
"CustomEventTask" , fireAgain)
Return DTSExecResult.Success
End Function
Public Overrides Sub InitializeTask(ByVal connections As Connections, _
ByVal variableDispenser As VariableDispenser,
ByVal events As IDTSInfoEvents,
ByVal log As IDTSLogging, ByVal eventInfos As EventInfos, ByVal logEnTryInfos As LogEnTryInfos, ByVal refTracker As ObjectReferenceTracker)
Dim names() As String = New String(1) {"Parameter1"}
Dim types() As TypeCode = New TypeCode(1) {TypeCode.String}
Dim descriptions() As String = New String(1) {"Parameter description."}
eventInfos.Add("MyCustomEvent", _
"Fires when my interesting event happens.", _
True, names, types, descriptions)
End Sub
End Class
Integration Services를 사용하여 최신 상태 유지
Microsoft의 최신 다운로드, 문서, 샘플 및 비디오와 커뮤니티에서 선택한 솔루션은 MSDN의 Integration Services 페이지를 방문하세요.
MSDN의 Integration Services 페이지 방문
이러한 업데이트에 대한 자동 알림을 보려면 페이지에서 사용할 수 있는 RSS 피드를 구독합니다.