次の方法で共有


SimpleSyncProvider.GetMetadataStore メソッド

派生クラスでオーバーライドされると、レプリカの MetadataStore オブジェクトを返すために Sync Framework ランタイムによって呼び出されます。

名前空間: Microsoft.Synchronization.SimpleProviders
アセンブリ: Microsoft.Synchronization.SimpleProviders (microsoft.synchronization.simpleproviders.dll 内)

構文

'宣言
Public MustOverride Function GetMetadataStore ( _
    <OutAttribute> ByRef replicaId As SyncId, _
    <OutAttribute> ByRef culture As CultureInfo _
) As MetadataStore
'使用
Dim instance As SimpleSyncProvider
Dim replicaId As SyncId
Dim culture As CultureInfo
Dim returnValue As MetadataStore

returnValue = instance.GetMetadataStore(replicaId, culture)
public abstract MetadataStore GetMetadataStore (
    out SyncId replicaId,
    out CultureInfo culture
)
public:
virtual MetadataStore^ GetMetadataStore (
    [OutAttribute] SyncId^% replicaId, 
    [OutAttribute] CultureInfo^% culture
) abstract
public abstract MetadataStore GetMetadataStore (
    /** @attribute OutAttribute() */ /** @ref */ SyncId replicaId, 
    /** @attribute OutAttribute() */ /** @ref */ CultureInfo culture
)
JScript does not support passing value-type arguments by reference.

パラメーター

  • replicaId
    MetadataStore オブジェクトが返されるレプリカの ID を含む SyncId オブジェクト。
  • culture
    文字列の比較に使用されるカルチャを表す CultureInfo オブジェクト。

戻り値

指定されたレプリカのメタデータ ストアを表す MetadataStore オブジェクト。

レプリカにはそれぞれのメタデータ ストアが必要です。簡易プロバイダーの場合、メタデータ ストアは SqlMetadataStore のインスタンスです。次のコード例では、ストアに対するオプションを MyFullEnumerationSimpleSyncProvider のコンストラクターで指定しています。

public MyFullEnumerationSimpleSyncProvider(string name, MySimpleDataStore store)
{
    _name = name;
    _store = store;

    // Create a file to store metadata for all items and a file to store 
    // the replica ID.
    _replicaMetadataFile = Environment.CurrentDirectory + "\\" + _name.ToString() + ".Metadata";
    _replicaIdFile = Environment.CurrentDirectory + "\\" + _name.ToString() + ".Replicaid";

    // Set ReplicaIdFormat to use a GUID as an ID, and ItemIdFormat to use a GUID plus
    // an 8-byte prefix.
    _idFormats = new SyncIdFormatGroup();
    _idFormats.ItemIdFormat.IsVariableLength = false;
    _idFormats.ItemIdFormat.Length = 24;
    _idFormats.ReplicaIdFormat.IsVariableLength = false;
    _idFormats.ReplicaIdFormat.Length = 16;

    this.ItemConstraint += new EventHandler<SimpleSyncItemConstraintEventArgs>(OnItemConstraint);
    this.ItemConflicting += new EventHandler<SimpleSyncItemConflictingEventArgs>(OnItemConflicting);
}
Public Sub New(ByVal name As String, ByVal store As MySimpleDataStore)
    _name = name
    _store = store

    ' Create a file to store metadata for all items and a file to store 
    ' the replica ID. 
    _replicaMetadataFile = (Environment.CurrentDirectory & "\") + _name.ToString() & ".Metadata"
    _replicaIdFile = (Environment.CurrentDirectory & "\") + _name.ToString() & ".Replicaid"

    ' Set ReplicaIdFormat to use a GUID as an ID, and ItemIdFormat to use a GUID plus 
    ' an 8-byte prefix. 
    _idFormats = New SyncIdFormatGroup()
    _idFormats.ItemIdFormat.IsVariableLength = False
    _idFormats.ItemIdFormat.Length = 24
    _idFormats.ReplicaIdFormat.IsVariableLength = False
    _idFormats.ReplicaIdFormat.Length = 16

    AddHandler Me.ItemConstraint, AddressOf HandleItemConstraint
    AddHandler Me.ItemConflicting, AddressOf HandleItemConflicting
End Sub

次のコード例ではストアを作成します。

private void InitializeMetadataStore()
{
    SyncId id = ReplicaId;

    // Create or open the metadata store, initializing it with the ID formats 
    // that are used to reference items and replicas.
    if (!File.Exists(_replicaMetadataFile))
    {
        _metadataStore = SqlMetadataStore.CreateStore(_replicaMetadataFile);
    }
    else
    {
        _metadataStore = SqlMetadataStore.OpenStore(_replicaMetadataFile);
    }
}
Private Sub InitializeMetadataStore()
    Dim id As SyncId = ReplicaId

    ' Create or open the metadata store, initializing it with the ID formats 
    ' that are used to reference items and replicas. 
    If Not File.Exists(_replicaMetadataFile) Then
        _metadataStore = SqlMetadataStore.CreateStore(_replicaMetadataFile)
    Else
        _metadataStore = SqlMetadataStore.OpenStore(_replicaMetadataFile)
    End If
End Sub

次のコードは、このストアをプロバイダーのプロパティとして返します。

public override MetadataStore GetMetadataStore(out SyncId replicaId, out System.Globalization.CultureInfo culture)
{
    InitializeMetadataStore();

    replicaId = ReplicaId;
    culture = CultureInfo.CurrentCulture;
    return _metadataStore;
}
Public Overrides Function GetMetadataStore(ByRef replicaId__1 As SyncId, ByRef culture As System.Globalization.CultureInfo) As MetadataStore
    InitializeMetadataStore()

    replicaId__1 = ReplicaId
    culture = CultureInfo.CurrentCulture
    Return _metadataStore
End Function

完全なアプリケーションのコンテキストでこのコードを表示するには、Sync Framework SDK やCode Galleryから入手できる "Sync101 using Simple Sync Provider" アプリケーションを参照してください。

参照

リファレンス

SimpleSyncProvider クラス
SimpleSyncProvider メンバー
Microsoft.Synchronization.SimpleProviders 名前空間