public static void UpdateGame(Game game)
        {
            List<ActivityPoint> points = null;

            using (var repository = new TweetRepository())
            {
                points = (from tweet in repository.GetAll().AsParallel()
                          where tweet.GameId == game.Id
                          group tweet by tweet.Timestamp.AddSeconds(-tweet.Timestamp.Second) into minute
                          select new ActivityPoint()
                          {
                              Time = minute.Key,
                              GameId = game.Id,
                              TweetCount = minute.Count()
                          }).ToList();
            }

            using (var repository = new ActivityRepository())
            {
                if (!repository.AddRange(points))
                {
                    Console.WriteLine("Error occurred with saving points");
                }
            }
        }
Esempio n. 2
0
        public ActionResult DeleteTweet(int id)
        {
            var repository = new TweetRepository();

            repository.DeleteTweet(id);
            return(RedirectToAction("MyProfile", "Twitter"));
        }
        public TweetPoster(TweetRepository tweetRepository)
        {
            _tweetService    = new TweetService();
            _tweetRepository = tweetRepository;

            Task.Factory.StartNew(PostTweetsInBackGround);
        }
Esempio n. 4
0
        /// <summary>
        /// 現在読み込まれているツイートより前のツイートを読み込みます。
        /// </summary>
        /// <returns>非同期操作を示す <see cref="System.Threading.Tasks.Task"/>。</returns>
        public Task LoadPreviousAsync()
        {
            this.Dispatcher.BeginInvoke(() => this.RaiseAsyncStarted());
            var repository = new TweetRepository();
            var max        = this.Items.LastOrDefault();

            return(repository.GetAsync(maxId: max == null ? null : max.StatusId)
                   .ContinueWith(
                       task => this.Dispatcher.BeginInvoke(
                           parameter => {
                if (parameter != null)
                {
                    this.Items.AddRangeIf(parameter.OrderByDescending(x => x.StatusId), x => x.StatusId);
                    this.RaiseAsyncCompleted();
                }
                else
                {
                    this.RaiseAsyncError(null);
                }
            },
                           task.Result),
                       TaskContinuationOptions.OnlyOnRanToCompletion)
                   .ContinueWith(
                       task => this.Dispatcher.BeginInvoke(() => this.RaiseAsyncError(task.Exception)),
                       TaskContinuationOptions.NotOnRanToCompletion));
        }
        //[TestMethod]
        public void createalogofMessages()
        {
            /*
             * All tests start with a clean file to work against to ensure that no test affects any other.
             * This method creates the tweets file, removes the following files and creates a clean slate
             * for the subsequent test.
             *
             */

            //get rid of the server/file if it exists..
            TweetRepository.Deleterepository();

            //Set up an array to contain a set of messages
            TweetMessageWriter tmw = new TweetMessageWriter();

            //create those message and add them to the collection
            tmw.writeMessage(new tweetyMessage("Alice", "I love the weather today"));
            tmw.writeMessage(new tweetyMessage("Bob", "Damn! We lost!"));
            tmw.writeMessage(new tweetyMessage("Bob", "Good game though."));
            tmw.writeMessage(new tweetyMessage("Charlie", "I'm in New York today! Anyone want to have a coffee?"));

            tweetMessageReader tmr = new tweetMessageReader();

            Trace.WriteLine(tmr.ToString());
        }
        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);
        }
Esempio n. 7
0
 public TweetService(TweetDto tweetDto, IMapper mapper, MemberDto memberDto, TweetRepository tweetRepository, Tweet tweet)
 {
     _tweetDto        = tweetDto;
     _mapper          = mapper;
     _memberDto       = memberDto;
     _tweetRepository = tweetRepository;
     _tweet           = tweet;
 }
Esempio n. 8
0
        public void TestCommentWithGreaterAs()
        {
            Tweet tweet;

            TweetRepository.GetFromLine("Alan> If you have a procedure with > 10 parameters, you probably missed some.", 0, out tweet);
            Assert.AreEqual("Alan", tweet.Username);
            Assert.AreEqual("If you have a procedure with > 10 parameters, you probably missed some.", tweet.Comment);
        }
Esempio n. 9
0
        public ActionResult EditTweet(int id)
        {
            var repository = new TweetRepository();
            var tweetObj   = repository.FindTweet(id);
            var tweetModel = new TweetsViewModel {
                user_id = tweetObj.Useridd, tweet_id = tweetObj.tweet_id, message = tweetObj.usermessage, created = tweetObj.created
            };

            return(View(tweetModel));
        }
Esempio n. 10
0
        public object DeleteAll()
        {
            var entities = TweetRepository.GetAll().ToList();

            foreach (var entity in entities)
            {
                TweetRepository.Delete(entity);
            }
            return(entities.Count);
        }
 public void DeleteTweetFile()
 {
     try
     {
         TweetRepository.Deleterepository();
     }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
 public Tweet Get(long tweetId)
 {
     Tweet tweet = null;
     using (var repository = new TweetRepository())
     {
         tweet = (from t in repository.GetAll()
                  where t.Id == tweetId
                  select t).SingleOrDefault();
     }
     return tweet;
 }
        public void GetLatestTweetsForScreenName_ShouldReturn10Tweets_WhenProvidedSalesforceScreenName()
        {
            //Arrange
            TwitterAuthorizer auth = new TwitterAuthorizer(GetAppKeyConfigOptions());
            TweetRepository   rep  = new TweetRepository(auth);

            //Act
            List <Tweet> tweets = rep.GetLatestTweetsForScreenName(10, "salesforce", 150);

            //Assert
            Assert.AreEqual(10, tweets.Count);
        }
        public TweetListViewModel(string name, TweetRepository tweetRepository, ITweetFilter filter)
        {
            _tweetRepository = tweetRepository;
            _filter = filter;
            Name = name;
            Tweets =
                new ObservableCollection<TweetViewModel>(
                    _tweetRepository.GetAll()
                        .Select(t => new TweetViewModel(t, _tweetRepository))
                        .OrderBy(t => t.ScheduledDateTime));

            tweetRepository.TweetAddedUpdatedOrDeleted += TweetRepository_TweetAddedUpdatedOrDeleted;
        }
        public IEnumerable<Tweet> Get(long gameId, int limit)
        {
            List<Tweet> tweets = null;
            using (var repository = new TweetRepository())
            {
                tweets = (from tweet in repository.GetAll()
                          where tweet.GameId == gameId
                          && tweet.RetweetCount.HasValue && !tweet.Text.StartsWith("RT ")
                          select tweet).OrderByDescending(t => t.RetweetCount).Take(limit).OrderBy(t => t.Timestamp).ToList();
            }

            return tweets;
        }
        public TweetViewModel(Tweet tweet, TweetRepository tweetRepository)
        {
            Id                = tweet.Id;
            Status            = tweet.Status;
            ScheduledDateTime = tweet.ScheduledDateTime;
            MediaUrls         = tweet.MediaUrls;
            Posted            = tweet.Posted;

            _tweetRepository = tweetRepository;

            EditButtonClickCommand   = new RelayCommand <TweetViewModel>(EditTweet);
            DeleteButtonClickCommand = new RelayCommand <TweetViewModel>(DeleteTweet);
        }
 public IEnumerable<IEnumerable<object>> Get(long gameId, long tweetsPerMin)
 {
     using (var repository = new TweetRepository())
     {
         var minGroups = (from tweet in repository.DataSet.Include("Images")
                          where tweet.GameId == gameId
                          && tweet.RetweetCount.HasValue && !tweet.Text.StartsWith("RT ")
                          group tweet by SqlFunctions.DateAdd("second", -tweet.Timestamp.Second, tweet.Timestamp) into minute
                          select minute.OrderByDescending(t => t.RetweetCount).Take(5)
                          .Select(t => new { Tweet = t, Url = t.Images.FirstOrDefault().Url })
                          .ToList()).ToList();
         return minGroups.OrderBy(m => m[0].Tweet.Timestamp).ToList();
     }
 }
        public void Can_Add_Tweet_Json()
        {
            var expected = new Tweet
            {
                Json = Guid.NewGuid().ToString()
            };

            var repo = new TweetRepository();

            repo.Add(expected);

            Assert.IsTrue(repo.Tweets.Count() == 1);
            Assert.AreEqual(expected.Json, repo.Tweets.FirstOrDefault()?.Json);
        }
Esempio n. 19
0
        // GET: Twitter

        public ActionResult Home()
        {
            var repository = new TweetRepository();
            var objTweets  = repository.GetAllTweets();
            var tweetModel = new List <TweetsViewModel>();

            foreach (var item in objTweets)
            {
                tweetModel.Add(new TweetsViewModel {
                    user_id = item.Useridd, tweet_id = item.tweet_id, message = item.usermessage, created = item.created
                });
            }
            return(View(tweetModel));
        }
        public static void Main()
        {
            IWriter          writer    = new ConsoleWriter();
            ITweetRepository tweetRepo = new TweetRepository();

            var client = new Client(writer, tweetRepo);
            var tweet  = new Tweet(client);

            tweet.ReceiveMessage("This is a tweet");
            tweet.ReceiveMessage("Yet another tweet");
            tweet.ReceiveMessage("More dummy messages");
            tweet.ReceiveMessage("Dummy message 4");
            tweet.ReceiveMessage("Last dummy message");
        }
        public async void ProcessTweetStream(CancellationToken stoppingToken)
        {
            Logger.LogDebug($"ApiKey: {ApiKey}");
            Logger.LogDebug($"ApiSecret: {ApiSecret}");
            Logger.LogDebug($"BearerToken: {BearerToken}");

            if (string.IsNullOrWhiteSpace(ApiKey) ||
                string.IsNullOrWhiteSpace(ApiSecret) ||
                string.IsNullOrWhiteSpace(BearerToken))
            {
                var errorMessage = "One or all of the following are missing configuration: " +
                                   "ApiKey, BearerToken and ApiUrl.";
                Logger.LogCritical(errorMessage);
                throw new Exception(errorMessage);
            }

            try
            {
                // Use this if passed through... <= 0 is no limit (Great for testing)
                var maxTweetCount = Configuration.GetValue <short>(
                    "TwitterApi:MaxTweetCount", -1);

                InitializeTweetMapper();
                EmojiParser.Initialize();

                var client = new TwitterClient(ApiKey, ApiSecret, BearerToken);
                client.Config.TweetMode = TweetMode.Extended;
                if (maxTweetCount > 0)
                {
                    client.Config.Limits.MESSAGES_GET_MAX_PAGE_SIZE = maxTweetCount;
                }

                var sampleStream = client.StreamsV2.CreateSampleStream();
                sampleStream.TweetReceived += (sender, args) =>
                {
                    var tweet = TweetMapper.Map <TweetV2, Data.Model.Tweet>(args.Tweet);
                    tweet.Json   = args.Json;
                    tweet.Emojis = EmojiParser.Parse(tweet.Text);
                    TweetRepository.Add(tweet);
                };

                await sampleStream.StartAsync();
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Error downloading tweet stream.");
                throw;
            }
        }
Esempio n. 22
0
        // GET: Blogs
        public ActionResult Index()
        {
            var repository = new TweetRepository();
            var objTweets  = repository.GetAllTweets();
            var tweetModel = new List <TweetViewModel>();

            foreach (var item in objTweets)
            {
                tweetModel.Add(new TweetViewModel {
                    userid = item.userid, TweetID = item.TweetID, message = item.message, created = item.created
                });
            }

            return(View(tweetModel));
        }
Esempio n. 23
0
        public ActionResult MyProfile()
        {
            string userID     = User.Identity.Name;
            var    repository = new TweetRepository();
            var    objTweets  = repository.GetTweetsByName(userID);
            var    tweetModel = new List <TweetsViewModel>();

            foreach (var item in objTweets)
            {
                tweetModel.Add(new TweetsViewModel {
                    user_id = item.Useridd, tweet_id = item.tweet_id, message = item.usermessage, created = item.created
                });
            }
            return(View(tweetModel));
        }
        public EditTweetWindowViewModel(TweetViewModel tweetViewModel, TweetRepository tweetRepository)
        {
            _tweetViewModel  = tweetViewModel;
            _tweetRepository = tweetRepository;

            Status = tweetViewModel.Status;

            if (tweetViewModel.MediaUrls != null)
            {
                MediaUrls = string.Join("\n", tweetViewModel.MediaUrls);
            }

            ScheduledDateTime = tweetViewModel.ScheduledDateTime;

            WindowClosingCommand = new RelayCommand(SaveTweetAndCloseWindow);
        }
Esempio n. 25
0
 public async Task SaveTweetsAsync(List <TweetModel> tweets)
 {
     try
     {
         await Task.Run(() => {
             if (Tweets.Count > 0)
             {
                 TweetRepository.SaveListOfTweets(tweets);
             }
         });
     }
     catch (Exception ex)
     {
         Logger.LogInformation($"Error at SaveTweetsAsync");
     }
 }
Esempio n. 26
0
        public void TestEmptyTweetsShouldBeIgnored()
        {
            Tweet tweet;
            var   added = TweetRepository.GetFromLine("Alan> ", 0, out tweet);

            Assert.IsFalse(added);

            added = TweetRepository.GetFromLine("Alan", 0, out tweet);
            Assert.IsFalse(added);

            added = TweetRepository.GetFromLine("", 0, out tweet);
            Assert.IsFalse(added);

            added = TweetRepository.GetFromLine(null, 0, out tweet);
            Assert.IsFalse(added);
        }
Esempio n. 27
0
        public ActionResult Tweet(TweetsViewModel objModel)
        {
            if (ModelState.IsValid)
            {
                var objTweet = new Tweet();
                objTweet.usermessage = objModel.message;
                objTweet.created     = DateTime.Now;
                objTweet.Useridd     = User.Identity.Name;


                var tRep = new TweetRepository();
                tRep.AddTweet(objTweet);

                ViewBag.msg = "Tweeted!!";
            }
            return(View(objModel));
        }
        public void GetLatestTweetsForScreenName_ShouldReturnTweetsForSalesforce_WhenProvidedSalesforceScreenName()
        {
            //Arrange
            TwitterAuthorizer auth = new TwitterAuthorizer(GetAppKeyConfigOptions());
            TweetRepository   rep  = new TweetRepository(auth);

            //Act
            List <Tweet> tweets = rep.GetLatestTweetsForScreenName(10, "salesforce", 150);
            List <Tweet> nonSalesForceTweets = tweets.Where(t => t.ScreenName != "salesforce").ToList();

            //Assert
            //there are tweets
            Assert.AreEqual(10, tweets.Count);

            //they are no tweets for another screen name
            Assert.AreEqual(0, nonSalesForceTweets.Count);
        }
        public void GetLatestTweetsForScreenName_ShouldReturnEmbeddedDetailsForTweet()
        {
            //Arrange
            TwitterAuthorizer auth = new TwitterAuthorizer(GetAppKeyConfigOptions());
            TweetRepository   rep  = new TweetRepository(auth);

            //Act
            List <Tweet> tweets = rep.GetLatestTweetsForScreenName(10, "salesforce", 150);
            List <Tweet> missingEmbeddedDetails = tweets.Where(t => t.HTMLForOEmbed == null || t.HTMLForOEmbed == string.Empty).ToList();

            //Assert
            //there are tweets
            Assert.AreEqual(10, tweets.Count);

            //they are no tweets for another screen name
            Assert.AreEqual(0, missingEmbeddedDetails.Count);
        }
        public MainWindowViewModel()
        {
            // TODO: should initialize in the project root or use DI/IOC
            _tweetRepository = new TweetRepository();
            _tweetPoster     = new TweetPoster(_tweetRepository);

            TweetsViewModelCollection = new ObservableCollection <TweetListViewModel>();
            TweetsViewModelCollection.Add(new TweetListViewModel("Unscheduled Tweets", _tweetRepository,
                                                                 new UnscheduledTweetFilter()));
            TweetsViewModelCollection.Add(new TweetListViewModel("Scheduled Tweets", _tweetRepository,
                                                                 new ScheduledTweetFilter()));
            TweetsViewModelCollection.Add(new TweetListViewModel("Posted Tweets", _tweetRepository,
                                                                 new PostedTweetFilter()));

            NewTweetCommand = new RelayCommand(AddTweet);

            DoubleClickTweetCommand = new RelayCommand <TweetViewModel>(EditTweet);
        }
Esempio n. 31
0
        public ActionResult create(TweetViewModel objModel)
        {
            if (ModelState.IsValid)
            {
                var objTweet = new Tweet();
                objTweet.TweetID = objModel.TweetID;
                objTweet.message = objModel.message;
                objTweet.userid  = User.Identity.Name;
                objTweet.created = DateTime.Now;

                //create repository
                var Repository = new TweetRepository();
                Repository.AddTweet(objTweet);

                ViewBag.Message = "Tweets sent for Request";
            }
            return(View(objModel));
        }
        public void TestAdd()
        {
            // Set up data
            long id = -1;
            var tweet = new Tweet()
            {
                Text = "test tweet",
                Timestamp = new DateTime(2014, 1, 1, 12, 0, 0),
            };

            // Execute
            using (var repository = new TweetRepository())
            {
                id = repository.Add(tweet);
            }

            // Validate
            Assert.AreNotEqual(-1, id);
        }
Esempio n. 33
0
        public ActionResult EditTweet(TweetsViewModel objTweetModel)
        {
            if (ModelState.IsValid)
            {
                var objTweet = new Tweet();
                objTweet.usermessage = objTweetModel.message;
                objTweet.created     = DateTime.Now;
                objTweet.Useridd     = User.Identity.Name;
                objTweet.tweet_id    = objTweetModel.tweet_id;

                var tRep = new TweetRepository();
                tRep.EditTweet(objTweet);
                ViewBag.msg = "Editted Successfully";
            }
            else
            {
                ViewBag.msg = "Error";
            }
            return(View(objTweetModel));
        }
        public void TestDelete()
        {
            // Set up data
            bool success = false;
            var tweet = new Tweet()
            {
                Text = "test tweet",
                Timestamp = new DateTime(2014, 1, 1, 12, 0, 0),
            };

            // Execute
            using (var repository = new TweetRepository())
            {
                tweet.Id = repository.Add(tweet);
                success = repository.Delete(tweet);
            }

            // Validate
            Assert.IsTrue(success);
        }
Esempio n. 35
0
 public static void ReadFeeds(string userFileName, string tweetFileName)
 {
     try
     {
         var users  = new UserRepository(userFileName).GetAll().OrderBy(p => p.Name);
         var tweets = new TweetRepository(tweetFileName).GetAll().ToLookup(p => p.Username.ToUpper());
         foreach (var user in users)
         {
             Console.WriteLine(user.Name);
             foreach (var tweet in GetTweetsForUser(user, tweets))
             {
                 Console.Write("\t@");
                 Console.Write(tweet.Username);
                 Console.Write(": ");
                 Console.WriteLine(tweet.Comment);
             }
         }
     }
     catch (Exception ex)
     {
         SimpleFileLogger.LogEvent("Read tweets exception", DateTime.Now, ex.Message, true);
     }
 }
        public void TestSave()
        {
            // Set up data
            string updatedText = "updated test tweet";
            var tweet = new Tweet()
            {
                Text = "test tweet",
                Timestamp = new DateTime(2014, 1, 1, 12, 0, 0),
            };

            // Execute
            using (var repository = new TweetRepository())
            {
                // Add
                tweet = repository.Save(tweet);
                tweet.Text = updatedText;
                // Update
                tweet = repository.Save(tweet);
            }

            // Validate
            Assert.IsTrue(tweet.Id > 0);
            Assert.AreEqual(updatedText, tweet.Text);
        }
Esempio n. 37
0
        private async void ScrapeTweets(Game game)
        {
            DateTime pointerTime, lastPrintTime, adjustedStart;
            ulong maxId;
            long counter = 0;

            string query = BuildQuery(game);

            // get the id of the closest tweet to full time
            if (game.TweetsRetrieved == RetrievalStatus.IN_PROGRESS)
            {
                using (var repository = new TweetRepository())
                {
                    var lastTweet = repository.GetAll()
                        .Where(tweet => tweet.GameId == game.Id)
                        .OrderBy(tweet => tweet.TwitterId)
                        .Take(1).First();
                    maxId = (ulong)lastTweet.TwitterId;
                    pointerTime = lastTweet.Timestamp;
                    lastPrintTime = lastTweet.Timestamp;
                }
            }
            else
            {
                Status lastStatus = null;
                while (true) {
                    try
                    {
                        // need to wrap this in try as this method can exceed rate limit as well
                        lastStatus = FindClosestTweetToTime(BSTDateTime.ToBSTDateTime(game.End.Value), query);
                        break;
                    }
                    catch (AggregateException e)
                    {
                        if (e.InnerException is TwitterQueryException)
                        {
                            // wait 15 mins and try again
                            Console.Out.WriteLine(String.Format("Rate limit hit. Sleeping for 15 mins from {0}{1}Zzz Zzz",
                                DateTime.Now, Environment.NewLine));
                            Thread.Sleep(1000 * 60 * 15);
                            Console.Out.WriteLine("Awake now, continuing...");
                        }
                    }
                }
                if (lastStatus == null)
                {
                    Console.Out.WriteLine(String.Format("Unable to find starting point for game.. Skipping..{0}",
                        Environment.NewLine));
                    _completed = true;
                    return;
                }
                maxId = lastStatus.StatusID;
                pointerTime = lastStatus.CreatedAt;
                lastPrintTime = lastStatus.CreatedAt;
            }

            // adjust times for british daylight savings
            pointerTime = BSTDateTime.ToBSTDateTime(pointerTime);
            lastPrintTime = BSTDateTime.ToBSTDateTime(lastPrintTime);
            adjustedStart = BSTDateTime.ToBSTDateTime(game.Start);

            while (adjustedStart < pointerTime)
            {
                try {
                    var resp = await (from search in Twitter.Search
                                      where search.Type == SearchType.Search
                                      && search.ResultType == ResultType.Recent
                                      && search.Query == query
                                      && search.Count == 100
                                      && search.MaxID == maxId
                                      select search).SingleOrDefaultAsync();


                    if (resp != null && resp.Statuses != null)
                    {
                        // update loop
                        Status earliest = resp.Statuses[resp.Statuses.Count - 1];
                        maxId = (ulong)earliest.StatusID;
                        counter += resp.Statuses.Count;
                        pointerTime = earliest.CreatedAt;
                        
                        // add the statuses to the queue
                        _statuses.Enqueue(resp.Statuses);
                    }
                    else
                    {
                        break;
                    }
                }
                catch (TwitterQueryException)
                {
                    Console.Out.WriteLine(String.Format("Rate limit hit. Sleeping for 15 mins from {0}{1}Zzz Zzz",
                        DateTime.Now, Environment.NewLine));
                    Thread.Sleep(1000 * 60 * 15);
                    Console.Out.WriteLine("Awake now, continuing...");
                    continue;
                }

                if ((lastPrintTime - pointerTime).Minutes > 1)
                {
                    Console.Out.WriteLine(String.Format("pointerTime: {0} tweets: {1}", BSTDateTime.FromBSTDateTime(pointerTime), counter));
                    lastPrintTime = pointerTime;
                }
            }
            // done at this point
            _completed = true;
        }
        private void CreateTestData()
        {
            var tweet = new Tweet()
            {
                Text = "test tweet",
                Timestamp = new DateTime(2014, 1, 1, 12, 0, 0),
            };

            var tweet2 = new Tweet()
            {
                Text = "test tweet2",
                Timestamp = new DateTime(2014, 1, 1, 12, 1, 0),
            };

            using (var repository = new TweetRepository())
            {
                repository.Add(tweet);
                repository.Add(tweet2);
            }
        }
        public void TestUpdate()
        {
            // Set up data
            bool success = false;
            string updatedText = "updated test tweet";
            var tweet = new Tweet()
            {
                Text = "test tweet",
                Timestamp = new DateTime(2014, 1, 1, 12, 0, 0),
            };

            // Execute
            using (var repository = new TweetRepository())
            {
                tweet.Id = repository.Add(tweet);
                tweet.Text = updatedText;
                success = repository.Update(tweet);
            }

            // Validate
            Assert.IsTrue(success);
            Assert.AreEqual(updatedText, tweet.Text);
        }
        public void TestGetAll()
        {
            // Set up data
            CreateTestData();
            List<Tweet> results = null;

            // Execute
            using (var repository = new TweetRepository())
            {
                results = repository.GetAll().ToList();
            }

            // Validate
            Assert.IsTrue(results.Count > 0);
        }
        public IEnumerable<object> Get(long id, DateTime after, int skip, int type)
        {
            IEnumerable<ImageTimestamp> ret = null;
            long uId = id + after.Ticks;
            if (!_topGameImages.Keys.Contains(uId))
            {
                _topGameImages.Add(uId, new List<ImageTimestamp>());
            }

            // parse the type of event
            GameEventType eventType = (GameEventType)type;
            string keyword = "";
            switch(eventType) {
                case GameEventType.GOAL:
                    keyword = "goal";
                    break;
                case GameEventType.YELLOW:
                case GameEventType.RED:
                    keyword = "card";
                    break;
                case GameEventType.SUB:
                    keyword = "substitution";
                    break;
            }

            if (_topGameImages[uId].Count >= skip + 5)
            {
                ret = _topGameImages[uId].GetRange(skip, 5);
            }
            else
            {
                using (var repository = new TweetRepository())
                {
                    var imgs = (from tweet in repository.DataSet.Include("Images")
                                where tweet.GameId == id
                                && tweet.Timestamp > after
                                && tweet.Images.Count > 0
                                && !tweet.Text.StartsWith("RT")
                                select tweet)
                                 .OrderBy(tweet => tweet.Timestamp)
                                 .Skip(skip).Take(5)
                                 .Select(tweet => new ImageTimestamp()
                                 {
                                     Url = tweet.Images.FirstOrDefault().Url,
                                     Timestamp = tweet.Timestamp
                                 }).ToList();

                    _topGameImages[uId].AddRange(imgs);
                    ret = imgs;

                    /*
                                && !tweet.Text.StartsWith("RT")
                                && tweet.Text.ToLower().Contains(keyword)

                     *
                    images = (from image in repository.DataSet.Include("Tweet")
                              where image.GameId == id
                              && image.Tweet.Timestamp > after
                              select new ImageTimestamp
                              {
                                  Url = image.Url,
                                  Timestamp = image.Tweet.Timestamp
                              }).OrderBy(img => img.Timestamp).Distinct().Skip(skip).Take(5).ToList();
                    */
                }
            }

            return ret;
        }
Esempio n. 42
0
        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;
        }
Esempio n. 43
0
 public TweetService()
 {
     _tweetRepo = new TweetRepository();
 }
        public async Task <IHttpActionResult> Get(int tweetcount = 0)
        {
            TweetRepository tr = new TweetRepository(ConfigurationManager.AppSettings["ConsumerKey"], ConfigurationManager.AppSettings["ConsumerSecret"], ConfigurationManager.AppSettings["AccessToken"], ConfigurationManager.AppSettings["AccessTokenSecret"]);

            return(Ok(await tr.GetTweetstats(tweetcount)));
        }