in Source/Internal/ServiceHelper.cs [460:507]
private static async Task<Response> ProcessAsyncResponse<T>(Response response, Action<int> remainingTimeCallback) where T: Resource
{
if (response != null)
{
if (response.ErrorDetails != null && response.ErrorDetails.Length > 0)
{
throw new Exception(String.Join("", response.ErrorDetails));
}
if (response.ResourceSets != null && response.ResourceSets.Length > 0 && response.ResourceSets[0].Resources != null && response.ResourceSets[0].Resources.Length > 0)
{
if (response.ResourceSets[0].Resources[0] is AsyncStatus && !string.IsNullOrEmpty((response.ResourceSets[0].Resources[0] as AsyncStatus).RequestId))
{
var status = response.ResourceSets[0].Resources[0] as AsyncStatus;
status = await ServiceHelper.ProcessAsyncStatus(status, remainingTimeCallback).ConfigureAwait(false);
if (status != null && status.IsCompleted && !string.IsNullOrEmpty(status.ResultUrl))
{
try
{
using (var resultStream = await ServiceHelper.GetStreamAsync(new Uri(status.ResultUrl)).ConfigureAwait(false))
{
var resource = ServiceHelper.DeserializeStream<T>(resultStream);
response.ResourceSets[0].Resources[0] = resource;
}
}
catch (Exception ex)
{
throw new Exception("There was an issue downloading and serializing the results. Results Download URL: " + status.ResultUrl + "\r\n" + ex.Message);
}
}
return response;
}
else if (response.ResourceSets[0].Resources[0] is AsyncStatus && !string.IsNullOrEmpty((response.ResourceSets[0].Resources[0] as AsyncStatus).ErrorMessage))
{
throw new Exception((response.ResourceSets[0].Resources[0] as AsyncStatus).ErrorMessage);
}
else if (response.ResourceSets[0].Resources[0] is Resource && !(response.ResourceSets[0].Resources[0] is AsyncStatus))
{
return response;
}
}
}
throw new Exception("No response returned by service.");
}