public string ExecuteMultipartQuery(string queryURL, string contentId, HttpMethod httpMethod, IEnumerable<byte[]> binaries)
        {
            CleanupQueryURL(ref queryURL);
            var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerOption;
            
            ITwitterQuery twitterQuery;
            if (!TryPrepareRequest(queryURL, httpMethod, rateLimitTrackerOption, null, out twitterQuery))
            {
                return null;
            }

            try
            {
                var jsonResult = _twitterRequester.ExecuteMultipartQuery(twitterQuery, contentId, binaries);

                QueryCompleted(twitterQuery, jsonResult, rateLimitTrackerOption);

                return jsonResult;
            }
            catch (TwitterException ex)
            {
                HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery);

                throw;
            }
        }
        public string ExecuteMultipartQuery(string queryURL, string contentId, HttpMethod httpMethod, IEnumerable <byte[]> binaries)
        {
            CleanupQueryURL(ref queryURL);
            var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerOption;

            ITwitterQuery twitterQuery;

            if (!TryPrepareRequest(queryURL, httpMethod, rateLimitTrackerOption, null, out twitterQuery))
            {
                return(null);
            }

            try
            {
                var jsonResult = _twitterRequester.ExecuteMultipartQuery(twitterQuery, contentId, binaries);

                QueryCompleted(twitterQuery, jsonResult, rateLimitTrackerOption);

                return(jsonResult);
            }
            catch (TwitterException ex)
            {
                HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery);

                throw;
            }
        }
        public string ExecuteQuery(
            string queryURL, 
            HttpMethod httpMethod, 
            TwitterClientHandler handler = null,
            ITwitterCredentials credentials = null)
        {
            CleanupQueryURL(ref queryURL);
            var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerOption;
            
            ITwitterQuery twitterQuery;
            if (!TryPrepareRequest(queryURL, httpMethod, rateLimitTrackerOption, credentials, out twitterQuery))
            {
                return null;
            }

            try
            {
                var jsonResult = _twitterRequester.ExecuteQuery(twitterQuery, handler);

                QueryCompleted(twitterQuery, jsonResult, rateLimitTrackerOption);

                return jsonResult;
            }
            catch (TwitterException ex)
            {
                HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery);
                
                throw;
            }
        }
        public string ExecuteQuery(
            string queryURL,
            HttpMethod httpMethod,
            TwitterClientHandler handler    = null,
            ITwitterCredentials credentials = null)
        {
            CleanupQueryURL(ref queryURL);
            var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerOption;

            ITwitterQuery twitterQuery;

            if (!TryPrepareRequest(queryURL, httpMethod, rateLimitTrackerOption, credentials, out twitterQuery))
            {
                return(null);
            }

            try
            {
                var jsonResult = _twitterRequester.ExecuteQuery(twitterQuery, handler);

                QueryCompleted(twitterQuery, jsonResult, rateLimitTrackerOption);

                return(jsonResult);
            }
            catch (TwitterException ex)
            {
                HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery);

                throw;
            }
        }
        private bool TryPrepareRequest(
            string query,
            HttpMethod httpMethod,
            RateLimitTrackerOptions rateLimitTrackerOption,
            ITwitterCredentials credentials,
            out ITwitterQuery twitterQuery)
        {
            twitterQuery = _twitterQueryFactory.Create(query, httpMethod, credentials ?? _credentialsAccessor.CurrentThreadCredentials);

            var beforeQueryExecuteEventArgs = new QueryBeforeExecuteEventArgs(twitterQuery);

            _tweetinviEvents.RaiseBeforeQueryExecute(beforeQueryExecuteEventArgs);

            if (beforeQueryExecuteEventArgs.Cancel)
            {
                twitterQuery = null;
                return(false);
            }

            if (rateLimitTrackerOption == RateLimitTrackerOptions.TrackAndAwait)
            {
                _rateLimitAwaiter.WaitForCurrentCredentialsRateLimit(query);
            }

            return(true);
        }
        private bool TryPrepareRequest(
            string query,
            HttpMethod httpMethod,
            RateLimitTrackerOptions rateLimitTrackerOption,
            ITwitterCredentials credentials,
            out ITwitterQuery twitterQuery)
        {
            credentials = credentials ?? _credentialsAccessor.CurrentThreadCredentials;

            if (credentials == null)
            {
                throw new TwitterNullCredentialsException();
            }

            twitterQuery = _twitterQueryFactory.Create(query, httpMethod, credentials);

            var beforeQueryExecuteEventArgs = new QueryBeforeExecuteEventArgs(twitterQuery);


            if (rateLimitTrackerOption == RateLimitTrackerOptions.TrackOnly ||
                rateLimitTrackerOption == RateLimitTrackerOptions.TrackAndAwait)
            {
                var timeToWait = _rateLimitAwaiter.TimeToWaitBeforeTwitterRequest(query, twitterQuery.TwitterCredentials);

                twitterQuery.DateWhenCredentialsWillHaveRequiredRateLimits = DateTime.Now.AddMilliseconds(timeToWait);
                _tweetinviEvents.RaiseBeforeQueryExecute(beforeQueryExecuteEventArgs);

                if (beforeQueryExecuteEventArgs.Cancel)
                {
                    twitterQuery = null;
                    return(false);
                }

                if (rateLimitTrackerOption == RateLimitTrackerOptions.TrackAndAwait)
                {
                    _rateLimitAwaiter.Wait(timeToWait);
                }
            }
            else
            {
                _tweetinviEvents.RaiseBeforeQueryExecute(beforeQueryExecuteEventArgs);

                if (beforeQueryExecuteEventArgs.Cancel)
                {
                    twitterQuery = null;
                    return(false);
                }
            }

            _tweetinviEvents.RaiseBeforeExecuteAfterRateLimitAwait(beforeQueryExecuteEventArgs);

            return(true);
        }
        private bool TryPrepareRequest(
            string query, 
            HttpMethod httpMethod, 
            RateLimitTrackerOptions rateLimitTrackerOption,
            ITwitterCredentials credentials,
            out ITwitterQuery twitterQuery)
        {
            credentials = credentials ?? _credentialsAccessor.CurrentThreadCredentials;

            if (credentials == null)
            {
                throw new TwitterNullCredentialsException();
            }

            twitterQuery = _twitterQueryFactory.Create(query, httpMethod, credentials);

            var beforeQueryExecuteEventArgs = new QueryBeforeExecuteEventArgs(twitterQuery);


            if (rateLimitTrackerOption == RateLimitTrackerOptions.TrackOnly ||
                rateLimitTrackerOption == RateLimitTrackerOptions.TrackAndAwait)
            {
                var timeToWait = _rateLimitAwaiter.TimeToWaitBeforeTwitterRequest(query, twitterQuery.TwitterCredentials);

                twitterQuery.DateWhenCredentialsWillHaveRequiredRateLimits = DateTime.Now.AddMilliseconds(timeToWait);
                _tweetinviEvents.RaiseBeforeQueryExecute(beforeQueryExecuteEventArgs);

                if (beforeQueryExecuteEventArgs.Cancel)
                {
                    twitterQuery = null;
                    return false;
                }

                if (rateLimitTrackerOption == RateLimitTrackerOptions.TrackAndAwait)
                {
                    _rateLimitAwaiter.Wait(timeToWait);
                }
            }
            else
            {
                _tweetinviEvents.RaiseBeforeQueryExecute(beforeQueryExecuteEventArgs);

                if (beforeQueryExecuteEventArgs.Cancel)
                {
                    twitterQuery = null;
                    return false;
                }
            }

            _tweetinviEvents.RaiseBeforeExecuteAfterRateLimitAwait(beforeQueryExecuteEventArgs);

            return true;
        }
Example #8
0
        private bool TryPrepareRequest(
            string query, 
            HttpMethod httpMethod, 
            RateLimitTrackerOptions rateLimitTrackerOption,
            ITwitterCredentials credentials,
            out ITwitterQuery twitterQuery)
        {
            twitterQuery = _twitterQueryFactory.Create(query, httpMethod, credentials ?? _credentialsAccessor.CurrentThreadCredentials);

            var beforeQueryExecuteEventArgs = new QueryBeforeExecuteEventArgs(twitterQuery);
            _tweetinviEvents.RaiseBeforeQueryExecute(beforeQueryExecuteEventArgs);

            if (beforeQueryExecuteEventArgs.Cancel)
            {
                twitterQuery = null;
                return false;
            }

            if (rateLimitTrackerOption == RateLimitTrackerOptions.TrackAndAwait)
            {
                _rateLimitAwaiter.WaitForCurrentCredentialsRateLimit(query);
            }

            return true;
        }