Exemplo n.º 1
0
        /// <summary>
        /// Checks if the user exists in Twitter.
        /// If Exists, returns the user details else returns exception
        /// </summary>
        /// <param name="twitterUserScreenName"></param>
        /// <param name="siteId"></param>
        /// <returns></returns>
        private string IsValidTwitterUser(string twitterUserScreenName, int siteId)
        {
            MemberList memberList = null;
            var twitterException = string.Empty;
            var _isValidTwitterScreenName = string.Empty;
            try
            {
                memberList = new MemberList(base.InputContext);

                TweetUsers tweetUser = memberList.RetrieveTweetUserDetails(twitterUserScreenName);
                
                if (tweetUser.TwitterResponseException != null)
                {
                    var twitterRateLimitException = "rate limit exceeded.";
                    var twitterErrorNotFound = "the remote server returned an error: (404) not found.";
                    var twitterUnexpectedResponseException = "the remote server returned an unexpected response: (400) bad request.";

                    if (tweetUser.TwitterResponseException.Message.ToLower().Contains(twitterRateLimitException))
                    {
                        twitterException = "Twitter Exception: Twitter API has reached its rate limit. Please try again later.";
                    }
                    else if (tweetUser.TwitterResponseException.Message.ToLower().Equals(twitterErrorNotFound) ||
                        tweetUser.TwitterResponseException.InnerException.Message.ToLower().Equals(twitterErrorNotFound))
                    {
                        twitterException = "Twitter Error: Searched user not found in Twitter";
                    }
                    else if (tweetUser.TwitterResponseException.Message.ToLower().Equals(twitterUnexpectedResponseException))
                    {
                        twitterException = "Twitter Exception: " + tweetUser.TwitterResponseException.Message + " Please try again in few minutes.";
                    }
                    else
                    {
                        twitterException = "Twitter Exception: " + tweetUser.TwitterResponseException.Message;
                    }

                    _isValidTwitterScreenName = twitterException;
                }
                else
                {
                    _isValidTwitterScreenName = tweetUser.id;

                    //Creating the twitter user in DNA
                    ICacheManager cacheManager = CacheFactory.GetCacheManager();

                    var callingUser = new CallingTwitterUser(this.readerCreator, this.dnaDiagnostic, cacheManager);

                    //Create the twitter user and map it to DNA with the site the profile and the forum is created
                    callingUser.CreateUserFromTwitterUser(siteId, tweetUser);
                    callingUser.SynchroniseSiteSuffix(tweetUser.ProfileImageUrl);
                }
           
            }
            finally
            {
                memberList = null;
            }
            return _isValidTwitterScreenName;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a twitter user and returns the twitter user details
        /// </summary>
        /// <param name="site"></param>
        /// <param name="tweet"></param>
        /// <returns></returns>
        private CallingTwitterUser GetCallingTwitterUser(ISite site, Tweet tweet)
        {
            var callingTwitterUser = new CallingTwitterUser(readerCreator, dnaDiagnostic, cacheManager);

            callingTwitterUser.CreateUserFromTwitterUser(site.SiteID, tweet.user);
            callingTwitterUser.SynchroniseSiteSuffix(tweet.user.ProfileImageUrl);

            return callingTwitterUser;
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method creates and maps the twitter user to a DNA User ID and retrieve the created twitter user details
        /// </summary>
        /// <param name="searchText"></param>
        /// <param name="dataReader"></param>
        private string CreateRetrieveTwitterUser(string searchText, IDnaDataReader dataReader)
        {
            //TODO: Call the twitter api to get the user details
            TwitterClient client;
            TweetUsers tweetUser;
            //var twitterAPIException = string.Empty;
            var twitterException = string.Empty;
            try
            {
                client = new TwitterClient();
                tweetUser = new TweetUsers();

                //tweetUser = client.GetUserDetails(searchText);
                tweetUser = client.GetUserDetailsByScrapping(searchText);

                // Create the twitter user with the associated dnauserid in DNA
                if (tweetUser != null)
                {
                    ICacheManager cacheManager = CacheFactory.GetCacheManager();

                    var callingUser = new CallingTwitterUser(this.readerCreator, this.dnaDiagnostic, cacheManager);

                    //Create the twitter user and map it to DNA with site id 1
                    callingUser.CreateUserFromTwitterUser(1, tweetUser);
                    callingUser.SynchroniseSiteSuffix(tweetUser.ProfileImageUrl);

                    if (dataReader != null)
                    {
                        dataReader.Execute();
                    }
                }
            }
            catch (Exception ex)
            {
                InputContext.Diagnostics.WriteExceptionToLog(ex);

                var twitterRateLimitException = "Rate limit exceeded.";
                var twitterErrorNotFound = "The remote server returned an error: (404) Not Found.";
                var twitterUnexpectedResponseException = "The remote server returned an unexpected response: (400) Bad Request.";

                if (ex.Message.Contains(twitterRateLimitException))
                {
                    twitterException = "Twitter API has reached its rate limit. Please try again later.";
                }
                else if (ex.Message.Equals(twitterErrorNotFound) ||
                    ex.InnerException.Message.Equals(twitterErrorNotFound))
                {
                    twitterException = "Searched user not found in Twitter";
                }
                else if (ex.Message.Equals(twitterUnexpectedResponseException))
                {
                    twitterException = "Twitter Exception: " + ex.Message + " Please try again in few minutes.";
                }
                else
                {
                    twitterException = "Twitter Exception: " + ex.Message;
                }
            }

            return twitterException;
        }