SqlCeClientSyncProvider クラス
クライアントと通信する SQL Server Compact のクライアント同期プロバイダーを抽象化して、同期エージェントに対してクライアント データベースの特定の実装が明らかにならないようにします。
名前空間: Microsoft.Synchronization.Data.SqlServerCe
アセンブリ: Microsoft.Synchronization.Data.SqlServerCe (Microsoft.Synchronization.Data.SqlServerCe.dll 内)
構文
'宣言
Public Class SqlCeClientSyncProvider _
Inherits ClientSyncProvider
'使用
Dim instance As SqlCeClientSyncProvider
public class SqlCeClientSyncProvider : ClientSyncProvider
public ref class SqlCeClientSyncProvider : public ClientSyncProvider
type SqlCeClientSyncProvider =
class
inherit ClientSyncProvider
end
public class SqlCeClientSyncProvider extends ClientSyncProvider
説明
クライアント同期プロバイダーの主要な動作は次のとおりです。
クライアント上の同期可能なテーブルに関する情報を格納します。
前回の同期以降にクライアント データベースで発生した変更を取得します。
クライアント データベースに増分変更を適用します。
競合する変更を検出します。
例
次のコード例では、SqlCeClientSyncProvider から派生するクラスを作成します。このクラスは、クライアント データベースへの接続を作成し、クライアント データベース内のスキーマの作成など、いくつかの一般的なイベントを処理します。完全なコンテキスト例でこのコードを表示するには、「イベントを操作する方法とビジネス ロジックをプログラムする方法」を参照してください。
public class SampleClientSyncProvider : SqlCeClientSyncProvider
{
public SampleClientSyncProvider()
{
//Specify a connection string for the sample client database.
Utility util = new Utility();
this.ConnectionString = Utility.ConnStr_SqlCeClientSync;
//Log information for the following events.
this.SchemaCreated += new EventHandler<SchemaCreatedEventArgs>(EventLogger.LogEvents);
this.ChangesSelected += new EventHandler<ChangesSelectedEventArgs>(EventLogger.LogEvents);
this.ChangesApplied += new EventHandler<ChangesAppliedEventArgs>(EventLogger.LogEvents);
this.ApplyChangeFailed += new EventHandler<ApplyChangeFailedEventArgs>(EventLogger.LogEvents);
//Use the following events to fix up schema on the client.
//We use the CreatingSchema event to change the schema
//by using the API. We use the SchemaCreated event
//to change the schema by using SQL.
//Note that both schema events fire for the Customer table,
//even though we already created the table. This allows us
//to work with the table at this point if we have to.
this.CreatingSchema += new EventHandler<CreatingSchemaEventArgs>(SampleClientSyncProvider_CreatingSchema);
this.SchemaCreated += new EventHandler<SchemaCreatedEventArgs>(SampleClientSyncProvider_SchemaCreated);
}
private void SampleClientSyncProvider_CreatingSchema(object sender, CreatingSchemaEventArgs e)
{
string tableName = e.Table.TableName;
if (tableName == "Customer")
{
//Set the RowGuid property because it is not copied
//to the client by default. This is also a good time
//to specify literal defaults with .Columns[ColName].DefaultValue,
//but we will specify defaults like NEWID() by calling
//ALTER TABLE after the table is created.
e.Schema.Tables["Customer"].Columns["CustomerId"].RowGuid = true;
}
if (tableName == "OrderHeader")
{
e.Schema.Tables["OrderHeader"].Columns["OrderId"].RowGuid = true;
}
}
private void SampleClientSyncProvider_SchemaCreated(object sender, SchemaCreatedEventArgs e)
{
string tableName = e.Table.TableName;
Utility util = new Utility();
//Call ALTER TABLE on the client. This must be done
//over the same connection and within the same
//transaction that Sync Framework uses
//to create the schema on the client.
if (tableName == "Customer")
{
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "Customer");
}
if (tableName == "OrderHeader")
{
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "OrderHeader");
}
if (tableName == "OrderDetail")
{
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "OrderDetail");
}
}
}
Public Class SampleClientSyncProvider
Inherits SqlCeClientSyncProvider
Public Sub New()
'Specify a connection string for the sample client database.
Dim util As New Utility()
Me.ConnectionString = Utility.ConnStr_SqlCeClientSync
'Log information for the following events.
AddHandler Me.SchemaCreated, AddressOf EventLogger.LogEvents
AddHandler Me.ChangesSelected, AddressOf EventLogger.LogEvents
AddHandler Me.ChangesApplied, AddressOf EventLogger.LogEvents
AddHandler Me.ApplyChangeFailed, AddressOf EventLogger.LogEvents
'Use the following events to fix up schema on the client.
'We use the CreatingSchema event to change the schema
'by using the API. We use the SchemaCreated event
'to change the schema by using SQL.
'Note that both schema events fire for the Customer table,
'even though we already created the table. This allows us
'to work with the table at this point if we have to.
AddHandler Me.CreatingSchema, AddressOf SampleClientSyncProvider_CreatingSchema
AddHandler Me.SchemaCreated, AddressOf SampleClientSyncProvider_SchemaCreated
End Sub 'New
Private Sub SampleClientSyncProvider_CreatingSchema(ByVal sender As Object, ByVal e As CreatingSchemaEventArgs)
Dim tableName As String = e.Table.TableName
If tableName = "Customer" Then
'Set the RowGuid property because it is not copied
'to the client by default. This is also a good time
'to specify literal defaults with .Columns[ColName].DefaultValue,
'but we will specify defaults like NEWID() by calling
'ALTER TABLE after the table is created.
e.Schema.Tables("Customer").Columns("CustomerId").RowGuid = True
End If
If tableName = "OrderHeader" Then
e.Schema.Tables("OrderHeader").Columns("OrderId").RowGuid = True
End If
End Sub 'SampleClientSyncProvider_CreatingSchema
Private Sub SampleClientSyncProvider_SchemaCreated(ByVal sender As Object, ByVal e As SchemaCreatedEventArgs)
Dim tableName As String = e.Table.TableName
Dim util As New Utility()
'Call ALTER TABLE on the client. This must be done
'over the same connection and within the same
'transaction that Sync Framework uses
'to create the schema on the client.
If tableName = "Customer" Then
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "Customer")
End If
If tableName = "OrderHeader" Then
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "OrderHeader")
End If
If tableName = "OrderDetail" Then
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "OrderDetail")
End If
End Sub 'SampleClientSyncProvider_SchemaCreated
End Class 'SampleClientSyncProvider
継承階層
System. . :: . .Object
Microsoft.Synchronization. . :: . .SyncProvider
Microsoft.Synchronization.Data. . :: . .ClientSyncProvider
Microsoft.Synchronization.Data.SqlServerCe..::..SqlCeClientSyncProvider
スレッド セーフ
この型の public static (Visual Basic では Shared) のメンバーはスレッド セーフです。インスタンス メンバーの場合は、スレッド セーフであるとは限りません。