Udostępnij za pośrednictwem


Klasa BusinessLogicModule

Implementuje logika biznesowa niestandardowy, który jest wywoływany podczas procesu synchronizacji replikacja scalająca.

Hierarchia dziedziczenia

System.Object
  Microsoft.SqlServer.Replication.BusinessLogicSupport.BusinessLogicModule

Przestrzeń nazw:  Microsoft.SqlServer.Replication.BusinessLogicSupport
Zestaw:  Microsoft.SqlServer.Replication.BusinessLogicSupport (w Microsoft.SqlServer.Replication.BusinessLogicSupport.dll)

Składnia

'Deklaracja
Public MustInherit Class BusinessLogicModule
'Użycie
Dim instance As BusinessLogicModule
public abstract class BusinessLogicModule
public ref class BusinessLogicModule abstract
[<AbstractClassAttribute>]
type BusinessLogicModule =  class end
public abstract class BusinessLogicModule

Typ BusinessLogicModule uwidacznia następujące elementy członkowskie.

Konstruktorzy

  Nazwa Opis
Metoda chroniona BusinessLogicModule Konstruktor.

Do góry

Właściwości

  Nazwa Opis
Właściwość publiczna HandledChangeStates Wymagana właściwość, która zwraca informacje o typy zmian, obsługiwane przez moduł logika biznesowa.

Do góry

Metody

  Nazwa Opis
Metoda publiczna CommitHandler Opcjonalne metoda implementuje niestandardowe logika biznesowa, która jest wywoływana, gdy zmiana danych jest zobowiązana podczas synchronizacji.
Metoda publiczna DeleteErrorHandler Opcjonalne metoda, która implementuje niestandardowe logika biznesowa wywoływana, gdy wystąpi błąd w czas jest Instrukcja DELETE przekazywania lub pobierania.
Metoda publiczna DeleteHandler Opcjonalne metoda, która implementuje niestandardowe logika biznesowa wywoływana, gdy instrukcji DELETE są przekazywane lub pobrane.
Metoda publiczna Dispose Usuwa wszystkie zasoby używane.Ta metoda jest wywoływana po wykonaniu wszystkie niestandardowe logika biznesowa.
Metoda publiczna Equals (Dziedziczony z Object).
Metoda chroniona Finalize (Dziedziczony z Object).
Metoda publiczna GetHashCode (Dziedziczony z Object).
Metoda publiczna GetType (Dziedziczony z Object).
Metoda publiczna Initialize Wysyła informacje o artykuł synchronizowane logika biznesowa program rozpoznawania nazw podczas uruchamiania agenta scalania.
Metoda publiczna InsertErrorHandler Opcjonalne metoda implementuje niestandardowe logika biznesowa wywoływana, gdy wystąpi błąd w czas jest instrukcja INSERT przekazywania lub pobierania.
Metoda publiczna InsertHandler Opcjonalne metoda, która implementuje niestandardowe logika biznesowa wywoływana, gdy są instrukcji INSERT przekazywania lub pobierania.
Metoda chroniona MemberwiseClone (Dziedziczony z Object).
Metoda publiczna PhaseBegin Opcjonalne metoda wskazuje początek przekazywania lub pobierania fazie synchronizacji.
Metoda publiczna ToString (Dziedziczony z Object).
Metoda publiczna UpdateConflictsHandler Opcjonalne metodę, która implementuje niestandardowe logika biznesowa wywoływana, gdy występują konflikty instrukcji UPDATE w Wydawca i przez subskrybenta.
Metoda publiczna UpdateDeleteConflictHandler Opcjonalne metodę, która implementuje niestandardowe logika biznesowa wywoływana, gdy instrukcji UPDATE konflikt z instrukcji DELETE na Wydawca i przez subskrybenta.
Metoda publiczna UpdateErrorHandler Opcjonalne metoda, która implementuje niestandardowe logika biznesowa wywoływana, gdy wystąpi błąd w czas jest instrukcja UPDATE przekazywania lub pobierania.
Metoda publiczna UpdateHandler Opcjonalne metoda, która implementuje niestandardowe logika biznesowa wywoływana, gdy instrukcji UPDATE są przekazywane lub pobrać.

Do góry

Uwagi

Implementacja muszą zostać dostarczone tylko dla określonych metod, które zawierają niestandardową logikę.Jeśli nie podano wykonania przez użytkownika, zostanie wykonana akcja domyślna.

Przykłady

using System;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.SqlServer.Replication.BusinessLogicSupport;
using Microsoft.Samples.SqlServer.BusinessLogicHandler;

namespace Microsoft.Samples.SqlServer.BusinessLogicHandler
{
    public class OrderEntryBusinessLogicHandler :
      Microsoft.SqlServer.Replication.BusinessLogicSupport.BusinessLogicModule
    {
        // Variables to hold server names.
        private string publisherName;
        private string subscriberName;

        public OrderEntryBusinessLogicHandler()
        {
        }

        // Implement the Initialize method to get publication 
        // and subscription information.
        public override void Initialize(
            string publisher,
            string subscriber,
            string distributor,
            string publisherDB,
            string subscriberDB,
            string articleName)
        {
            // Set the Publisher and Subscriber names.
            publisherName = publisher;
            subscriberName = subscriber;
        }

        // Declare what types of row changes, conflicts, or errors to handle.
        override public ChangeStates HandledChangeStates
        {
            get
            {
                // Handle Subscriber inserts, updates and deletes.
                return ChangeStates.SubscriberInserts |
                  ChangeStates.SubscriberUpdates | ChangeStates.SubscriberDeletes;
            }
        }

        public override ActionOnDataChange InsertHandler(SourceIdentifier insertSource,
          DataSet insertedDataSet, ref DataSet customDataSet, ref int historyLogLevel,
          ref string historyLogMessage)
        {
            if (insertSource == SourceIdentifier.SourceIsSubscriber)
            {
                // Build a line item in the audit message to log the Subscriber insert.
                StringBuilder AuditMessage = new StringBuilder();
                AuditMessage.Append(String.Format("A new order was entered at {0}. " +
                  "The SalesOrderID for the order is :", subscriberName));
                AuditMessage.Append(insertedDataSet.Tables[0].Rows[0]["SalesOrderID"].ToString());
                AuditMessage.Append("The order must be shipped by :");
                AuditMessage.Append(insertedDataSet.Tables[0].Rows[0]["DueDate"].ToString());

                // Set the reference parameter to write the line to the log file.
                historyLogMessage = AuditMessage.ToString();
                
                // Set the history log level to the default verbose level.
                historyLogLevel = 1;

                // Accept the inserted data in the Subscriber's data set and 
                // apply it to the Publisher.
                return ActionOnDataChange.AcceptData;
            }
            else
            {
                return base.InsertHandler(insertSource, insertedDataSet, ref customDataSet,
                  ref historyLogLevel, ref historyLogMessage);
            }
        }

        public override ActionOnDataChange UpdateHandler(SourceIdentifier updateSource,
          DataSet updatedDataSet, ref DataSet customDataSet, ref int historyLogLevel,
          ref string historyLogMessage)
        {
            if (updateSource == SourceIdentifier.SourceIsPublisher)
            {
                // Build a line item in the audit message to log the Subscriber update.
                StringBuilder AuditMessage = new StringBuilder();
                AuditMessage.Append(String.Format("An existing order was updated at {0}. " +
                  "The SalesOrderID for the order is ", subscriberName));
                AuditMessage.Append(updatedDataSet.Tables[0].Rows[0]["SalesOrderID"].ToString());
                AuditMessage.Append("The order must now be shipped by :");
                AuditMessage.Append(updatedDataSet.Tables[0].Rows[0]["DueDate"].ToString());

                // Set the reference parameter to write the line to the log file.
                historyLogMessage = AuditMessage.ToString();
                // Set the history log level to the default verbose level.
                historyLogLevel = 1;

                // Accept the updated data in the Subscriber's data set and apply it to the Publisher.
                return ActionOnDataChange.AcceptData;
            }
            else
            {
                return base.UpdateHandler(updateSource, updatedDataSet,
                  ref customDataSet, ref historyLogLevel, ref historyLogMessage);
            }
        }

        public override ActionOnDataDelete DeleteHandler(SourceIdentifier deleteSource,
          DataSet deletedDataSet, ref int historyLogLevel, ref string historyLogMessage)
        {
            if (deleteSource == SourceIdentifier.SourceIsSubscriber)
            {
                // Build a line item in the audit message to log the Subscriber deletes.
                // Note that the rowguid is the only information that is 
                // available in the dataset.
                StringBuilder AuditMessage = new StringBuilder();
                AuditMessage.Append(String.Format("An existing order was deleted at {0}. " +
                  "The rowguid for the order is ", subscriberName));
                AuditMessage.Append(deletedDataSet.Tables[0].Rows[0]["rowguid"].ToString());

                // Set the reference parameter to write the line to the log file.
                historyLogMessage = AuditMessage.ToString();
                // Set the history log level to the default verbose level.
                historyLogLevel = 1;

                // Accept the delete and apply it to the Publisher.
                return ActionOnDataDelete.AcceptDelete;
            }
            else
            {
                return base.DeleteHandler(deleteSource, deletedDataSet,
                  ref historyLogLevel, ref historyLogMessage);
            }
        }
    }
}
Imports System
Imports System.Text
Imports System.Data
Imports System.Data.Common
Imports Microsoft.SqlServer.Replication.BusinessLogicSupport

Namespace Microsoft.Samples.SqlServer.BusinessLogicHandler
    Public Class OrderEntryBusinessLogicHandler
        Inherits BusinessLogicModule

        ' Variables to hold server names.
        Private publisherName As String
        Private subscriberName As String

        ' Implement the Initialize method to get publication 
        ' and subscription information.
        Public Overrides Sub Initialize( _
        ByVal publisher As String, _
        ByVal subscriber As String, _
        ByVal distributor As String, _
        ByVal publisherDB As String, _
        ByVal subscriberDB As String, _
        ByVal articleName As String _
      )
            ' Set the Publisher and Subscriber names.
            publisherName = publisher
            subscriberName = subscriber
        End Sub

        ' Declare what types of row changes, conflicts, or errors to handle.
        Public Overrides ReadOnly Property HandledChangeStates() As ChangeStates
            Get
                ' Handle Subscriber inserts, updates and deletes.
                Return (ChangeStates.SubscriberInserts Or _
                 ChangeStates.SubscriberUpdates Or ChangeStates.SubscriberDeletes)
            End Get
        End Property

        Public Overrides Function InsertHandler(ByVal insertSource As SourceIdentifier, _
        ByVal insertedDataSet As DataSet, ByRef customDataSet As DataSet, _
        ByRef historyLogLevel As Integer, ByRef historyLogMessage As String) _
        As ActionOnDataChange

            If insertSource = SourceIdentifier.SourceIsSubscriber Then
                ' Build a line item in the audit message to log the Subscriber insert.
                Dim AuditMessage As StringBuilder = New StringBuilder()
                AuditMessage.Append(String.Format("A new order was entered at {0}. " + _
                 "The SalesOrderID for the order is :", subscriberName))
                AuditMessage.Append(insertedDataSet.Tables(0).Rows(0)("SalesOrderID").ToString())
                AuditMessage.Append("The order must be shipped by :")
                AuditMessage.Append(insertedDataSet.Tables(0).Rows(0)("DueDate").ToString())

                ' Set the reference parameter to write the line to the log file.
                historyLogMessage = AuditMessage.ToString()

                ' Set the history log level to the default verbose level.
                historyLogLevel = 1

                ' Accept the inserted data in the Subscriber's data set and 
                ' apply it to the Publisher.
                Return ActionOnDataChange.AcceptData
            Else
                Return MyBase.InsertHandler(insertSource, insertedDataSet, customDataSet, _
                 historyLogLevel, historyLogMessage)
            End If
        End Function
        Public Overrides Function UpdateHandler(ByVal updateSource As SourceIdentifier, _
        ByVal updatedDataSet As DataSet, ByRef customDataSet As DataSet, _
        ByRef historyLogLevel As Integer, ByRef historyLogMessage As String) _
        As ActionOnDataChange

            If updateSource = SourceIdentifier.SourceIsPublisher Then
                ' Build a line item in the audit message to log the Subscriber update.
                Dim AuditMessage As StringBuilder = New StringBuilder()
                AuditMessage.Append(String.Format("An existing order was updated at {0}. " + _
                 "The SalesOrderID for the order is ", subscriberName))
                AuditMessage.Append(updatedDataSet.Tables(0).Rows(0)("SalesOrderID").ToString())
                AuditMessage.Append("The order must now be shipped by :")
                AuditMessage.Append(updatedDataSet.Tables(0).Rows(0)("DueDate").ToString())

                ' Set the reference parameter to write the line to the log file.
                historyLogMessage = AuditMessage.ToString()
                ' Set the history log level to the default verbose level.
                historyLogLevel = 1

                ' Accept the updated data in the Subscriber's data set and apply it to the Publisher.
                Return ActionOnDataChange.AcceptData
            Else
                Return MyBase.UpdateHandler(updateSource, updatedDataSet, _
                 customDataSet, historyLogLevel, historyLogMessage)
            End If
        End Function
        Public Overrides Function DeleteHandler(ByVal deleteSource As SourceIdentifier, _
        ByVal deletedDataSet As DataSet, ByRef historyLogLevel As Integer, _
         ByRef historyLogMessage As String) As ActionOnDataDelete
            If deleteSource = SourceIdentifier.SourceIsSubscriber Then
                ' Build a line item in the audit message to log the Subscriber deletes.
                ' Note that the rowguid is the only information that is 
                ' available in the dataset.
                Dim AuditMessage As StringBuilder = New StringBuilder()
                AuditMessage.Append(String.Format("An existing order was deleted at {0}. " + _
                 "The rowguid for the order is ", subscriberName))
                AuditMessage.Append(deletedDataSet.Tables(0).Rows(0)("rowguid").ToString())

                ' Set the reference parameter to write the line to the log file.
                historyLogMessage = AuditMessage.ToString()
                ' Set the history log level to the default verbose level.
                historyLogLevel = 1

                ' Accept the delete and apply it to the Publisher.
                Return ActionOnDataDelete.AcceptDelete
            Else
                Return MyBase.DeleteHandler(deleteSource, deletedDataSet, _
                 historyLogLevel, historyLogMessage)
            End If
        End Function
    End Class
End Namespace

Bezpieczeństwo wątków

Wszystkie publiczne statyczny (Shared w języku Visual Basic) elementy członkowskie tego typu są bezpieczne dla wątków. Nie ma gwarancji, że elementy członkowskie wystąpień będą bezpieczne dla wątków.