public void TestAddRange() { // Set up data bool success = false; var tweet1 = new Tweet() { Text = "test tweet 1", Timestamp = new DateTime(2014, 1, 1, 12, 0, 0), }; var tweet2 = new Tweet() { Text = "test tweet 2", Timestamp = new DateTime(2014, 1, 1, 12, 30, 0), }; List<Tweet> tweets = new List<Tweet>() { tweet1, tweet2 }; // Execute using (var repository = new TweetRepository()) { success = repository.AddRange(tweets); } // Validate Assert.IsTrue(success); }
public bool Mine() { // Get all games whos tweets need indexing using (var repository = new GameRepository()) { Games = (from game in repository.DataSet.Include("HomeTeam.Hashtags").Include("AwayTeam.Hashtags") where game.TweetsRetrieved != RetrievalStatus.COMPLETED && game.EventsRetrieved == RetrievalStatus.COMPLETED && game.MatchDay >= MinGameDay select game).OrderByDescending(g => g.Start).ToList(); } foreach (Game game in Games) { long tweetCount = 0; _statuses = new ConcurrentQueue<List<Status>>(); _completed = false; Console.Out.WriteLine(String.Format("Mining tweets from {0} vs {1}{2}Start Time: {3}{2}", game.HomeTeam.Name, game.AwayTeam.Name, Environment.NewLine, game.Start)); ScrapeTweets(game); while (!_completed) { List<Status> recieved = null; if (_statuses.TryDequeue(out recieved)) { // work to do var tweets = from status in recieved select new Tweet() { Timestamp = BSTDateTime.FromBSTDateTime(status.CreatedAt), Text = status.Text, TwitterId = (long)status.StatusID, Longitude = status.Coordinates.Longitude, Latitude = status.Coordinates.Latitude, RetweetCount = status.RetweetCount, Images = (from media in status.Entities.MediaEntities select new Image() { Url = media.MediaUrl, GameId = game.Id }).ToList(), GameId = game.Id }; tweetCount += tweets.Count(); if (game.TweetsRetrieved == RetrievalStatus.NONE) { // update game status if nessessary game.TweetsRetrieved = RetrievalStatus.IN_PROGRESS; using (var repository = new GameRepository()) { repository.Update(game); } } using (var repository = new TweetRepository()) { repository.AddRange(tweets); } } else { // no work to do Thread.Sleep(2500); } } // update the game status game.TweetsRetrieved = RetrievalStatus.COMPLETED; game.TweetCount = tweetCount; using (var repository = new GameRepository()) { repository.Update(game); } // update the activity chart try { ActivityChartManager.UpdateGame(game); } catch (Exception e) { Console.Out.WriteLine(String.Format("An error occured while creating chart points:{0}{1}", Environment.NewLine, e.Message)); } Console.Out.WriteLine(String.Format("{0} vs {1} tweet mining compeleted{2}", game.HomeTeam.Name, game.AwayTeam.Name, Environment.NewLine)); } return true; }