private void btnURLEnter_Click(object sender, EventArgs e) { bool isAlbumEnable = false; if (!IsFieldsEmpty()) { try { Authorizing(); AlbumAddress albumAddress = ParseUrl(tbSource.Text); List <VkCollection <Photo> > get = GetPhotos(albumAddress); urls = GetUrls(get); AlbumName(albumAddress); isAlbumEnable = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); isAlbumEnable = false; } } else { MessageBox.Show("Не все поля заполнены", "Будьте внимательны", MessageBoxButtons.OK, MessageBoxIcon.Error); isAlbumEnable = false; } DownloadButtonEnable(isAlbumEnable); }
private void AlbumName(AlbumAddress albumAddress) { if (isAuthorizedSuccess) { try { if (albumAddress.isDefaultAlbum()) { var album = api.Photo.GetAlbums(new PhotoGetAlbumsParams { OwnerId = albumAddress.OwnerId, AlbumIds = new List <long>() { Convert.ToInt64(albumAddress.AlbumId) } }); lblAlbumName.Text = album[0].Title; } else { lblAlbumName.Text = albumAddress.GetAlbumName(); } } catch { Debug.WriteLine("error get album name"); throw; } } }
private List <VkCollection <Photo> > GetPhotos(AlbumAddress albumAddress) { List <VkCollection <Photo> > get = new List <VkCollection <Photo> >(); int size = 0; if (isAuthorizedSuccess) { try { int dsize = 1; int i = 0; while (dsize > 0) { dsize = 0; VkCollection <Photo> photos = null; photos = api.Photo.Get(new PhotoGetParams { Count = 1000, OwnerId = albumAddress.OwnerId, AlbumId = albumAddress.GetPhotoAlbum, Extended = true, PhotoSizes = true, Offset = 1000 * (ulong)i }); dsize = photos.Count(); size += dsize; get.Add(photos); i++; } lblCountPhotos.Text = size.ToString(); } catch (Exception ex) { lblCountPhotos.Text = "Error - " + ex.Message; Debug.WriteLine("error get photos"); throw; } } return(get); }
private AlbumAddress ParseUrl(string value) { string source = value; int index = 0; string albumId = ""; string ownerId = ""; int shiftIndex = 5; AlbumAddress albumAddress = new AlbumAddress(); if (source.Contains("album")) { index = source.IndexOf("album"); while (!source[index + shiftIndex].Equals('_')) { ownerId += source[index + shiftIndex]; shiftIndex++; } shiftIndex++; while (index + shiftIndex != source.Length) { albumId += source[index + shiftIndex]; shiftIndex++; } Debug.WriteLine("owner= " + ownerId.ToString() + "\nalbumid= " + albumId.ToString()); albumAddress.AlbumId = albumId; albumAddress.OwnerId = Convert.ToInt64(ownerId); return(albumAddress); } else { Debug.WriteLine("error of source url !"); return(null); } }