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
包含傳回 MetadataStore 物件之複寫識別碼的 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 命名空間