Exemplo n.º 1
0
        private IEnumerable <Tuple <Photo, Image> > update_ui(PhotoSearchResult searchResult)
        {
            int photosUntilNow = searchResult.Photos.Length + _lastRequestedPage * DEFAULT_PHOTOS_PER_PAGE;

            _lastRequestedPage = searchResult.Page;
            _totalPages        = searchResult.TotalPages;
            _statusText.Text   = "{0} photos of a total {1}".FormatWith(photosUntilNow, _totalPages);

            var photosUi = new List <Tuple <Photo, Image> >();

            foreach (var photo in searchResult.Photos)
            {
                var image = new Image
                {
                    Width   = 110,
                    Height  = 150,
                    Margin  = new Thickness(5),
                    ToolTip = new ToolTip {
                        Content = photo.Title
                    }
                };
                _resultsPanel.Children.Add(image);
                photosUi.Add(Tuple.Create(photo, image));
            }

            return(photosUi);
        }
Exemplo n.º 2
0
        private async Task load_photo_urls_async(CancellationToken token)
        {
            var client = new WebClient();
            var uri    = new Uri(_query.FormatWith(_lastRequestedPage + 1, _currentSearchTerm));

            var photoUrlsTask = client.DownloadStringTaskAsync(uri, token);

            if (photoUrlsTask != await TaskEx.WhenAny(photoUrlsTask, TaskEx.Delay(20000)))
            {
                cancel();
            }

            if (token.IsCancellationRequested)
            {
                return;
            }

            var searchResult = await TaskEx.Run(() => PhotoSearchResult.TryParse(photoUrlsTask.Result));

            if (searchResult.Photos.Length == 0)
            {
                _statusText.Text = "No results found";
                return;
            }

            display_photos(update_ui(searchResult), token);
        }
Exemplo n.º 3
0
        private IEnumerable<Tuple<Photo, Image>> update_ui(PhotoSearchResult searchResult)
        {
            int photosUntilNow = searchResult.Photos.Length + _lastRequestedPage * DEFAULT_PHOTOS_PER_PAGE;
            _lastRequestedPage = searchResult.Page;
            _totalPages = searchResult.TotalPages;
            _statusText.Text = "{0} photos of a total {1}".FormatWith(photosUntilNow, _totalPages);

            var photosUi = new List<Tuple<Photo, Image>>();
            foreach (var photo in searchResult.Photos)
            {
                var image = new Image
                {
                    Width = 110,
                    Height = 150,
                    Margin = new Thickness(5),
                    ToolTip = new ToolTip { Content = photo.Title }
                };
                _resultsPanel.Children.Add(image);
                photosUi.Add(Tuple.Create(photo, image));
            }

            return photosUi;
        }