示例#1
0
        public void GetPhotos()
        {
            SlackHelper slackHelper = null;

            for (int i = 0; i < users_helpers.Count; i++)
            {
                Responses.SlackUsersInfoResponse usersInfoResponse = users_helpers[i].Users_Info(applicationContract.GetPhotoUserID());

                if (usersInfoResponse.Ok)
                {
                    slackHelper = users_helpers[i];
                    break;
                }
            }

            if (!slackHelper.IsAuthorized)
            {
                return;
            }

            const UInt64 count = 20;
            UInt64       page  = applicationContract.GetPhotosCount() / count + 1;

            Responses.SlackFilesListResponse slackFilesListResponse = slackHelper.Files_List(applicationContract.GetPhotoUserID(), Models.SlackFileTypes.Images, count, page);

            if (!slackFilesListResponse.Ok)
            {
                return;
            }

            List <Models.SlackFile> files = slackFilesListResponse.Files.ToList();

            List <PhotosListItem> photosItems = new List <PhotosListItem>();

            foreach (Models.SlackFile file in files)
            {
                if (!file.PublicURLShared)
                {
                    continue;
                }

                String[] permalink_split = file.PermalinkPublic.Split('-');
                String   photo_link      = String.Format("{0}?pub_secret={1}", file.URLPrivate, permalink_split[permalink_split.Length - 1]);

                PhotosListItem photoItem = new PhotosListItem(new Uri(photo_link));

                photosItems.Add(photoItem);
            }

            applicationContract.AddItemsToPhotosList(photosItems);
            applicationContract.SetPhotosListSatusData(String.Format("{0}/{1}", applicationContract.GetPhotosCount(), slackFilesListResponse.Paging.Total));
            if (applicationContract.GetPhotosCount() == slackFilesListResponse.Paging.Total)
            {
                applicationContract.DisableNextPhotosButton();
            }
        }
示例#2
0
        public void GetPhotos()
        {
            VkCollection <Photo> photos = null;

            long owner_id = Convert.ToInt64(applicationContract.GetPhotoUserID());

            PhotoGetAllParams photoGetAllParams = new PhotoGetAllParams();

            photoGetAllParams.OwnerId    = owner_id;
            photoGetAllParams.PhotoSizes = true;
            photoGetAllParams.Offset     = applicationContract.GetPhotosCount();

            VkApi user_api = null;

            for (int i = 0; i < users_api.Count; i++)
            {
                if
                (
                    (users_api[i].UserId == owner_id) ||
                    (users_api[i].Friends.AreFriends(new List <long>()
                {
                    owner_id
                })[0].FriendStatus == VkNet.Enums.FriendStatus.Friend)
                )
                {
                    user_api = users_api[i];
                    break;
                }
            }

            if (user_api == null)
            {
                return;
            }

            try
            {
                photos = user_api.Photo.GetAll(photoGetAllParams);
            }
            catch (VkApiException)
            {
                return;
            }

            List <PhotosListItem> photosItems = new List <PhotosListItem>();

            foreach (Photo photo in photos)
            {
                PhotosListItem photoItem = new PhotosListItem(photo.Sizes[photo.Sizes.Count - 1].Url);

                photosItems.Add(photoItem);
            }

            applicationContract.AddItemsToPhotosList(photosItems);
            applicationContract.SetPhotosListSatusData(String.Format("{0}/{1}", applicationContract.GetPhotosCount(), photos.TotalCount));

            if (applicationContract.GetPhotosCount() == photos.TotalCount)
            {
                applicationContract.DisableNextPhotosButton();
            }
        }