사용자 지정 태스크에서 이벤트 발생 및 정의Raising and Defining Events in a Custom Task

Integration ServicesIntegration Services 런타임 엔진에서는 태스크의 유효성 검사 및 실행 시 태스크의 진행 상태에 대한 정보를 제공하는 이벤트의 컬렉션을 제공합니다.The Integration ServicesIntegration Services run-time engine provides a collection of events that provide status on the progress of a task as the task is validated and executed. IDTSComponentEvents 인터페이스는 이러한 이벤트를 정의하며 ValidateExecute 메서드에 대한 매개 변수로 태스크에 제공됩니다.The IDTSComponentEvents interface defines these events, and is provided to tasks as a parameter to the Validate and Execute methods.

IDTSEvents 인터페이스에 정의되며 태스크 대신 TaskHost에서 발생시키는 다른 이벤트 집합도 있습니다.There is another set of events, which are defined in the IDTSEvents interface, that are raised on behalf of the task by the TaskHost. TaskHost에서는 유효성 검사 및 실행 전후에 이벤트를 발생시키는 반면 태스크에서는 실행 및 유효성 검사 도중에 이벤트를 발생시킵니다.The TaskHost raises events that occur before and after validation and execution, whereas the task raises the events that occur during execution and validation.

사용자 지정 이벤트 만들기Creating Custom Events

사용자 지정 태스크 개발자는 EventInfo 메서드의 재정의된 구현에서 새 InitializeTask를 만들어 새 사용자 지정 이벤트를 정의할 수 있습니다.Custom task developers can define new, custom events by creating a new EventInfo in their overridden implementation of the InitializeTask method. 후는 EventInfo 은에 추가 됩니다 만들어지면는 EventInfos 사용 하 여 컬렉션에서 Add 메서드.After the EventInfo is created, it is added to the EventInfos collection by using the Add method. Add 메서드의 서명은 다음과 같습니다.The method signature of the Add method is as follows:

public void Add(string eventName, string description, bool allowEventHandlers, string[] parameterNames, TypeCode[] parameterTypes, string[] parameterDescriptions);

다음 코드 샘플에서는 두 개의 사용자 지정 이벤트를 만들고 해당 속성을 설정하는 사용자 지정 태스크의 InitializeTask 메서드를 보여 줍니다.The following code sample shows the InitializeTask method of a custom task, where two custom events are created and their properties are set. 그런 다음 새 이벤트를 EventInfos 컬렉션에 추가합니다.The new events are then added to the EventInfos collection.

첫 번째 사용자 지정 이벤트에는 "OnBeforeIncrement"라는 eventName과 "Fires after the initial value is updated."라는 description이 있습니다.The first custom event has an eventName of "OnBeforeIncrement" and description of "Fires after the initial value is updated." 다음 매개 변수인 true 값은 이 이벤트에서 이벤트를 처리하기 위해 이벤트 처리기 컨테이너를 만들 수 있도록 허용해야 함을 나타냅니다.The next parameter, the true value, indicates that this event should allow an event handler container to be created to handle the event. 이벤트 처리기는 패키지, 시퀀스, ForLoop, ForEachLoop 등의 다른 컨테이너와 같이 태스크에 패키지의 구조와 서비스를 제공하는 컨테이너입니다.The event handler is a container that provides structure in a package and services to tasks, like other containers such as the package, Sequence, ForLoop, and ForEachLoop. 경우는 allowEventHandlers 매개 변수는 true, DtsEventHandler 이벤트에 대해 개체가 만들어집니다.When the allowEventHandlers parameter is true, DtsEventHandler objects are created for the event. 그러면 해당 이벤트에 대해 정의된 모든 매개 변수를 DtsEventHandler의 변수 컬렉션에 있는 DtsEventHandler에서 사용할 수 있습니다.Any parameters that were defined for the event are now available to the DtsEventHandler in the variables collection of the 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  

사용자 지정 이벤트 발생Raising Custom Events

사용자 지정 이벤트는 FireCustomEvent 메서드를 호출하면 발생합니다.Custom events are raised by calling the FireCustomEvent method. 다음 코드 줄은 사용자 지정 이벤트를 발생시킵니다.The following line of code raises a custom event.

componentEvents.FireCustomEvent(this.onBeforeIncrement.Name,  
   this.onBeforeIncrement.Description, ref arguments,  
   null, ref bFireOnBeforeIncrement);  
componentEvents.FireCustomEvent(Me.onBeforeIncrement.Name, _  
Me.onBeforeIncrement.Description, arguments, _  
Nothing,  bFireOnBeforeIncrement)  

예제Sample

다음 예제에서 사용자 지정 이벤트를 정의 하는 작업을 보여 줍니다.는 InitializeTask 사용자 지정 이벤트를 추가 하는 메서드를는 EventInfos 컬렉션 중 사용자 지정 이벤트를 발생 시킵니다. 해당 Execute 메서드를 호출 하 여는 FireCustomEvent 메서드.The following example shows a task that defines a custom event in the InitializeTask method, adds the custom event to the EventInfos collection, and then raises the custom event during its Execute method by calling the FireCustomEvent method.

[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  

참고 항목See Also

Integration Services ( Ssis) 이벤트 처리기 Integration Services (SSIS) Event Handlers
패키지에 이벤트 처리기를 추가 합니다.Add an Event Handler to a Package