Notatka
Dostęp do tej strony wymaga autoryzacji. Może spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Dotyczy:SQL Server
Środowisko SSIS Integration Runtime w usłudze Azure Data Factory
Silnik wykonawczy Integration Services zapewnia zbiór zdarzeń, które dostarczają status postępu zadania w trakcie walidacji i wykonywania zadania. Interfejs definiuje IDTSComponentEvents te zdarzenia i jest udostępniany zadaniom jako parametr do Validate metod i Execute
Istnieje inny zestaw zdarzeń, które są definiowane w interfejsie IDTSEvents i są wywoływane w imieniu zadania przez .TaskHost Podnosi zdarzenia TaskHost występujące przed i po walidacji i wykonaniu, natomiast zadanie podnosi zdarzenia zachodzące podczas wykonywania i walidacji.
Tworzenie niestandardowych zdarzeń
Twórcy zadań niestandardowych mogą definiować nowe, niestandardowe zdarzenia, tworząc nowe EventInfo w swojej nadpisanej implementacji InitializeTask metody. Po utworzeniu jest EventInfo dodawany do kolekcji EventInfos za pomocą tej metody Add . Sygnatura Add metody jest następująca:
public void Add(string eventName, string description, bool allowEventHandlers, string[] parameterNames, TypeCode[] parameterTypes, string[] parameterDescriptions);
Poniższy przykład kodu pokazuje metodę InitializeTask dla zadania niestandardowego, w której tworzone są dwa niestandardowe zdarzenia i ustalane są ich właściwości. Nowe wydarzenia są następnie dodawane do kolekcji EventInfos .
Pierwsze niestandardowe zdarzenie ma nazwę zdarzenia "OnBeforeIncrement" oraz opis "Uruchamia się po aktualizacji wartości początkowej." Następny parametr, wartość prawdziwa , wskazuje, że to zdarzenie powinno pozwolić na utworzenie kontenera obsługi zdarzenia do obsługi tego zdarzenia. Obsługa zdarzeń to kontener, który zapewnia strukturę w pakiecie i usługach dla zadań, takich jak inne kontenery, takie jak package, Sequence, ForLoop i ForEachLoop. Gdy parametr allowEventHandlers jest prawdziwy, DtsEventHandler obiekty są tworzone dla zdarzenia. Wszelkie parametry zdefiniowane dla zdarzenia są teraz dostępne w DtsEventHandler zbiorze zmiennych .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
Wydarzenia dotyczące Wznoszenia Niestandardowych Wydarzeń
Niestandardowe zdarzenia są wywoływane przez wywołanie metody FireCustomEvent . Następny wiersz kodu generuje niestandardowe zdarzenie.
componentEvents.FireCustomEvent(this.onBeforeIncrement.Name,
this.onBeforeIncrement.Description, ref arguments,
null, ref bFireOnBeforeIncrement);
componentEvents.FireCustomEvent(Me.onBeforeIncrement.Name, _
Me.onBeforeIncrement.Description, arguments, _
Nothing, bFireOnBeforeIncrement)
Przykład
Poniższy przykład pokazuje zadanie, które definiuje niestandardowe zdarzenie w metodzie InitializeTask , dodaje to zdarzenie do kolekcji EventInfos , a następnie podnosi to zdarzenie podczas metody Execute poprzez wywołanie metody 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