コード例 #1
0
        public async Task <GenericResult <tweetModels.Tweet, string> > CreateTweet(CreateTweetRequest createTweetRequest)
        {
            if (createTweetRequest is null)
            {
                throw new System.ArgumentNullException(nameof(createTweetRequest));
            }
            var result = new GenericResult <tweetModels.Tweet, string>();

            if (string.IsNullOrWhiteSpace(createTweetRequest.Content))
            {
                result.Error = "Content cannot be empty";
                return(result);
            }
            var tweet = CreateTweetFromCreateTweetRequest(createTweetRequest);
            await _tweetRepository.Create(tweet);

            var tweetEvent = new TweetEvent
            {
                Type    = TweetEventType.Created,
                TweetId = tweet.Id
            };

            _rabbitMqClient.PushToExchange(Constants.TweetsExchangeName, tweetEvent);

            result.SuccessResult = tweet;
            return(result);
        }
コード例 #2
0
        public async Task <Result <bool> > ProcessTweetEvent(TweetEvent tweetEvent)
        {
            if (tweetEvent is null)
            {
                throw new System.ArgumentNullException(nameof(tweetEvent));
            }

            var result = new Result <bool>();

            if (tweetEvent.TweetId < 1)
            {
                result.SuccessResult = true; // This true signifies the event has been handled.
                Console.WriteLine(">>>> Invalid TweetId <<<<<<<");
                return(result);
            }
            if (tweetEvent.Type == TweetEventType.Created)
            {
                result.SuccessResult = await ProcessCreateTweetEvent(tweetEvent);

                return(result);
            }
            else if (tweetEvent.Type == TweetEventType.Deleted)
            {
                result.SuccessResult = await ProcessDeleteTweetEvent(tweetEvent);

                return(result);
            }

            throw new BusinessException($"Unknown TweetEventType or unhandled case for the tweet: {_jsonUtils.SerializeToJson(tweetEvent)}");
        }
コード例 #3
0
        public void GetDTTest()
        {
            DateTime   expectedTime = DateTime.Now;
            TweetEvent te           = new TweetEvent(new GRLocation(0, 0), expectedTime.ToString(), "some text");

            Assert.AreEqual(expectedTime.ToString(), te.EventDateTime);
        }
コード例 #4
0
        public void TweetEventTest()
        {
            string     expectedText = "my text";
            TweetEvent te           = new TweetEvent(new GRLocation(0, 0), "", expectedText);

            Assert.AreEqual(expectedText, te.TweetText);
        }
コード例 #5
0
        public void GetLocationTest()
        {
            GRLocation expectedLocation = new GRLocation(10, 12);
            TweetEvent te            = new TweetEvent(expectedLocation, "dateTime", "some text");
            GRLocation eventLocation = te.EventLocation;

            Assert.AreEqual(expectedLocation, eventLocation);
        }
コード例 #6
0
        public async Task ProcessEvent(TweetEvent tweetEvent)
        {
            if (tweetEvent is null)
            {
                throw new System.ArgumentNullException(nameof(tweetEvent));
            }

            await _timeLineServiceLogic.ProcessTweetEvent(tweetEvent);
        }
コード例 #7
0
        public void SetLocationTest()
        {
            GRLocation original         = new GRLocation(0, 0);
            GRLocation expectedLocation = new GRLocation(10, 12);
            TweetEvent te = new TweetEvent(original, "dateTime", "some text");

            te.EventLocation = expectedLocation;

            Assert.AreEqual(expectedLocation, te.EventLocation);
        }
コード例 #8
0
        public Task <Result <bool> > ProcessTweetEvent(TweetEvent tweetEvent)
        {
            if (tweetEvent is null)
            {
                throw new System.ArgumentNullException(nameof(tweetEvent));
            }

            // TODO: Need to process NewsFeedTimeLineService as well.
            return(_timeLineServiceFactory.GetTimeLineService(TimeLineType.Home).ProcessTweetEvent(tweetEvent));
        }
コード例 #9
0
        private async Task ProcessCreateTweetEvent(List <long> userIds, TweetEvent tweetEvent)
        {
            var newsFeedTimeLineEntry = new NewsFeedTimeLineEntry
            {
                TweetId = tweetEvent.TweetId
            };

            var tasks = userIds.Select(userId => _timeLineRepository.AddToNewsFeedTimeLine(userId, newsFeedTimeLineEntry));

            await Task.WhenAll(tasks);
        }
コード例 #10
0
        public static void Write(string ns, XmlTextWriter writer, TweetEvent aEvent)
        {
            writer.WriteStartElement(ns + "tweet");

            writer.WriteStartElement(ns + "text");
            writer.WriteString(aEvent.TweetText);
            writer.WriteEndElement();

            Write(ns, writer, aEvent.EventLocation);
            Write(ns, writer, aEvent.EventDateTime);

            writer.WriteEndElement();
        }
コード例 #11
0
        // TODO: need to test the NewsFeedTimeLine functionality
        public async Task <Result <bool> > ProcessTweetEvent(TweetEvent tweetEvent)
        {
            if (tweetEvent is null)
            {
                throw new System.ArgumentNullException(nameof(tweetEvent));
            }
            var result = new Result <bool>();
            var tweet  = await _tweetRepository.Get(tweetEvent.TweetId);

            if (tweet == null || tweet.Id < 1)
            {
                Console.WriteLine("Could not find any tweet");
                result.SuccessResult = true;
                return(result);
            }

            var userId = tweet.AuthorId;

            var followersTask = _followsLogic.GetFollowers(userId);

            var followersResult = followersTask.Result;


            var userIds = new List <long>();

            userIds.Add(userId);

            if (followersResult.SuccessResult.IsNotEmpty())
            {
                userIds.AddRange(followersResult.SuccessResult.Select(follows => follows.FollowerId));
            }
            if (tweetEvent.Type == TweetEventType.Created)
            {
                await ProcessCreateTweetEvent(userIds, tweetEvent);
            }
            else if (tweetEvent.Type == TweetEventType.Deleted)
            {
                await ProcessDeleteTweetEvent(userIds, tweetEvent);
            }
            else
            {
                throw new BusinessException("Unhandled Tweet Event Type");
            }

            result.SuccessResult = true;

            return(result);
        }
コード例 #12
0
        private void btn_submit_Click(object sender, EventArgs e)
        {
            tweetText = txt_tweet.Text;
            dt        = dtPicker.Value;

            if (Ready())
            {
                Event newEvent = new TweetEvent(new GRLocation(eventLocation.Latitude, eventLocation.Longitude), dt.ToString(), tweetText);
                GREventManager.AddEvent(newEvent);
                MessageBox.Show("Event successfully added!");
                this.Hide();
            }
            else
            {
                MessageBox.Show("Could not add event.");
            }
        }
コード例 #13
0
        private async Task <bool> ProcessCreateTweetEvent(TweetEvent tweetEvent)
        {
            var tweet = await _tweetRepository.Get(tweetEvent.TweetId);

            if (tweet == null)
            {
                Console.WriteLine("No tweet found");
                return(true);
            }

            var homeTimeLineEntry = new HomeTimeLineEntry
            {
                TweetId = tweetEvent.TweetId
            };
            await _timeLineRepository.AddToHomeTimeLine(tweet.AuthorId, homeTimeLineEntry);

            return(true);
        }
コード例 #14
0
        public void RegisterTweetEvent(string source, ITweet tweet)
        {
            _logger.WriteLine($"Registering a tweet event for {_contact.Personal()?.Nickname ?? _contact.Id.ToString()}");
            var interaction = new Interaction(_contact, InteractionInitiator.Contact, Guid.Parse(_xconnectConfiguration.TwitterChannelId), source);

            _client.SetFacet <Tweet>(interaction, Tweet.FacetName, new Tweet()
            {
                Text = tweet.FullText
            });

            var goal = new Goal(Guid.Parse(_xconnectConfiguration.TwitterEngagementGoalId), DateTime.UtcNow);

            interaction.Events.Add(goal);

            var tweetEvent = new TweetEvent(Guid.Parse(_xconnectConfiguration.MonitoredPhraseOnTwitterEventId), DateTime.UtcNow)
            {
                TargetPhrase = GetPhraseMatches(tweet.FullText)
            };

            interaction.Events.Add(tweetEvent);

            _client.AddInteraction(interaction);
            _logger.WriteLine("Tweet event successfully registered");
        }
コード例 #15
0
        public IActionResult PostWebhook([FromBody] TweetEvent tweetEvent)
        {
            // Here's where we'll process the calls from Twitter when there's a new Tweet event.

            return(new OkResult());
        }
コード例 #16
0
 private async Task ProcessDeleteTweetEvent(List <long> userIds, TweetEvent tweetEvent)
 {
     var tasks = userIds.Select(userId => _timeLineRepository.DeleteFromNewsFeedTimeLine(userId, tweetEvent.TweetId));
     await Task.WhenAll(tasks);
 }