BusinessLogicModule BusinessLogicModule BusinessLogicModule Class

정의

병합 복제 동기화 프로세스 중에 호출되는 사용자 지정 비즈니스 논리를 구현합니다. Implements the custom business logic that is invoked during the merge replication synchronization process.

public ref class BusinessLogicModule abstract
public abstract class BusinessLogicModule
Public MustInherit Class BusinessLogicModule
상속
BusinessLogicModuleBusinessLogicModuleBusinessLogicModule

예제

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

설명

구현을은 사용자 지정 논리를 포함 하는 특정 방법에 대해서만 제공 해야 합니다.An implementation needs to be provided only for the specific methods that contain the custom logic. 사용자 지정 구현을 제공 하지 않으면 기본 동작이 수행 됩니다.If a user-defined implementation is not provided, the default action will be performed.

생성자

BusinessLogicModule() BusinessLogicModule() BusinessLogicModule()

생성자입니다. Constructor.

속성

HandledChangeStates HandledChangeStates HandledChangeStates

비즈니스 논리 모듈에서 처리되는 변경 유형에 대한 정보를 반환하는 필수 속성입니다. Required property that returns information on the types of changes handled by the business logic module.

메서드

CommitHandler(SourceIdentifier, Guid) CommitHandler(SourceIdentifier, Guid) CommitHandler(SourceIdentifier, Guid)

동기화 중 데이터 변경 내용이 커밋될 때 호출되는 사용자 지정 비즈니스 논리를 구현하는 선택적 메서드입니다. Optional method implements the custom business logic that is invoked when a data change is committed during synchronization.

DeleteErrorHandler(SourceIdentifier, DataSet, ErrorLogType, String, Int32, String, Int32, String) DeleteErrorHandler(SourceIdentifier, DataSet, ErrorLogType, String, Int32, String, Int32, String) DeleteErrorHandler(SourceIdentifier, DataSet, ErrorLogType, String, Int32, String, Int32, String)

DELETE 문이 업로드되거나 다운로드되는 동안 오류가 발생할 때 호출되는 사용자 지정 비즈니스 논리를 구현하는 선택적 메서드입니다. Optional method that implements the custom business logic invoked when an error occurs at the time a DELETE statement is being uploaded or downloaded.

DeleteHandler(SourceIdentifier, DataSet, Int32, String) DeleteHandler(SourceIdentifier, DataSet, Int32, String) DeleteHandler(SourceIdentifier, DataSet, Int32, String)

DELETE 문이 업로드되거나 다운로드되는 동안 호출되는 사용자 지정 비즈니스 논리를 구현하는 선택적 메서드입니다. Optional method that implements the custom business logic invoked when DELETE statements are being uploaded or downloaded.

Dispose() Dispose() Dispose()

사용되는 모든 리소스를 삭제합니다. Disposes of all used resources. 이 메서드는 모든 사용자 지정 비즈니스 논리가 실행된 후 호출됩니다. This method is invoked after all the custom business logic has been executed.

Initialize(String, String, String, String, String, String) Initialize(String, String, String, String, String, String) Initialize(String, String, String, String, String, String)

병합 에이전트가 시작될 때 비즈니스 논리 해결 프로그램에 동기화 중인 아티클에 대한 정보를 보냅니다. Sends information about the article being synchronized to the business logic resolver when the Merge Agent is started.

InsertErrorHandler(SourceIdentifier, DataSet, ErrorLogType, String, Int32, String, Int32, String) InsertErrorHandler(SourceIdentifier, DataSet, ErrorLogType, String, Int32, String, Int32, String) InsertErrorHandler(SourceIdentifier, DataSet, ErrorLogType, String, Int32, String, Int32, String)

INSERT 문이 업로드되거나 다운로드되는 동안 오류가 발생할 때 호출되는 사용자 지정 비즈니스 논리를 구현하는 선택적 메서드입니다. Optional method implements the custom business logic invoked when an error occurs at the time an INSERT statement is being uploaded or downloaded.

InsertHandler(SourceIdentifier, DataSet, DataSet, Int32, String) InsertHandler(SourceIdentifier, DataSet, DataSet, Int32, String) InsertHandler(SourceIdentifier, DataSet, DataSet, Int32, String)

INSERT 문이 업로드되거나 다운로드되는 동안 호출되는 사용자 지정 비즈니스 논리를 구현하는 선택적 메서드입니다. Optional method that implements the custom business logic invoked when INSERT statements are being uploaded or downloaded.

PhaseBegin(Boolean) PhaseBegin(Boolean) PhaseBegin(Boolean)

동기화의 업로드 또는 다운로드 단계의 시작을 나타내는 선택적 메서드입니다. Optional method that indicates the beginning of an upload or download phase of the synchronization.

UpdateConflictsHandler(DataSet, DataSet, DataSet, ConflictLogType, String, Int32, String) UpdateConflictsHandler(DataSet, DataSet, DataSet, ConflictLogType, String, Int32, String) UpdateConflictsHandler(DataSet, DataSet, DataSet, ConflictLogType, String, Int32, String)

게시자와 구독자에서 충돌하는 UPDATE 문이 발생할 때 호출되는 사용자 지정 비즈니스 논리를 구현하는 선택적 메서드입니다. Optional method that implements the custom business logic invoked when conflicting UPDATE statements occur at the Publisher and at the Subscriber.

UpdateDeleteConflictHandler(SourceIdentifier, DataSet, DataSet, ConflictLogType, String, Int32, String) UpdateDeleteConflictHandler(SourceIdentifier, DataSet, DataSet, ConflictLogType, String, Int32, String) UpdateDeleteConflictHandler(SourceIdentifier, DataSet, DataSet, ConflictLogType, String, Int32, String)

게시자와 구독자에서 UPDATE 문이 DELETE 문과 충돌할 때 호출되는 사용자 지정 비즈니스 논리를 구현하는 선택적 메서드입니다. Optional method that implements the custom business logic invoked when UPDATE statements conflict with DELETE statements at the Publisher and at the Subscriber.

UpdateErrorHandler(SourceIdentifier, DataSet, ErrorLogType, String, Int32, String, Int32, String) UpdateErrorHandler(SourceIdentifier, DataSet, ErrorLogType, String, Int32, String, Int32, String) UpdateErrorHandler(SourceIdentifier, DataSet, ErrorLogType, String, Int32, String, Int32, String)

UPDATE 문이 업로드되거나 다운로드되는 동안 오류가 발생할 때 호출되는 사용자 지정 비즈니스 논리를 구현하는 선택적 메서드입니다. Optional method that implements the custom business logic invoked when an error occurs at the time an UPDATE statement is being uploaded or downloaded.

UpdateHandler(SourceIdentifier, DataSet, DataSet, Int32, String) UpdateHandler(SourceIdentifier, DataSet, DataSet, Int32, String) UpdateHandler(SourceIdentifier, DataSet, DataSet, Int32, String)

UPDATE 문이 업로드되거나 다운로드되는 동안 호출되는 사용자 지정 비즈니스 논리를 구현하는 선택적 메서드입니다. Optional method that implements the custom business logic invoked when UPDATE statements are being uploaded or downloaded.

적용 대상