예제 #1
0
        public void Search(ImageSearchQuery query, Action <IEnumerable <Image>, Exception> result)
        {
            var images = new List <Image>();

            images.Add(new Image()
            {
                Title = "A", Thumbnail = "https://aaa.com/thumbnail", Description = "A description", Url = "https://aaa.ru/full", Tags = "T1"
            });
            images.Add(new Image()
            {
                Title = "B", Thumbnail = "https://bbb.com/thumbnail", Description = "B description", Url = "https://bbb.ru/full", Tags = "T2"
            });
            images.Add(new Image()
            {
                Title = "C", Thumbnail = "https://ccc.com/thumbnail", Description = "C description", Url = "https://ccc.ru/full", Tags = "T1 T2"
            });
            images.Add(new Image()
            {
                Title = "D", Thumbnail = "https://ddd.com/thumbnail", Description = "D description", Url = "https://ddd.ru/full", Tags = "T3"
            });

            var filtered = from i in images where i.Tags.Contains(query.Tags[0]) select i;

            result(filtered, null);
        }
예제 #2
0
        public async Task<IList<ImageMetadata>> Handle(ImageSearchQuery request, CancellationToken cancellationToken)
        {
            if (request == null) throw new ArgumentNullException(nameof(request));

            _logger.LogDebug($"Image Search request with criteria :: {request.Criteria}  was received by Flickr Handler");

            var response = await _httpClient.GetAsync($"{ _flickApi }?tags={ request.Criteria }");
            _logger.LogDebug($"FLickr Api responded with status code :: {response.StatusCode}");
            response.EnsureSuccessStatusCode();
            var stream = await response.Content.ReadAsStreamAsync();

            if (stream.Length == 0) return default;

            var feed = (FlickrFeed)new XmlSerializer(typeof(FlickrFeed)).Deserialize(stream);
            var result = feed.Entries
                    .Select(MapToImageMetadata)
                    .ToList();
            return result;
        }
예제 #3
0
        public void Search(ImageSearchQuery option, Action <IEnumerable <Image>, Exception> callback)
        {
            var images = new List <Image>();

            images.Add(new Image()
            {
                Title = "Google", Thumbnail = "https://www.google.ru/images/srpr/logo11w.png", Description = "Google description", Url = "https://www.google.ru/images/srpr/logo11w.png"
            });
            images.Add(new Image()
            {
                Title = "Microsoft", Thumbnail = "https://c.s-microsoft.com/ru-ru/CMSImages/mslogo.png?version=856673f8-e6be-0476-6669-d5bf2300391d"
            });
            images.Add(new Image()
            {
                Title = "Google+", Thumbnail = "https://www.google.ru/images/srpr/logo11w.png"
            });
            images.Add(new Image()
            {
                Title = "Microsoft", Thumbnail = "https://c.s-microsoft.com/ru-ru/CMSImages/mslogo.png?version=856673f8-e6be-0476-6669-d5bf2300391d"
            });
            callback(images, null);
        }