SqlMetadataStore.InitializeReplicaMetadata メソッド
メタデータ ストアでレプリカのメタデータを作成して初期化し、レプリカ メタデータにアクセスするために使用されるレプリカ メタデータ オブジェクトを返します。
名前空間: Microsoft.Synchronization.MetadataStorage
アセンブリ: Microsoft.Synchronization.MetadataStorage (microsoft.synchronization.metadatastorage.dll 内)
構文
'宣言
Public Overrides Function InitializeReplicaMetadata ( _
idFormats As SyncIdFormatGroup, _
replicaId As SyncId, _
customItemFieldSchemas As IEnumerable(Of FieldSchema), _
customIndexedFieldSchemas As IEnumerable(Of IndexSchema) _
) As ReplicaMetadata
'使用
Dim instance As SqlMetadataStore
Dim idFormats As SyncIdFormatGroup
Dim replicaId As SyncId
Dim customItemFieldSchemas As IEnumerable(Of FieldSchema)
Dim customIndexedFieldSchemas As IEnumerable(Of IndexSchema)
Dim returnValue As ReplicaMetadata
returnValue = instance.InitializeReplicaMetadata(idFormats, replicaId, customItemFieldSchemas, customIndexedFieldSchemas)
public override ReplicaMetadata InitializeReplicaMetadata (
SyncIdFormatGroup idFormats,
SyncId replicaId,
IEnumerable<FieldSchema> customItemFieldSchemas,
IEnumerable<IndexSchema> customIndexedFieldSchemas
)
public:
virtual ReplicaMetadata^ InitializeReplicaMetadata (
SyncIdFormatGroup^ idFormats,
SyncId^ replicaId,
IEnumerable<FieldSchema^>^ customItemFieldSchemas,
IEnumerable<IndexSchema^>^ customIndexedFieldSchemas
) override
public ReplicaMetadata InitializeReplicaMetadata (
SyncIdFormatGroup idFormats,
SyncId replicaId,
IEnumerable<FieldSchema> customItemFieldSchemas,
IEnumerable<IndexSchema> customIndexedFieldSchemas
)
public override function InitializeReplicaMetadata (
idFormats : SyncIdFormatGroup,
replicaId : SyncId,
customItemFieldSchemas : IEnumerable<FieldSchema>,
customIndexedFieldSchemas : IEnumerable<IndexSchema>
) : ReplicaMetadata
パラメーター
- idFormats
プロバイダーの ID 形式スキーマです。
- replicaId
このメタデータに関連付けられているレプリカ ID です。
- customItemFieldSchemas
各メタデータ項目のカスタム メタデータ フィールドに関するスキーマ情報のコレクションです。カスタム メタデータ フィールドがない場合は、NULL 参照 (Visual Basic では Nothing) です。 が返されることがあります。
- customIndexedFieldSchemas
メタデータ ストアにおける項目の検索を効率化するために使用されるインデックス スキーマの一覧です。カスタム インデックスがない場合は NULL 参照 (Visual Basic では Nothing) です。 にできます。
戻り値
メタデータ ストア内のレプリカ メタデータにアクセスするために使用されるレプリカ メタデータ オブジェクトです。
例外
例外の種類 | 条件 |
---|---|
このオブジェクトが破棄されているか、正しく初期化されていません。 |
|
idFormats または replicaId が NULL 参照 (Visual Basic では Nothing) です。 です。 |
|
customItemFieldSchemas に長さが 0 のカスタム フィールド名があります。 |
|
customItemFieldSchemas に名前が NULL 参照 (Visual Basic では Nothing) です。 のカスタム フィールドがあります。 |
|
customIndexedFieldSchemas 内のフィールドが customItemFieldSchemas に存在しません。 |
|
replicaId の形式が、idFormats で指定された形式と一致しません。 |
|
idFormats によって指定された ID の長さが 8,000 バイトを超えています。 |
|
メタデータ ストアが開かれていないか、作成されていません。 |
|
指定された replicaId のレプリカ メタデータがメタデータ ストアに既に存在します。 |
解説
このメソッドは、メタデータ ストアで一連の新しいレプリカ メタデータを作成するために使用されます。メタデータ ストアの既存のレプリカ メタデータにアクセスするには、GetReplicaMetadata を使用します。
このメソッドは、Metadata Storage Services に用意された ReplicaMetadata 抽象クラスの実装を返します。この抽象クラスを使用すると、Sync Framework データベース ファイルに格納されているレプリカ メタデータにアクセスできます。
customItemFieldSchemas を使用すると、項目メタデータに対して一連のカスタム フィールドを定義できます。各フィールドは、一意の文字列の名前と値で構成されます。これらのフィールドを使用すると、既定の項目メタデータによってはサポートされていないような、項目に関する追加のメタデータを格納できます。フィールドにアクセスするには、ItemMetadata.GetByteField や Microsoft.Synchronization.MetadataStorage.ItemMetadata.SetCustomField などのさまざまなメソッドを ItemMetadata に対して使用します。
customIndexedFieldSchemas を使用してインデックス スキーマを定義すると、一連のカスタム フィールドをインデックスとして使用して、メタデータ ストア内の項目を効率的に検索できるようになります。インデックス スキーマを一意に定義すると、インデックスによって単一の項目が定義されるようになります。インデックス スキーマに含まれている各フィールドは、レプリカ用に定義されたカスタム フィールド スキーマ内にも存在する必要があります。インデックス フィールドは、ReplicaMetadata.FindItemMetadataByIndexedField や ReplicaMetadata.FindItemMetadataByUniqueIndexedFields などのメソッドで使用できます。
例
次の例では、レプリカ メタデータが既に存在しない場合に SqlMetadataStore オブジェクト内のレプリカ メタデータを初期化します。この例では、レプリカ メタデータに一連のカスタム フィールドを指定し、さらにカスタム フィールドを一意なインデックスとして使用することを指定します。
public void NewStore(string StoreName, MetadataStore metaStore, bool metaStoreIsNew)
{
// Close the current store. This is necessary to release the ReplicaMetadata object held by this object.
Close(true);
// Keep the store name for later use.
_StoreName = StoreName;
// The absolute path of the item store is used as the replica ID.
string StoreAbsPath = Path.GetFullPath(StoreName);
// Get or initialize replica metadata in the metadata store.
_ContactMetadataStore = metaStore;
if (!metaStoreIsNew)
{
// The metadata store exists, so open it and get the replica metadata for the current replica.
// The replica ID is the absolute path of the item store.
_ContactReplicaMetadata = _ContactMetadataStore.GetReplicaMetadata(ContactIdFormatGroup,
new SyncId(StoreAbsPath));
// Read the contacts from the item store and the metadata store and save them in two
// in-memory lists. These lists are modified in memory by the methods in this object
// and committed to the disk when SaveChanges is called.
StreamReader contactReader;
contactReader = File.OpenText(StoreName);
Contact contact = ReadNextContact(contactReader);
while (null != contact)
{
ItemMetadata itemMeta = FindMetadata(contact);
_ContactList.Add(itemMeta.GlobalId, contact);
_ContactItemMetaList.Add(itemMeta.GlobalId, itemMeta);
contact = ReadNextContact(contactReader);
}
contactReader.Close();
}
else
{
// The metadata store does not exist, so create a new one.
// Create custom fields for First Name, Last Name, and Phone Number. These will be used
// as unique index fields for identifying items between the metadata store and the item store.
FieldSchema[] CustomFields =
{
new FieldSchema(FirstNameField, typeof(string), 100),
new FieldSchema(LastNameField, typeof(string), 100),
new FieldSchema(PhoneNumberField, typeof(string), 20)
};
// Specify the custom fields as a unique index.
string[] IndexFields = { FirstNameField, LastNameField, PhoneNumberField };
IndexSchema[] Indexes =
{
new IndexSchema(IndexFields, true)
};
// Create the metadata for the replica in the metadata store.
_ContactReplicaMetadata = _ContactMetadataStore.InitializeReplicaMetadata(
ContactIdFormatGroup, new SyncId(StoreAbsPath), CustomFields, Indexes);
// Set the provider version
_ContactReplicaMetadata.ProviderVersion = (uint)ContactsProviderVersion.ContactsProvider_v1;
}
}
参照
リファレンス
SqlMetadataStore クラス
SqlMetadataStore メンバー
Microsoft.Synchronization.MetadataStorage 名前空間