feat(NetworkModule) - Add URI support (#443)

* feat(NetworkModule) - Add URI support

* perf(NetworkingModule): Reduce number of closures allocated in NetworkingModule

While the LINQ approach is elegant, many C# developers understand async/await better than the syntactic sugar behind LINQ. These changes are more imperative and also more efficient.
This commit is contained in:
Matthew Podwysocki 2016-05-27 09:28:27 -04:00 коммит произвёл Eric Rozell
Родитель fc3af07058
Коммит da44203fcd
1 изменённых файлов: 29 добавлений и 1 удалений

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

@ -8,6 +8,7 @@ using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Web.Http;
using Windows.Web.Http.Filters;
@ -123,7 +124,15 @@ namespace ReactNative.Modules.Network
return;
}
throw new NotImplementedException("URI upload is not supported");
_tasks.Add(requestId, token => ProcessRequestFromUriAsync(
requestId,
new Uri(uri),
useIncrementalUpdates,
timeout,
request,
token));
return;
}
else if ((formData = data.Value<JArray>("formData")) != null)
{
@ -174,6 +183,25 @@ namespace ReactNative.Modules.Network
_shuttingDown = true;
}
private async Task ProcessRequestFromUriAsync(
int requestId,
Uri uri,
bool useIncrementalUpdates,
int timeout,
HttpRequestMessage request,
CancellationToken token)
{
var storageFile = await StorageFile.GetFileFromApplicationUriAsync(uri);
var inputStream = await storageFile.OpenReadAsync();
request.Content = new HttpStreamContent(inputStream);
await ProcessRequestAsync(
requestId,
useIncrementalUpdates,
timeout,
request,
token);
}
private async Task ProcessRequestAsync(
int requestId,
bool useIncrementalUpdates,