public PhotoLite(Photo photo) { ListingKey = photo.ListingKey; DisplayOrder = photo.DisplayOrder; PhotoUrl = photo.PhotoUrl; }
public List<Photo> GetRetsPropertiesImages(List<long> propertyKeys) { List<Photo> photos = new List<Photo>(); HttpWebResponse loginResponse = Login(); loginResponse.Close(); HttpWebResponse propertyResponse = GetPhotoData(propertyKeys); string response = PrintResponseStream(propertyResponse); propertyResponse.Close(); if (string.IsNullOrWhiteSpace(response) == false) { try { string[] images = response.Replace('\r', ' ').Split(new char[] { '\r', '\n' }); for (int i = 0; i < images.Count(); i++) { if (images[i].StartsWith("--simple boundary")) { // safety check. if (i + 5 < images.Count()) { // we have data for image. bool correctData = true; // Property's listing key as Content-ID i += 3; Photo photo = new Photo(); try { if (images[i].Contains("Content-ID") == false) correctData = false; string contentId = images[i].Trim().Split(':')[1].Trim(); long temp = 0; if (long.TryParse(contentId, out temp)) photo.ListingKey = long.Parse(contentId); // Display order as Object-ID i++; if (images[i].Contains("Object-ID") == false) correctData = false; string objectId = images[i].Trim().Split(':')[1].Trim(); int temp2 = 0; if (int.TryParse(objectId, out temp2)) photo.DisplayOrder = int.Parse(objectId); // Link to image as Location i++; if (images[i].Contains("Location") == false) correctData = false; string location = string.Empty; // problem? well urls also contain : so... string[] locations = images[i].Trim().Split(':');//[1].Trim(); for (int j = 1; j < locations.Length; j++) { if (j < locations.Length - 1) location += locations[j].Trim() + ":"; else location += locations[j].Trim(); } photo.PhotoUrl = location.Trim(); } catch (Exception e) { Console.WriteLine("Exception while loading image from image."); Console.WriteLine(e.StackTrace); } if (correctData) photos.Add(photo); }// end if } //Console.WriteLine(images[i].Trim()); } } catch (Exception e) { Console.WriteLine("ERROR: " + e.StackTrace); } } HttpWebResponse logoutResponse = Logout(); logoutResponse.Close(); return photos; }