internal async Task <HttpResponseMessage> DoHttpCall(PhotoAnalysisRequest photo) { ByteArrayContent content = new ByteArrayContent(GetImageAsByteArray(photo.FullPath)); content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); return(await _client.PostAsync(uri, content)); }
internal async Task <PhotoAnalysisResult> GetSuccessPhotoAnalysisResult(PhotoAnalysisRequest request, HttpResponseMessage message) { return(new PhotoAnalysisResult() { PhotoAnalysisRequest = request, Data = JsonConvert.DeserializeObject <PhotoAnalysisResultData>(await message.Content.ReadAsStringAsync()), Success = true }); }
internal async Task <PhotoAnalysisResult> AnalysePhoto(PhotoAnalysisRequest request) { //_rateLimiter.EnsureRequestWithinRateLimitsAsync(imageFullPath); HttpResponseMessage httpResponseMessage = await DoHttpCall(request); return(httpResponseMessage.IsSuccessStatusCode ? await GetSuccessPhotoAnalysisResult(request, httpResponseMessage) : new PhotoAnalysisResult()); }
private async Task DoAnalysePhotoLoop(PhotoAnalysisRequest photo) { Console.WriteLine($"Requesting - {photo.FullPath}"); var result = await _photoAnayser.AnalysePhoto(photo); if (result.Success) { Console.WriteLine($"Successful reply for - {photo.FullPath}"); await _resultQueue.SendAsync(result); } else { Console.WriteLine($"Request failed for - {photo.FullPath}"); await _rateLimiter.AwaitRateLimitAsync(); Console.WriteLine($"Contiuing on - {photo.FullPath}"); await EnqueueAsync(photo); } }
public async Task <bool> EnqueueAsync(PhotoAnalysisRequest photo) { _requestQueue.Post(photo); return(await Task.FromResult(true)); }