SimpleSyncProvider::GetMetadataStore Method
When overridden in a derived class, called by the Sync Framework runtime to return a MetadataStore object for a replica.
Assembly: Microsoft.Synchronization.SimpleProviders (in Microsoft.Synchronization.SimpleProviders.dll)
public: virtual MetadataStore^ GetMetadataStore( [OutAttribute] SyncId^% replicaId, [OutAttribute] CultureInfo^% culture ) abstract
Parameters
- replicaId
- Type: Microsoft.Synchronization::SyncId%
A SyncId object that contains the ID of the replica for which the MetadataStore object is returned.
- culture
- Type: System.Globalization::CultureInfo%
A CultureInfo object that represents the culture that is used for string comparisons.
Return Value
Type: Microsoft.Synchronization.MetadataStorage::MetadataStoreA MetadataStore object that represents a metadata store for the specified replica.
Each replica requires a metadata store, which for simple providers is an instance of SqlMetadataStore. The following code example specifies options for a store in the constructor of 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
The following code example creates the store.
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
The following code returns this store as a provider property.
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
To view this code in the context of a complete application, see the "Sync101 using Simple Sync Provider" application that is available in the Sync Framework SDK and from Code Gallery.
Show: