public void Enumerate(MediaCollector collector, Action itemsAvailable = null) { foreach (var fm in folderList) { var path = Path.Combine(fm.Path); if (!Path.IsPathRooted(path)) { path = Path.GetFullPath(Path.Combine(baseFolder, path)); } if (Directory.Exists(path)) { try { FileEnumerator.AddFilenames( (s) => collector.AddItem(new MediaItem(this, s)), path, (s) => SupportedExtension(Path.GetExtension(s))); } catch (Exception ex) { logger.Info("Exception: {0}", ex); } } else { logger.Warn("Ignoring non-existent path: '{0}'", path); } } }
public void Enumerate(MediaCollector collector, Action itemsAvailable = null) { using (var client = new HttpClient()) { int first = 0; int count = 100; client.BaseAddress = new Uri(host); try { bool searchAgain = true; do { searchAgain = false; var requestUrl = string.Format("api/search?f={0}&c={1}&q={2}", first, count, search); var result = client.GetAsync(requestUrl).Result; if (result.IsSuccessStatusCode) { var body = result.Content.ReadAsStringAsync().Result; dynamic response = JObject.Parse(body); if (response["matches"] != null) { first += count; foreach (var m in response["matches"]) { searchAgain = true; var mimeType = m["mimeType"].ToString(); if (mimeType != null && mimeType.StartsWith("image")) { var item = new ItemCache { Url = m["fullUrl"], Length = m["length"], MimeType= m["mimeType"], CreatedDate = m["createdDate"], Signature = m["signature"], Latitude = m["latitude"], Longitude = m["longitude"], }; logger.Info("Lat/long {0}, {1}", item.Latitude, item.Longitude); collector.AddItem(new MediaItem(this, item)); } } } } else { logger.Error( "FindAPhoto search failed: {0}; {1}; {2}", result.StatusCode, result.ReasonPhrase, result.Content.ReadAsStringAsync().Result); break; } } while (searchAgain); } catch (Exception ex) { logger.Error("Exception searching: {0}", ex); } } }