SimpleSyncProvider.GetMetadataStore 方法

在派生类中重写时,由 Sync Framework 运行时调用来返回副本的 MetadataStore 对象。

命名空间: 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
    一个 SyncId 对象,该对象包含要为其返回 MetadataStore 对象的副本的 ID。
  • 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

若要在完整应用程序的上下文中查看此代码,请参见"Sync101 using Simple Sync Provider" 应用程序(可从 Sync Framework SDK 和 Code Gallery 获得)。

请参阅

参考

SimpleSyncProvider 类
SimpleSyncProvider 成员
Microsoft.Synchronization.SimpleProviders 命名空间