Esempio n. 1
0
        public void RunAllSearches()
        {
            var appinfo = _twitterAppLogic.GetItem(1);

            if (appinfo.RateLimitRemaining < 10)
            {
                //wait 65 seconds so that hopefully everything is all reset and happy and such as
                Thread.Sleep(65000);
            }

            foreach (var search in _searchLogic.GetItems(SearchDependencies.Logs))
            {
                //search tweets
                var results = _twitterSearchRepository.Search(search.ToQuery(), search.ResultType, search.LastLog == null ? 0 : search.LastLog.LastTweetId, appinfo);

                //add a record to the history log
                var lastlog = new SearchHistoryLog()
                {
                    LastTweetId = results.LastId, SearchDate = DateTime.UtcNow, SearchId = search.SearchId, TweetCount = results.SearchResult.Statuses.Count()
                };
                _searchHistoryLogicRepository.Insert(lastlog);

                //update app info with last rate limit status
                appinfo.LastAccessedDTM    = DateTime.UtcNow;
                appinfo.RateLimitRemaining = results.RateLimitStatus.HourlyLimit = results.RateLimitStatus.RemainingHits;
                _twitterAppLogic.SaveOrUpdate(appinfo);


                //map tweets to domain model
                var tweets = Mapper.Map <List <TwitterStatus>, List <Tweet> >(results.SearchResult.Statuses.ToList());


                //persist tweets to database
                _tweetsLogic.PersistTweets(tweets, search.SearchId);
            }
        }