Aracılığıyla paylaş


Yükseltme ve bir özel görev olayları tanımlama

The Integration Services run-saat engine provides a koleksiyon of events that provide status on the progress of a task as the task is validated and executed. The IDTSComponentEvents arabirim defines these events, and is provided to tasks as a parameter to the Validate(Connections, Variables, IDTSEvents, IDTSLogging) and Execute(Connections, Variables, IDTSEvents, IDTSLogging, Object) methods.

Başka yok küme tanımlanmış olan olayların IDTSEvents Göreve göre adına geçirilen arabirim, 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.

Özel olaylar oluşturma

Özel görev geliştiricilerin yeni, yeni bir oluşturarak, özel olaylar tanımlayabilirsiniz EventInfo geçersiz kılınmış kendi uygulamasında InitializeTask(Connections, VariableDispenser, IDTSInfoEvents, IDTSLogging, EventInfos, LogEntryInfos, ObjectReferenceTracker) yöntem. Sonra EventInfo ise, oluşturulan eklenir EventInfos kullanarak koleksiyon Add(String, String, Boolean, array<String[], array<TypeCode[], array<String[]) yöntem. Yöntem imzası Add(String, String, Boolean, array<String[], array<TypeCode[], array<String[]) Yöntem aşağıdaki gibidir:

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

Aşağıdaki örnek gösterir kod InitializeTask özel bir görev, iki özel olaylar oluşturulduğu yöntem ve bunların özelliklerini ayarlayın. Yeni olaylar sonra eklenen EventInfos koleksiyon.

Ilk özel olay sahip bir eventName"OnBeforeIncrement" and description"Ilk değer güncelleştirildikten sonra harekete geçirilir. "Sonraki parametrenin, true değer, bu olay olay işlemek için oluşturulacak olay işleyicisinin kapsayıcı izin gösterir. Olay işleyicisi bir paketini ve hizmet paket, sıra, ForLoop ve ForEachLoop gibi diğer kapsayıcıları gibi görevler için yapı sağlayan kapsayıcı.Zaman allowEventHandlers parametre true, DtsEventHandler nesneler için olayı oluşturulur. Olay için tanımlamış herhangi bir parametre şimdi kullanılabilir DtsEventHandler değişkenleri koleksiyonunda 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

Özel olaylar'ı yükseltme

Özel olaylar çaðýrarak geçirilen FireCustomEvent(String, String, array<Object[]%, String, Boolean%) yöntem. Aşağıdaki kod satırını, özel bir olay oluşturur.

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

Örnek

Aşağıdaki örnek, özel bir olayı tanımlayan bir görev gösterir InitializeTask yöntem için özel bir olay ekler EventInfos koleksiyon ve sonra da özel bir olay sırasında harekete geçiren, Execute arayarak yöntemi FireCustomEvent(String, String, array<Object[]%, String, Boolean%) yöntem.

[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 icon (small) Tümleştirme Hizmetleri ile güncel kalın

Karşıdan yüklemeler, makaleleri, örnekler ve en son Microsoft video yanı sıra, seçili topluluğun çözümleri için ziyaret Integration Services sayfa MSDN veya TechNet:

Bu güncelleştirmelerin otomatik bildirim için kullanılabilir RSS akışlarına abone olmak sayfa.