IDestinationChangeVersionsBuilder::AddItemMetadata
將指定的項目變更加入清單。
HRESULT AddItemMetadata(
const BYTE * pbOwnerReplicaId,
const BYTE * pbItemId,
const SYNC_VERSION * pChangeVersion,
const SYNC_VERSION * pCreationVersion,
DWORD dwFlags,
ISyncChangeBuilder ** ppChangeBuilder);
參數
- pbOwnerReplicaId
[in] 複寫識別碼,而且 pChangeVersion 和 pCreationVersion 在此複寫中必須有效。識別碼的格式必須與提供者的 ID_PARAMETERS 結構所指定的格式相符。
- pbItemId
[in] 此項目的識別碼。識別碼的格式必須與提供者的 ID_PARAMETERS 結構所指定的格式相符。
- pChangeVersion
[in] 此變更的版本。
- pCreationVersion
[in] 此項目的建立版本。
- dwFlags
[in] 指定此項目變更狀態的旗標。有關旗標的值,請參閱 SYNC_CHANGE_FLAG 旗標。
- ppChangeBuilder
[out] 傳回用來將變更單位資訊加入到變更的物件。
傳回值
S_OK
E_POINTER
如果 dwFlags 包含 SYNC_CHANGE_FLAG_DELETED 或 SYNC_CHANGE_FLAG_DOES_NOT_EXIST 以外的任何值,則為 E_INVALIDARG。
發生無效的作業時,為 SYNC_E_INVALID_OPERATION。
如果 pbOwnerReplicaId 或 pbItemId 的格式與提供者的識別碼格式結構描述指定的格式不符,則為 SYNC_E_ID_FORMAT_MISMATCH。
範例
以下範例示範如何列舉遠端變更批次中的變更,然後使用 AddItemMetadata
將本機版本加入至 IDestinationChangeVersionsBuilder 物件,建立相對應的本機版本清單。此範例也會使用 IDestinationChangeVersionsBuilder::GetChangeEnumerator 傳回本機版本的清單。
STDMETHODIMP CMetadataMgr::GetItemBatchVersions(
ISyncChangeBatch * pRemoteSyncChangeBatch,
IEnumSyncChanges ** ppLocalVersionsEnum)
{
HRESULT hr = E_UNEXPECTED;
if (NULL == pRemoteSyncChangeBatch || NULL == ppLocalVersionsEnum)
{
hr = E_POINTER;
}
else
{
IProviderSyncServices* pProvSvc;
hr = GetProviderSyncServices(&c_idParams, &pProvSvc);
if (SUCCEEDED(hr))
{
IDestinationChangeVersionsBuilder* pDestChangeBuilder = NULL;
hr = pProvSvc->CreateDestinationChangeVersionsBuilder(&pDestChangeBuilder);
if (SUCCEEDED(hr))
{
IEnumSyncChanges* pRemoteEnum = NULL;
hr = pRemoteSyncChangeBatch->GetChangeEnumerator(&pRemoteEnum);
if (SUCCEEDED(hr))
{
ULONG cFetched;
ISyncChange* pChange;
SYNC_GID gidItem;
DWORD cbID = sizeof(gidItem);
DWORD dwFlags;
SYNC_VERSION verCurrent;
SYNC_VERSION verCreation;
HRESULT hrEnum = S_OK;
while (S_OK == hrEnum && SUCCEEDED(hr))
{
pChange = NULL;
hrEnum = pRemoteEnum->Next(1, &pChange, &cFetched);
if (S_OK == hrEnum)
{
hr = pChange->GetRootItemId((BYTE*)&gidItem, &cbID);
if (SUCCEEDED(hr))
{
// Try to find the item in the local (destination) metadata.
IItemMetadata* pItem = NULL;
hr = FindItemMetadataByGlobalId((BYTE*)&gidItem, &pItem);
if (S_OK == hr)
{
// S_OK means the item exists in our local store.
// Extract its version and tombstone information.
dwFlags = 0;
BOOL fTombstone = FALSE;
hr = pItem->GetIsDeleted(&fTombstone);
if (SUCCEEDED(hr))
{
if (fTombstone)
{
dwFlags = SYNC_CHANGE_FLAG_DELETED;
}
}
if (SUCCEEDED(hr))
{
hr = pItem->GetChangeVersion(&verCurrent);
if (SUCCEEDED(hr))
{
hr = pItem->GetCreationVersion(&verCreation);
}
}
pItem->Release();
}
else if (S_FALSE == hr)
{
// S_FALSE means this item does not exist in our local store.
// Set versions to 0 and flag it as a new item.
verCurrent.dwLastUpdatingReplicaKey = 0;
verCurrent.ullTickCount = 0;
verCreation.dwLastUpdatingReplicaKey = 0;
verCreation.ullTickCount = 0;
dwFlags = SYNC_CHANGE_FLAG_DOES_NOT_EXIST;
}
if (SUCCEEDED(hr))
{
// Add the item to the batch of destination versions.
GUID guidReplicaID = GUID_NULL;
ULONG cbID = sizeof(guidReplicaID);
hr = GetReplicaId((BYTE*)&guidReplicaID, &cbID);
if (SUCCEEDED(hr))
{
hr = pDestChangeBuilder->AddItemMetadata((BYTE*)&guidReplicaID,
(BYTE*)&gidItem, &verCurrent, &verCreation, dwFlags, NULL);
}
}
}
pChange->Release();
}
}
if (FAILED(hrEnum))
{
hr = hrEnum;
}
pRemoteEnum->Release();
}
if (SUCCEEDED(hr))
{
hr = pDestChangeBuilder->GetChangeEnumerator(ppLocalVersionsEnum);
}
pDestChangeBuilder->Release();
}
pProvSvc->Release();
}
}
return hr;
}