コード例 #1
0
        public async Task <Photo> GetOriginalTagsTask(Photo photo, Preferences preferences)
        {
            var extraParams = new Dictionary <string, string>
            {
                {
                    ParameterNames.PhotoId, photo.Id
                },
                {
                    ParameterNames.Secret, photo.Secret
                }
            };

            var photoResponse =
                (Dictionary <string, object>)
                await _oAuthManager.MakeAuthenticatedRequestAsync(Methods.PhotosGetInfo, extraParams);

            // Override the internal tags with the original ones
            photo.Tags = string.Join(", ", photoResponse.ExtractOriginalTags());

            if (preferences.NeedLocationMetadata)
            {
                photo.Location = photoResponse.ExtractLocationDetails();
            }

            return(photo);
        }
コード例 #2
0
        public async Task <User> PopulateUserInfo(User user)
        {
            var exraParams = new Dictionary <string, string>
            {
                {
                    ParameterNames.UserId, user.UserNsId
                }
            };

            dynamic userWithUserInfo = await _oAuthManager.MakeAuthenticatedRequestAsync(Methods.PeopleGetInfo, exraParams);

            var userInfo = (Dictionary <string, object>)userWithUserInfo["person"];

            user.Info = new UserInfo
            {
                Id         = user.UserNsId,
                IsPro      = Convert.ToBoolean(userInfo["ispro"]),
                IconServer = userInfo["iconserver"].ToString(),
                IconFarm   = int.Parse(userInfo["iconfarm"].ToString()),
                PathAlias  =
                    userInfo["path_alias"] == null
            ? string.Empty
            : userInfo["path_alias"].ToString(),
                Description = userInfo.GetSubValue("description").ToString(),
                PhotosUrl   = userInfo.GetSubValue("photosurl").ToString(),
                ProfileUrl  = userInfo.GetSubValue("profileurl").ToString(),
                MobileUrl   = userInfo.GetSubValue("mobileurl").ToString(),
                PhotosCount = int.Parse(((Dictionary <string, object>)userInfo["photos"]).GetSubValue("count").ToString())
            };

            return(user);
        }
コード例 #3
0
        public async Task <PhotosResponse> GetPhotosAsync(string methodName, User user, Preferences preferences, int page,
                                                          IProgress <ProgressUpdate> progress)
        {
            var progressUpdate = new ProgressUpdate {
                OperationText = "Getting list of photos...",
                ShowPercent   = false
            };

            progress.Report(progressUpdate);

            var extraParams = new Dictionary <string, string> {
                {
                    ParameterNames.UserId, user.UserNsId
                }, {
                    ParameterNames.SafeSearch, preferences.SafetyLevel
                }, {
                    ParameterNames.PerPage,
                    preferences.PhotosPerPage.ToString(CultureInfo.InvariantCulture)
                }, {
                    ParameterNames.Page, page.ToString(CultureInfo.InvariantCulture)
                }
            };

            var photosResponse = (Dictionary <string, object>)
                                 await _oAuthManager.MakeAuthenticatedRequestAsync(methodName, extraParams);

            return(photosResponse.GetPhotosResponseFromDictionary());
        }
コード例 #4
0
        public async Task <PhotosResponse> GetPhotosAsync(Photoset photoset, User user, Preferences preferences, int page,
                                                          IProgress <ProgressUpdate> progress, string albumProgress = null)
        {
            var isGettingAlbumPhotos = !string.IsNullOrEmpty(albumProgress);
            var progressUpdate       = new ProgressUpdate
            {
                OperationText = isGettingAlbumPhotos ? "Getting photos in album..." : "Getting list of photos...",
                ShowPercent   = isGettingAlbumPhotos,
                PercentDone   = 0,
                AlbumProgress = albumProgress
            };

            progress.Report(progressUpdate);

            var methodName = GetPhotosetMethodName(photoset.Type);

            var extraParams = new Dictionary <string, string>
            {
                {
                    ParameterNames.UserId, user.UserNsId
                },
                {
                    ParameterNames.SafeSearch, preferences.SafetyLevel
                },
                {
                    ParameterNames.PerPage,
                    preferences.PhotosPerPage.ToString(CultureInfo.InvariantCulture)
                },
                {
                    ParameterNames.Page, page.ToString(CultureInfo.InvariantCulture)
                }
            };

            var isAlbum = photoset.Type == PhotosetType.Album;

            if (isAlbum)
            {
                extraParams.Add(ParameterNames.PhotosetId, photoset.Id);
            }

            var photosResponse = (Dictionary <string, object>)
                                 await _oAuthManager.MakeAuthenticatedRequestAsync(methodName, extraParams);

            return(photosResponse.GetPhotosResponseFromDictionary(isAlbum));
        }
コード例 #5
0
        public async Task <bool> IsUserLoggedInAsync(Action <User> applyUser)
        {
            _applyUser = applyUser;
            var token = _tokenRepository.Get();
            var user  = _userRepository.Get();

            if (string.IsNullOrEmpty(token.TokenString))
            {
                return(false);
            }

            _oAuthManager.AccessToken = token.TokenString;
            var testLogin =
                (Dictionary <string, object>) await _oAuthManager.MakeAuthenticatedRequestAsync(Methods.TestLogin);

            var userIsLoggedIn = (string)testLogin.GetSubValue("user", "id") == user.UserNsId;

            if (userIsLoggedIn)
            {
                CallApplyUser(user);
            }
            return(userIsLoggedIn);
        }