Exemplo n.º 1
0
        /// <summary>
        /// Access the profile image in various sizes for the user with the indicated screenName.
        /// If no size is provided the normal image is returned.
        /// </summary>
        /// <param name="screenName"></param>
        /// <param name="profileImageSize"></param>
        /// <returns></returns>
        /// <remarks>
        /// This method should only be used by application developers to lookup or check the profile image URL
        /// for a user. This method must not be used as the image source URL presented to users of your application.
        /// </remarks>
        public Uri RetrieveProfileImageUri(string screenName, ProfileImageSize profileImageSize = ProfileImageSize.Normal)
        {
            if (String.IsNullOrEmpty(screenName))
            {
                throw new ArgumentException();
            }

            var uri = new Uri(this.CommandBaseUri + String.Format("/profile_image/{0}.json?size={1}",
                                                                  screenName,
                                                                  profileImageSize.ToString().ToLowerInvariant()));

            var response = this.TwitterApi.ExecuteUnauthenticatedRequest(uri);
            var pattern  = @"(?<Protocol>\w+):\/\/(?<Domain>[\w@][\w.:@]+)\/?[\w\.?=%&=\-@/$,]*";
            var match    = Regex.Match(response, pattern);

            if (!match.Success)
            {
                throw new TwitterException("Unrecognized response.\n Server Response: \n" + response);
            }

            return(new Uri(match.Value));
        }
 public static string CalculateUserProfileImagePath(int userId, ProfileImageSize profileImageSize, string fileExtension)
 {
     return($"{AppConfigurationManager.AppDirectory}\\Users\\{userId}\\ProfileImage\\{profileImageSize.ToString()}{fileExtension}");
 }
        public static bool TryGetUserProfileImagePath(int userId, ProfileImageSize profileImageSize, out string userProfileImagePath, string fileExtensionsToSearch = "jpeg,png")
        {
            var extensions = fileExtensionsToSearch.Split(',');

            foreach (var ext in extensions)
            {
                var path = $"{AppDirectoryManager.GetUserProfileImageDirectory(userId)}\\{profileImageSize.ToString()}.{ext}";
                if (File.Exists(path))
                {
                    userProfileImagePath = path;
                    return(true);
                }
            }

            userProfileImagePath = null;
            return(false);
        }