public void AddPhoto(Album album, Photo photo, PhotoData data) { Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(username, album.Id)); using (Stream s = new MemoryStream(data.Data)) { PicasaEntry newentry = (PicasaEntry)service.Insert(postUri, s, data.Mime, photo.Name); } }
public static PhotoData GetPhotoData(Photo photo) { using (WebClient client = new WebClient()) { PhotoData data = new PhotoData() { Data = DownloadData(client, new Uri(photo.Url), NUMBER_OF_TRIES), Mime = client.ResponseHeaders["Content-Type"] }; return data; } }
public static async Task<Product> ReadProductTaskAsync(string url) { using (WebClient client = new WebClient()) { client.Encoding = Encoding.UTF8; client.Headers.Add("Accept-Language", "en-US,en;q=0.5"); String content = await DownloadStringTaskAsync(client, UpgradeUri(url), NUMBER_OF_TRIES); Product prod = new Product(); Match m1 = reProductName.Match(content); if (m1.Success) { prod.Name = m1.Groups[1].Value; } else { throw new Exception("Missing product name"); } Match mNext = null; do { // read photos MatchCollection mc = rePhotos.Matches(content); foreach (Match m2 in mc) { Photo photo = new Photo() { Url = m2.Groups[1].Value.Replace("square.jpg", "big.jpg"), Name = m2.Groups[2].Value }; prod.Photos.Add(photo); } // check existence of the next page mNext = reNext.Match(content); if (mNext.Success) { // fetch contents of the next page content = await DownloadStringTaskAsync(client, UpgradeUri("http://v.yupoo.com" + mNext.Groups[1].Value), NUMBER_OF_TRIES); } } while (mNext.Success); return prod; } }
public void AddPhoto(string album, Photo photo, PhotoData data) { Album a = GetAlbum(album); AddPhoto(a, photo, data); }