Exemplo n.º 1
0
        public async Task CreateTweet(string id, string tweetContent)
        {
            var tweet = new Entities.Tweet
            {
                TweetDateTime = DateTime.Now.ToString("d/MM/yyyy"),
                TimeStamp     = DateTime.Now,
                Id            = Guid.NewGuid().ToString(),
                UserId        = id,
                TweetContent  = tweetContent
            };

            if (await CheckForProfanity(tweet))
            {
                await _messagePublisher.PublishMessageAsync("NewProfanityTweetMessage", new { TweetDateTime = tweet.TweetDateTime, TimeStamp = tweet.TimeStamp, Id = tweet.Id, UserId = tweet.UserId, TweetContent = tweet.TweetContent });
            }

            if (tweetContent.Contains("#"))
            {
                await _messagePublisher.PublishMessageAsync("NewTopicTweetMessage", new { Id = tweet.Id, TweetContent = tweet.TweetContent });
            }

            await _messagePublisher.PublishMessageAsync("NewPostedTweetMessage", new { TweetDateTime = tweet.TweetDateTime, TimeStamp = tweet.TimeStamp, Id = tweet.Id, UserId = tweet.UserId, TweetContent = tweet.TweetContent });

            _tweets.InsertOne(tweet);
        }
Exemplo n.º 2
0
 public Tweet LoadData(Entities.Tweet tweet)
 {
     this.author.Text     = tweet.User.Login;
     this.content.Text    = tweet.Data;
     this.email.Text      = tweet.User.Email;
     this.timeposted.Text = ComputeTime(tweet.CreatedAt);
     return(this);
 }
Exemplo n.º 3
0
        public async Task <bool> CheckForProfanity(Entities.Tweet tweet)
        {
            var httpClient = new HttpClient();

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(_url),
                Content    = new StringContent("{\"tweetcontent\":\"" + tweet.TweetContent + "\"}", Encoding.UTF8, "application/json")
            };

            using var response = await httpClient.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var jsonString = await response.Content.ReadAsStringAsync();

            var jObject = JsonConvert.DeserializeObject <JObject>(jsonString);

            return(jObject["ProfanityResult"].Value <bool>());
        }