зеркало из https://github.com/microsoft/winsdkfb.git
Fixes for FBPaginatedArray
- Made IHttpClient methods use a read only data structure for parameters - FBClient parameters will not be overwritten by query string values in the request path
This commit is contained in:
Родитель
1c11ab407c
Коммит
39e2e95dce
|
@ -29,7 +29,7 @@ namespace FBWinStoreCsTests
|
|||
{
|
||||
public String ResponseData;
|
||||
|
||||
public IAsyncOperation<string> DeleteTaskAsync(string path, PropertySet parameters)
|
||||
public IAsyncOperation<string> DeleteTaskAsync(string path, IReadOnlyDictionary<String, Object> parameters)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ namespace FBWinStoreCsTests
|
|||
}).AsAsyncOperation<string>();
|
||||
}
|
||||
|
||||
public IAsyncOperation<string> GetTaskAsync(string path, PropertySet parameters)
|
||||
public IAsyncOperation<string> GetTaskAsync(string path, IReadOnlyDictionary<String, Object> parameters)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
|
@ -45,12 +45,12 @@ namespace FBWinStoreCsTests
|
|||
}).AsAsyncOperation<string>();
|
||||
}
|
||||
|
||||
public string ParametersToQueryString(PropertySet Parameters)
|
||||
public string ParametersToQueryString(IReadOnlyDictionary<String, Object> Parameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IAsyncOperation<string> PostTaskAsync(string path, PropertySet parameters)
|
||||
public IAsyncOperation<string> PostTaskAsync(string path, IReadOnlyDictionary<String, Object> parameters)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
|
|
|
@ -146,13 +146,13 @@ Windows::Foundation::IAsyncOperation<FBResult^>^ FBSingleValue::MakeHttpRequest(
|
|||
switch (httpMethod)
|
||||
{
|
||||
case HttpMethod::Get:
|
||||
innerTask = create_task(HttpManager::Instance->GetTaskAsync(_request, _parameters));
|
||||
innerTask = create_task(HttpManager::Instance->GetTaskAsync(_request, _parameters->GetView()));
|
||||
break;
|
||||
case HttpMethod::Post:
|
||||
innerTask = create_task(HttpManager::Instance->PostTaskAsync(_request, _parameters));
|
||||
innerTask = create_task(HttpManager::Instance->PostTaskAsync(_request, _parameters->GetView()));
|
||||
break;
|
||||
case HttpMethod::Delete:
|
||||
innerTask = create_task(HttpManager::Instance->DeleteTaskAsync(_request, _parameters));
|
||||
innerTask = create_task(HttpManager::Instance->DeleteTaskAsync(_request, _parameters->GetView()));
|
||||
break;
|
||||
default:
|
||||
OutputDebugString(L"FBSingleValue::MakeHttpRequest recieved unknown HttpMethod value\n");
|
||||
|
|
|
@ -96,13 +96,14 @@ PropertySet^ FBClient::ToDictionary(PropertySet^ parameters, PropertySet^ mediaO
|
|||
|
||||
IAsyncOperation<String^>^ FBClient::GetTaskAsync(
|
||||
String^ path,
|
||||
PropertySet^ parameters
|
||||
IMapView<String^, Object^>^ parameters
|
||||
)
|
||||
{
|
||||
PropertySet^ modifiableParams = MapViewToPropertySet(parameters);
|
||||
IAsyncOperation<String^>^ myTask = create_async([=]()
|
||||
{
|
||||
Uri^ uri = FBClient::PrepareRequestUri(HttpMethod::Get, path,
|
||||
parameters, nullptr);
|
||||
modifiableParams, nullptr);
|
||||
|
||||
return FBClient::GetTaskInternalAsync(uri)
|
||||
.then([=](String^ Response)
|
||||
|
@ -318,32 +319,33 @@ task<String^> FBClient::MultipartPostInternalAsync(
|
|||
|
||||
IAsyncOperation<String^>^ FBClient::PostTaskAsync(
|
||||
String^ path,
|
||||
PropertySet^ parameters
|
||||
IMapView<String^, Object^>^ parameters
|
||||
)
|
||||
{
|
||||
PropertySet^ modifiableParams = MapViewToPropertySet(parameters);
|
||||
IAsyncOperation<String^>^ result = nullptr;
|
||||
PropertySet^ streams = GetStreamsToUpload(parameters);
|
||||
PropertySet^ streams = GetStreamsToUpload(modifiableParams);
|
||||
if (streams)
|
||||
{
|
||||
result = FBClient::MultipartPostAsync(path, parameters, streams);
|
||||
result = FBClient::MultipartPostAsync(path, modifiableParams, streams);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = FBClient::SimplePostAsync(path, parameters);
|
||||
result = FBClient::SimplePostAsync(path, modifiableParams);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Windows::Foundation::IAsyncOperation<String^>^ FBClient::DeleteTaskAsync(
|
||||
String^ path,
|
||||
PropertySet^ parameters
|
||||
IMapView<String^, Object^>^ parameters
|
||||
)
|
||||
{
|
||||
PropertySet^ modifiableParams = MapViewToPropertySet(parameters);
|
||||
return create_async([=]()
|
||||
{
|
||||
Uri^ uri = FBClient::PrepareRequestUri(HttpMethod::Delete, path,
|
||||
parameters, nullptr);
|
||||
modifiableParams, nullptr);
|
||||
|
||||
return FBClient::DeleteTaskInternalAsync(uri)
|
||||
.then([=](String^ Response)
|
||||
|
@ -602,7 +604,7 @@ Uri^ FBClient::PrepareRequestUri(
|
|||
queryString += L"method=delete&";
|
||||
}
|
||||
#endif
|
||||
queryString += ParametersToQueryString(parametersWithoutMediaObjects);
|
||||
queryString += ParametersToQueryString(parametersWithoutMediaObjects->GetView());
|
||||
}
|
||||
|
||||
String^ host;
|
||||
|
@ -674,7 +676,7 @@ void FBClient::SerializeParameters(
|
|||
}
|
||||
|
||||
String^ FBClient::ParametersToQueryString(
|
||||
PropertySet^ Parameters
|
||||
IMapView<String^, Object^>^ parameters
|
||||
)
|
||||
{
|
||||
String^ queryString = L"";
|
||||
|
@ -683,7 +685,7 @@ String^ FBClient::ParametersToQueryString(
|
|||
// do not need to be uploaded as multipart, i.e. any which is are not
|
||||
// binary data, are required to be in the query string, even for POST
|
||||
// requests!
|
||||
IIterator<IKeyValuePair<String^, Object^>^>^ kvp = Parameters->First();
|
||||
IIterator<IKeyValuePair<String^, Object^>^>^ kvp = parameters->First();
|
||||
while (kvp->HasCurrent)
|
||||
{
|
||||
String^ key = Uri::EscapeComponent(kvp->Current->Key);
|
||||
|
@ -767,10 +769,26 @@ String^ FBClient::MovePathQueryStringToParameters(String^ path, PropertySet^ par
|
|||
while (it->HasCurrent)
|
||||
{
|
||||
IWwwFormUrlDecoderEntry^ current = it->Current;
|
||||
parameters->Insert(current->Name, current->Value);
|
||||
// we don't want to overwrite an explicitly specified value from the user
|
||||
if (!parameters->HasKey(current->Name))
|
||||
{
|
||||
parameters->Insert(current->Name, current->Value);
|
||||
}
|
||||
it->MoveNext();
|
||||
}
|
||||
}
|
||||
return uri->Path;
|
||||
|
||||
}
|
||||
|
||||
PropertySet^ FBClient::MapViewToPropertySet(IMapView<String^, Object^>^ mapView)
|
||||
{
|
||||
PropertySet^ propertySet = ref new PropertySet();
|
||||
IIterator<IKeyValuePair<String^, Object^>^>^ it = mapView->First();
|
||||
while (it->HasCurrent)
|
||||
{
|
||||
IKeyValuePair<String^, Object^>^ current = it->Current;
|
||||
propertySet->Insert(current->Key, current->Value);
|
||||
it->MoveNext();
|
||||
}
|
||||
return propertySet;
|
||||
}
|
|
@ -42,7 +42,7 @@ namespace winsdkfb
|
|||
*/
|
||||
GetTaskAsync(
|
||||
Platform::String^ path,
|
||||
Windows::Foundation::Collections::PropertySet^ parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -56,7 +56,7 @@ namespace winsdkfb
|
|||
virtual Windows::Foundation::IAsyncOperation<Platform::String^>^
|
||||
PostTaskAsync(
|
||||
Platform::String^ path,
|
||||
Windows::Foundation::Collections::PropertySet^ parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ namespace winsdkfb
|
|||
virtual Windows::Foundation::IAsyncOperation<Platform::String^>^
|
||||
DeleteTaskAsync(
|
||||
Platform::String^ path,
|
||||
Windows::Foundation::Collections::PropertySet^ parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ namespace winsdkfb
|
|||
* "key1=value1&key2=value2&..." etc.
|
||||
*/
|
||||
virtual Platform::String^ ParametersToQueryString(
|
||||
Windows::Foundation::Collections::PropertySet^ Parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
private:
|
||||
|
@ -237,5 +237,9 @@ namespace winsdkfb
|
|||
concurrency::task<Windows::Web::Http::HttpResponseMessage^> httpRequestTask,
|
||||
concurrency::cancellation_token_source cancellationTokenSource
|
||||
);
|
||||
|
||||
Windows::Foundation::Collections::PropertySet^ MapViewToPropertySet(
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ mapView
|
||||
);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -347,7 +347,7 @@ Uri^ FacebookDialog::BuildFeedDialogUrl(
|
|||
L"&redirect_uri=" + GetRedirectUriString(L"feed") +
|
||||
L"&display=popup" +
|
||||
L"&app_id=" + sess->FBAppId;
|
||||
String^ queryString = HttpManager::Instance->ParametersToQueryString(Parameters);
|
||||
String^ queryString = HttpManager::Instance->ParametersToQueryString(Parameters->GetView());
|
||||
if (queryString->Length() > 0)
|
||||
{
|
||||
dialogUriString += "&" + queryString;
|
||||
|
@ -372,7 +372,7 @@ Uri^ FacebookDialog::BuildRequestsDialogUrl(
|
|||
L"&redirect_uri=" + GetRedirectUriString(L"requests") +
|
||||
L"&display=popup" +
|
||||
L"&app_id=" + sess->FBAppId;
|
||||
String^ queryString = HttpManager::Instance->ParametersToQueryString(Parameters);
|
||||
String^ queryString = HttpManager::Instance->ParametersToQueryString(Parameters->GetView());
|
||||
if (queryString->Length() > 0)
|
||||
{
|
||||
dialogUriString += "&" + queryString;
|
||||
|
@ -397,7 +397,7 @@ Uri^ FacebookDialog::BuildSendDialogUrl(
|
|||
L"&redirect_uri=" + GetRedirectUriString(L"send") +
|
||||
L"&display=popup" +
|
||||
L"&app_id=" + sess->FBAppId;
|
||||
String^ queryString = HttpManager::Instance->ParametersToQueryString(Parameters);
|
||||
String^ queryString = HttpManager::Instance->ParametersToQueryString(Parameters->GetView());
|
||||
if (queryString->Length() > 0)
|
||||
{
|
||||
dialogUriString += "&" + queryString;
|
||||
|
|
|
@ -44,6 +44,10 @@ FBPaginatedArray::FBPaginatedArray(
|
|||
_parameters(Parameters),
|
||||
_objectFactory(ObjectFactory)
|
||||
{
|
||||
if (_parameters == nullptr)
|
||||
{
|
||||
_parameters = ref new PropertySet();
|
||||
}
|
||||
}
|
||||
|
||||
Windows::Foundation::IAsyncOperation<FBResult^>^ FBPaginatedArray::FirstAsync(
|
||||
|
@ -130,8 +134,7 @@ IVectorView<Object^>^ FBPaginatedArray::ObjectArrayFromJsonArray(
|
|||
}
|
||||
|
||||
FBResult^ FBPaginatedArray::ConsumePagedResponse(
|
||||
String^ JsonText,
|
||||
String^ OriginalPath
|
||||
String^ JsonText
|
||||
)
|
||||
{
|
||||
FBResult^ result = nullptr;
|
||||
|
@ -163,7 +166,7 @@ FBResult^ FBPaginatedArray::ConsumePagedResponse(
|
|||
if (_paging)
|
||||
{
|
||||
foundPaging = true;
|
||||
FormatPagingPaths(_paging, OriginalPath);
|
||||
FormatPagingPaths(_paging);
|
||||
}
|
||||
}
|
||||
else if (!String::CompareOrdinal(it->Current->Key, L"data"))
|
||||
|
@ -232,10 +235,10 @@ Windows::Foundation::IAsyncOperation<FBResult^>^ FBPaginatedArray::GetPage(
|
|||
String^ path
|
||||
)
|
||||
{
|
||||
return create_async([this, path]() -> task<FBResult^>
|
||||
return create_async([=]() -> task<FBResult^>
|
||||
{
|
||||
return create_task(HttpManager::Instance->GetTaskAsync(path, _parameters))
|
||||
.then([this, path](String^ responseString)
|
||||
return create_task(HttpManager::Instance->GetTaskAsync(path, _parameters->GetView()))
|
||||
.then([this](String^ responseString)
|
||||
{
|
||||
if (responseString == nullptr)
|
||||
{
|
||||
|
@ -243,18 +246,17 @@ Windows::Foundation::IAsyncOperation<FBResult^>^ FBPaginatedArray::GetPage(
|
|||
}
|
||||
else
|
||||
{
|
||||
return ConsumePagedResponse(responseString, path);
|
||||
return ConsumePagedResponse(responseString);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void FBPaginatedArray::FormatPagingPaths(
|
||||
FBPaging^ paging,
|
||||
String^ path
|
||||
FBPaging^ paging
|
||||
)
|
||||
{
|
||||
String^ regexString = L"(?:.*?)(" + path + L".*)";
|
||||
String^ regexString = L"(?:.*?)(" + _request + L".*)";
|
||||
std::wstring stdRegexString = std::wstring{ regexString->Data() };
|
||||
std::wregex relativePathRegex{ stdRegexString };
|
||||
std::wsmatch match;
|
||||
|
@ -275,7 +277,7 @@ void FBPaginatedArray::FormatPagingPaths(
|
|||
if (match.size() >= 2)
|
||||
{
|
||||
std::wstring matchText = match[1].str();
|
||||
paging->Next = ref new String(matchText.c_str());
|
||||
paging->Previous = ref new String(matchText.c_str());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -143,8 +143,7 @@ namespace winsdkfb
|
|||
);
|
||||
|
||||
FBResult^ ConsumePagedResponse(
|
||||
Platform::String^ JsonText,
|
||||
Platform::String^ OriginalPath
|
||||
Platform::String^ JsonText
|
||||
);
|
||||
|
||||
Windows::Foundation::IAsyncOperation<FBResult^>^ GetPage(
|
||||
|
@ -152,8 +151,7 @@ namespace winsdkfb
|
|||
);
|
||||
|
||||
void FormatPagingPaths(
|
||||
FBPaging^ paging,
|
||||
Platform::String^ path
|
||||
FBPaging^ paging
|
||||
);
|
||||
|
||||
Windows::Foundation::Collections::IVectorView<Object^>^ _current;
|
||||
|
|
|
@ -34,23 +34,23 @@ void HttpManager::SetHttpClient(IHttpClient^ httpClient)
|
|||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
IAsyncOperation<String^>^ HttpManager::GetTaskAsync(String^ path, PropertySet^ parameters)
|
||||
IAsyncOperation<String^>^ HttpManager::GetTaskAsync(String^ path, IMapView<String^, Object^>^ parameters)
|
||||
{
|
||||
return _httpClient->GetTaskAsync(path, parameters);
|
||||
}
|
||||
|
||||
IAsyncOperation<String^>^ HttpManager::PostTaskAsync(String^ path, PropertySet^ parameters)
|
||||
IAsyncOperation<String^>^ HttpManager::PostTaskAsync(String^ path, IMapView<String^, Object^>^ parameters)
|
||||
{
|
||||
return _httpClient->PostTaskAsync(path, parameters);
|
||||
}
|
||||
|
||||
IAsyncOperation<String^>^ HttpManager::DeleteTaskAsync(String^ path, PropertySet^ parameters)
|
||||
IAsyncOperation<String^>^ HttpManager::DeleteTaskAsync(String^ path, IMapView<String^, Object^>^ parameters)
|
||||
{
|
||||
return _httpClient->DeleteTaskAsync(path, parameters);
|
||||
}
|
||||
|
||||
String^ HttpManager::ParametersToQueryString(
|
||||
PropertySet^ Parameters
|
||||
IMapView<String^, Object^>^ Parameters
|
||||
)
|
||||
{
|
||||
return _httpClient->ParametersToQueryString(Parameters);
|
||||
|
|
|
@ -34,21 +34,21 @@ namespace winsdkfb
|
|||
|
||||
virtual Windows::Foundation::IAsyncOperation<Platform::String^>^ GetTaskAsync(
|
||||
Platform::String^ path,
|
||||
Windows::Foundation::Collections::PropertySet^ parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
virtual Windows::Foundation::IAsyncOperation<Platform::String^>^ PostTaskAsync(
|
||||
Platform::String^ path,
|
||||
Windows::Foundation::Collections::PropertySet^ parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
virtual Windows::Foundation::IAsyncOperation<Platform::String^>^ DeleteTaskAsync(
|
||||
Platform::String^ path,
|
||||
Windows::Foundation::Collections::PropertySet^ parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
virtual Platform::String^ ParametersToQueryString(
|
||||
Windows::Foundation::Collections::PropertySet^ Parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
private:
|
||||
|
|
|
@ -23,21 +23,21 @@ namespace winsdkfb
|
|||
public:
|
||||
Windows::Foundation::IAsyncOperation<Platform::String^>^ GetTaskAsync(
|
||||
Platform::String^ path,
|
||||
Windows::Foundation::Collections::PropertySet^ parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
Windows::Foundation::IAsyncOperation<Platform::String^>^ PostTaskAsync(
|
||||
Platform::String^ path,
|
||||
Windows::Foundation::Collections::PropertySet^ parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
Windows::Foundation::IAsyncOperation<Platform::String^>^ DeleteTaskAsync(
|
||||
Platform::String^ path,
|
||||
Windows::Foundation::Collections::PropertySet^ parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
|
||||
Platform::String^ ParametersToQueryString(
|
||||
Windows::Foundation::Collections::PropertySet^ Parameters
|
||||
Windows::Foundation::Collections::IMapView<Platform::String^, Platform::Object^>^ parameters
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ IAsyncOperation<String^>^ FBSDKAppEvents::LogInstallEvent(
|
|||
parameters->Insert(L"windows_attribution_id", campaignID);
|
||||
return create_task([=]() -> IAsyncOperation<String^>^
|
||||
{
|
||||
return HttpManager::Instance->PostTaskAsync(path, parameters);
|
||||
return HttpManager::Instance->PostTaskAsync(path, parameters->GetView());
|
||||
});
|
||||
}
|
||||
catch (Platform::Exception^ ex)
|
||||
|
@ -206,7 +206,7 @@ IAsyncAction^ FBSDKAppEvents::LogActivateEvent(
|
|||
|
||||
return create_async([=]()
|
||||
{
|
||||
return create_task(HttpManager::Instance->PostTaskAsync(path, parameters))
|
||||
return create_task(HttpManager::Instance->PostTaskAsync(path, parameters->GetView()))
|
||||
.then([=](String^ response) -> void
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
|
Загрузка…
Ссылка в новой задаче