The following code sample shows how to browse the catalog on Xbox Live. The catalog lists items that players can buy from the marketplace.
The function in the sample takes a vector of catalog item IDs and calls CatalogService.GetCatalogItemDetailsAsync Method using 10 IDs at a time to get the details about the items from the catalog. The reason for getting 10 items at a time is due to a limit in GetCatalogItemDetailsAsync.
IVectorView< Marketplace::CatalogItemDetails^ >^
Sample::GetCatalogListDetails( __in XboxLiveContext^ Requester,
__in IVectorView< Marketplace::CatalogItem^ >^ CatalogItems )
{
Vector< Marketplace::CatalogItemDetails^ >^ returnVector = ref new Vector< Marketplace::CatalogItemDetails^ >();
// The Details service can only support 10 CatalogItems per request (MAX_DETAILS_ITEMS)
// So batch up the calls with 10 or less CatalogItems
for( UINT iBatchStartPosition = 0; iBatchStartPosition < CatalogItems->Size; iBatchStartPosition += MAX_DETAILS_BATCH_ITEMS )
{
// Extract just the ID's to make the call for the details of each one
IVector< Platform::String^ >^ vProductIds = ref new Platform::Collections::Vector< Platform::String^ >();
UINT iBatchEndPosition = iBatchStartPosition + MAX_DETAILS_BATCH_ITEMS;
if ( iBatchEndPosition > CatalogItems->Size )
{
iBatchEndPosition = CatalogItems->Size;
}
for( UINT i = iBatchStartPosition; i < iBatchEndPosition; ++i )
{
vProductIds->Append( CatalogItems->GetAt( i )->ProductId );
}
IAsyncOperation< IVectorView<Marketplace::CatalogItemDetails^ >^ >^ asyncOp =
Requester->CatalogService->GetCatalogItemDetailsAsync( vProductIds->GetView() );
create_task( asyncOp )
.then( [this, &returnVector] ( task< IVectorView< Marketplace::CatalogItemDetails^ >^ > detailsResultTask )
{
try
{
// Get the results and append them to the return vector
IVectorView< Marketplace::CatalogItemDetails^ >^ detailsResults = detailsResultTask.get();
for( UINT i = 0; i < detailsResults->Size; ++i )
{
returnVector->Append( detailsResults->GetAt( i ) );
}
}
catch( Platform::Exception^ ex )
{
XboxSampleFramework::DebugPrint( "SAMPLE: Error 0x%x obtaining details from catalog\n", ex->HResult );
m_hrDisplayError = ex->HResult;
m_appState = APP_DONE_ERROR;
}
})
.wait();
}
return returnVector->GetView();
}