Ejemplo n.º 1
0
        private void HandleHashtags(TwitterStatus tweet)
        {
            foreach (TwitterHashTag hashtag in tweet.Entities.HashTags)
            {
                Hashtag h = new Hashtag();

                if (unitOfWork.Hashtags.HashtagAlreadyExists(hashtag.Text, out h) == false)
                {
                    h = new Hashtag
                    {
                        HashtagGuid  = Guid.NewGuid(),
                        HashtagValue = hashtag.Text
                    };

                    unitOfWork.Hashtags.Add(h);
                }

                TweetHashtag th = new TweetHashtag
                {
                    TweetId     = tweet.Id,
                    HashtagGuid = h.HashtagGuid
                };

                unitOfWork.Hashtags.AddTweetHashtag(th);
            }
        }
        public static void AddTweetPerMinute(TweetHashtag tweetHashtag, HashtagCount hashtagCount, IEnumerable <Tweet> tweets, DateTime dateTime)
        {
            // TODO- tweet is sometimes returning as null, not sure how this is happening
            // using if to catch null instances
            Tweet tweet = tweets.SingleOrDefault(t => t.ID == tweetHashtag.TweetID);

            if (tweet != null)
            {
                // adds 100 to the correct 5 minute interval 0-11
                hashtagCount.TweetsPer[Convert.ToInt32(Math.Floor((dateTime - UnixTimeStampToDateTime(tweet.UnixTimeStamp)).Minutes / 5.0))] += 100;
            }
        }
Ejemplo n.º 3
0
        private void AssociateTweetWithHashtags(Tweet tweet, IEnumerable <Hashtag> hashtags)
        {
            TweetHashtag tweetHashtag;

            foreach (var hashtag in hashtags)
            {
                tweetHashtag = new TweetHashtag
                {
                    Key     = Guid.NewGuid(),
                    Tweet   = tweet,
                    Hashtag = hashtag
                };

                _tweetHashtagRepository.Add(tweetHashtag);
            }
            try
            {
                _tweetHashtagRepository.Save();
            }
            catch (Exception e)
            {
                return;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Create a new Hashtag, or update an existing Hashtag
        /// </summary>
        /// <exception cref="InvalidOperationException">Throws if a Tweet was passed that has no Id.</exception>
        public Hashtag UpsertHashtag(string label, Tweet tweet)
        {
            if (tweet.Id == 0)
            {
                throw new InvalidOperationException("An unsaved tweet can not be passed to this method.");
            }

            try
            {
                var tag = GetByLabel(label);
                tag.LastUsed = DateTime.Now;
                //tag.Tweets.Add(tweet);
                _context.Hashtags.Update(tag);
                var tweetHashtag = new TweetHashtag()
                {
                    Tweet   = tweet,
                    Hashtag = tag,
                };
                _context.TweetHashtags.Add(tweetHashtag);
                _context.SaveChanges();
                return(tag);
            }
            catch (HashtagNotFoundException)
            {
                var hashtag = new Hashtag(label);
                _context.Hashtags.Add(hashtag);
                var tweetHashtag = new TweetHashtag()
                {
                    Tweet   = tweet,
                    Hashtag = hashtag,
                };
                _context.TweetHashtags.Add(tweetHashtag);
                _context.SaveChanges();
                return(hashtag);
            }
        }
Ejemplo n.º 5
0
 public void AddTweetHashtag(TweetHashtag tweetHashtag)
 {
     NoamContext.TweetHashtags.Add(tweetHashtag);
 }
Ejemplo n.º 6
0
 public static string ToTweetHashtagDto(this TweetHashtag tweetHashtag)
 {
     return(tweetHashtag.Hashtag.Name);
 }