protected override List <String> DiscoverImageUrls(String search) { List <String> urls = new List <String>(); try { if (search == "") { StatusManager.Instance.StatusMessage("Please enter some text and try again."); return(urls); } FlickrResponse response = PerformSearch(search); while (urls.Count < this.totalDesiredImages) { // First, look for obvious error conditions, or exhausted results if ((response == null) || (response.Photos == null)) { // The Urls collection could be populated, so only // present the error if it's not. if (urls.Count == 0) { StatusManager.Instance.StatusMessage("No subjects found."); } return(urls); } if (response.Photos.PhotoCollection.Count > 10) { urls.Add(response.Photos.PhotoCollection[rand.Next(response.Photos.PhotoCollection.Count - 1)].MediumUrl); } if (response.Photos.TotalPages > 1) { if (rand.Next(0, 3) == 1) { long nextPage = (response.Photos.PageNumber + 1) % response.Photos.TotalPages; response = PerformSearch(search, (int)nextPage); } } else { // We didn't get that many results, so try reducing // the search criteria search = pruneSearch(search); // Search again response = PerformSearch(search); } } } catch (Exception) { } return(urls); }
private static FlickrResponse Deserialize(string responseString) { XmlSerializer serializer = _responseSerializer; try { // Deserialise the web response into the Flickr response object System.IO.StringReader responseReader = new System.IO.StringReader(responseString); FlickrResponse response = (FlickrResponse)serializer.Deserialize(responseReader); responseReader.Close(); return(response); } catch (InvalidOperationException ex) { // Serialization error occurred! throw new Exception("FlickR: Invalid response received (" + ex.Message + ")"); } }