SimpleSyncProvider.IdFormats 属性
在派生类中重写时,获取表示副本和项 ID 的格式的 SyncIdFormatGroup 对象。
命名空间: Microsoft.Synchronization.SimpleProviders
程序集: Microsoft.Synchronization.SimpleProviders(在 microsoft.synchronization.simpleproviders.dll 中)
语法
声明
Public MustOverride ReadOnly Property IdFormats As SyncIdFormatGroup
用法
Dim instance As SimpleSyncProvider
Dim value As SyncIdFormatGroup
value = instance.IdFormats
public abstract SyncIdFormatGroup IdFormats { get; }
public:
virtual property SyncIdFormatGroup^ IdFormats {
SyncIdFormatGroup^ get () abstract;
}
/** @property */
public abstract SyncIdFormatGroup get_IdFormats ()
public abstract function get IdFormats () : SyncIdFormatGroup
属性值
一个用于定义副本和项 ID 的格式的 SyncIdFormatGroup 对象。
备注
要同步项,Sync Framework 必须能标识项存储区中的项并将该标识映射为元数据存储区中的内部 ID。彼此进行同步的提供程序必须对副本和项 ID 使用共同的格式,这由 IdFormats 属性指定。
示例
下面的代码为 MyFullEnumerationSimpleSyncProvider
示例类和 IdFormats 属性定义构造函数。这使 Sync Framework 运行时可以确定元数据存储区对 ID 采用的格式。如果未使用可变 ID,Sync Framework 使用固定格式标识副本、项和变更单位。如果使用可变 ID,则使用 ISimpleSyncProviderIdGenerator 方法来生成 ID。若要在完整应用程序的上下文中查看此代码,请参见"Sync101 using Simple Sync Provider"
应用程序(可从 Sync Framework SDK 和 Code Gallery 获得)。
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 SyncId ReplicaId
{
get
{
if (_replicaId == null)
{
_replicaId = GetReplicaIdFromFile( _replicaIdFile);
}
return _replicaId;
}
}
public override SyncIdFormatGroup IdFormats
{
get { return _idFormats; }
}
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
Public ReadOnly Property ReplicaId() As SyncId
Get
If _replicaId Is Nothing Then
_replicaId = GetReplicaIdFromFile(_replicaIdFile)
End If
Return _replicaId
End Get
End Property
Public Overrides ReadOnly Property IdFormats() As SyncIdFormatGroup
Get
Return _idFormats
End Get
End Property
请参阅
参考
SimpleSyncProvider 类
SimpleSyncProvider 成员
Microsoft.Synchronization.SimpleProviders 命名空间