SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (request.Headers.Contains("x-cm-identity")) { GeoUser user = UserManagement.FromIdentity( request.Headers.GetValues("x-cm-identity").FirstOrDefault()); request.Properties["USER"] = user; } return(base.SendAsync(request, cancellationToken)); }
public static async Task <bool> InsertOrUpdateGeoUsersAsync(GeoUser geoUser) { try { using (var context = new AppDbContext()) { if (context.GeoUsers.Count(x => x.UserId == geoUser.UserId && x.Id == geoUser.Id) == 0) { await context.AddAsync(geoUser); await context.SaveChangesAsync(); } return(true); } } catch (Exception ex) { return(false); } }
public async Task TweetAnalysis() { while (true) { if (Tweets.Count > 0) { ITweet t = Tweets.Pop(); var tweetRaw = AdapterTweet(t); if (t.Place == null) { if (!string.IsNullOrEmpty(tweetRaw?.User?.Location)) { var geoUsers = await GetLocation.GeoReverse(tweetRaw.User.Location); if (geoUsers != null) { tweetRaw.User.GeoUsers.AddRange(geoUsers); } } } else { try { var geoUser = new GeoUser { Lat = t.Place.BoundingBox.Coordinates[0].Latitude, Lon = t.Place.BoundingBox.Coordinates[0].Longitude, DisplayName = t.Place.FullName }; tweetRaw.User.GeoUsers.Add(geoUser); } catch (Exception ex) { } } var hashtags = regex.Matches(t.FullText); foreach (Match h in hashtags) { tweetRaw.TweetsHashtags.Add(new TweetHashtags() { Hashtags = h.Value }); } var tweetsSentiment = await TweetCognitive.AnalyzeTweetSentiment(new List <TweetRaw>() { tweetRaw }); if (tweetsSentiment != null && tweetsSentiment.Count > 0) { tweetRaw.TweetSentiment = tweetsSentiment[0]; } var tweetEntities = await TweetCognitive.AnalyzeTweetEntity(new List <TweetRaw> { tweetRaw }); if (tweetEntities != null && tweetEntities.Count > 0) { tweetRaw.TweetEntities = tweetEntities; } var tweet = CreateTweetDto(tweetRaw); Update?.Invoke(tweet, Connection); } } }