Beispiel #1
0
        private async Task <IActionResult> ByPhotoset()
        {
            var responseBody = new FlickrPhotosetsRoot();

            do
            {
                var response = await _http.GetAsync(BuildByPhotosetQuery(responseBody.Photoset.Page));

                responseBody =
                    JsonConvert.DeserializeObject <FlickrPhotosetsRoot>(await response.Content.ReadAsStringAsync());
                await HandleRequestAsync(responseBody, response);
            } while (responseBody.Photoset.Page < responseBody.Photoset.Pages);

            return(new OkResult());
        }
Beispiel #2
0
        private async Task HandleRequestAsync(FlickrPhotosetsRoot responseBody, HttpResponseMessage response)
        {
            var newPhotos = new List <string>();
            var dbPhotos  = await GetPhotosFromCache();

            foreach (var photo in responseBody.Photoset.Photo)
            {
                if (dbPhotos.Find(el => el.Id == photo.Id) == null)
                {
                    newPhotos.Add(CreatePhotoUrl(photo));
                    await _context.AddAsync(photo);
                }
            }

            await _faceService.AnalyzePhotos(newPhotos);

            await _context.SaveChangesAsync();

            _memoryCache.Remove("FlickrPhotos");
        }