Routing full URL to routed event, and adding profile call to test app (#291)

This commit is contained in:
Jason Sandlin 2017-12-01 14:14:12 -08:00 коммит произвёл GitHub
Родитель 78c911edee
Коммит 529a5e1fe3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 52 добавлений и 7 удалений

Просмотреть файл

@ -689,7 +689,7 @@ http_call_impl::get_http_call_response(
return std::make_shared<http_call_response>(
httpCallData->userContext != nullptr ? httpCallData->userContext->xbox_user_id() : string_t(),
httpCallData->xboxLiveContextSettings,
httpCallData->serverName,
httpCallData->serverName + httpCallData->pathQueryFragment.to_string(),
httpCallData->request,
httpCallData->requestBody,
httpCallData->xboxLiveApi,

Просмотреть файл

@ -183,13 +183,12 @@ void http_call_response::_Route_service_call() const
{
record_service_result();
#ifdef _WIN32
auto fullUrl = m_request.absolute_uri().to_string();
if (!m_errorCode)
{
TraceLoggingWrite(
g_hTraceLoggingProvider,
"http_request",
TraceLoggingWideString(fullUrl.c_str(), "url"),
TraceLoggingWideString(m_fullUrl.c_str(), "url"),
TraceLoggingInt32(m_httpStatus, "status"),
TraceLoggingInt64(std::chrono::duration_cast<std::chrono::milliseconds>(m_responseTime - m_requestTime).count(), "duration"),
TraceLoggingKeyword(XSAPI_TELEMETRY_KEYWORDS)
@ -200,7 +199,7 @@ void http_call_response::_Route_service_call() const
TraceLoggingWrite(
g_hTraceLoggingProvider,
"http_request_exception",
TraceLoggingWideString(fullUrl.c_str(), "url"),
TraceLoggingWideString(m_fullUrl.c_str(), "url"),
TraceLoggingInt32(m_errorCode.value(), "err"),
TraceLoggingString(m_errorMessage.c_str(), "errMsg"),
TraceLoggingInt64(std::chrono::duration_cast<std::chrono::milliseconds>(m_responseTime - m_requestTime).count(), "duration"),
@ -246,13 +245,13 @@ void http_call_response::_Route_service_call() const
{
std::shared_ptr<service_call_logger> tracker = service_call_logger::get_singleton_instance();
const web::uri uri = args.uri();
web::uri uri = args.uri();
const string_t host = uri.host();
const bool isGet = (utils::str_icmp(args.http_method(), L"GET") == 0);
service_call_logger_data sharedData(
host,
fullUrl,
args.uri(),
args.xbox_user_id(),
isGet,
static_cast<uint32_t>(args.http_status()),

Просмотреть файл

@ -51,6 +51,7 @@ void Game::RegisterInputKeys()
m_input->RegisterKey(Windows::System::VirtualKey::Number3, ButtonPress::ToggleSocialGroup3);
m_input->RegisterKey(Windows::System::VirtualKey::Number4, ButtonPress::ToggleSocialGroup4);
m_input->RegisterKey(Windows::System::VirtualKey::Number5, ButtonPress::ToggleSocialGroup5);
m_input->RegisterKey(Windows::System::VirtualKey::P, ButtonPress::CallGetProfile);
m_input->RegisterKey(Windows::System::VirtualKey::C, ButtonPress::ImportCustomList);
}
@ -155,6 +156,21 @@ void Game::OnGameUpdate()
UpdateSocialGroupOfListForAllUsers(m_customList);
}
if (m_input->IsKeyDown(ButtonPress::CallGetProfile))
{
Log(L"Calling get_user_profile");
m_xboxLiveContext->profile_service().get_user_profile(m_xboxLiveContext->user()->xbox_user_id())
.then([this](xbox::services::xbox_live_result<xbox::services::social::xbox_user_profile> result)
{
if (result.err())
return;
auto &payload = result.payload();
Log(L"get_user_profile returned: " + payload.gamertag() + L" Gamerscore: " + payload.gamerscore());
});
}
if (m_input->IsKeyDown(ButtonPress::ImportCustomList))
{
Log(L"Dev accounts CSV can be exported from XDP");
@ -554,6 +570,21 @@ void Game::UpdateSocialGroupOfList(
}
}
Platform::String^ StringFormat(LPCWSTR strMsg, ...)
{
WCHAR strBuffer[2048];
va_list args;
va_start(args, strMsg);
_vsnwprintf_s(strBuffer, 2048, _TRUNCATE, strMsg, args);
strBuffer[2047] = L'\0';
va_end(args);
Platform::String^ str = ref new Platform::String(strBuffer);
return str;
}
void Game::HandleSignInResult(
_In_ const xbox::services::system::sign_in_result& result
)
@ -563,6 +594,19 @@ void Game::HandleSignInResult(
case xbox::services::system::sign_in_status::success:
Log(L"xuid: "+ m_user->xbox_user_id());
m_xboxLiveContext = std::make_shared< xbox::services::xbox_live_context >(m_user);
m_xboxLiveContext->settings()->add_service_call_routed_handler([this](xbox::services::xbox_service_call_routed_event_args args)
{
stringstream_t ss;
Log(L"service_call_routed_handler:");
ss << "[URL]: " << args.http_method().c_str() << " " << args.uri().c_str();
Log(ss.str());
ss << "[Response]: " << args.http_status() << " " << args.response_body().c_str();
Log(ss.str());
});
m_xboxLiveContext->settings()->set_enable_service_call_routed_events(true);
xbox::services::service_call_logging_config::get_singleton_instance()->enable();
AddUserToSocialManager(m_user);
Log(L"Sign in succeeded");
break;

Просмотреть файл

@ -21,6 +21,7 @@ enum ButtonPress
ToggleSocialGroup4,
ToggleSocialGroup5,
ImportCustomList,
CallGetProfile
};
#define PERF_COUNTERS 0 // Enable this for capturing performance counters

Просмотреть файл

@ -163,7 +163,8 @@ void Renderer::RenderMenuOptions(
L"Press 3 to toggle social group for all favorites (%s).\n"
L"Press 4 to toggle social group for online in title (%s).\n"
L"Press 5 to toggle social group for custom list (%s).\n"
L"Press C to import custom list.\n",
L"Press C to import custom list.\n"
L"Press P to get profile without social manager.\n",
g_sampleInstance->GetNumberOfUserInGraph(),
g_sampleInstance->GetXboxLiveContext() == nullptr ? L"n/a" : g_sampleInstance->GetXboxLiveContext()->user()->gamertag().c_str(),
g_sampleInstance->GetAllFriends() ? L"On" : L"Off",