Inline CreateMediaLink(TwitterMedia Media) { MenuItem item = new MenuItem { Header = Localization.Resources.MuteDomain, Foreground = new SolidColorBrush(Colors.Black) }; item.Click += (sender, e) => { Uri uri; if (Uri.TryCreate(Media.DisplayUrl, UriKind.Absolute, out uri)) { var filter = FilterManager.SetupMute(FilterType.Text, uri.Host); Dependency.Resolve <IMessageService>().ShowMessage(String.Format(Localization.Resources.MutedUntil, filter.IsValidUntil.ToString("f")), ""); } else { Dependency.Resolve <IMessageService>().ShowError(Localization.Resources.NotValidURL); } }; return(CreateBaseLink(Media.DisplayUrl, Localization.Resources.CopyLink, Media.DisplayUrl, item)); }
Inline CreateMediaLink(TwitterMedia Media) { MenuItem item = new MenuItem { Header = Localization.Resources.MuteDomain, Foreground = new SolidColorBrush(Colors.Black) }; item.Click += (sender, e) => { Uri uri; if (Uri.TryCreate(Media.DisplayUrl, UriKind.Absolute, out uri)) { var filter = FilterManager.SetupMute(FilterType.Text, uri.Host); Dependency.Resolve<IMessageService>().ShowMessage(String.Format(Localization.Resources.MutedUntil, filter.IsValidUntil.ToString("f")), ""); } else Dependency.Resolve<IMessageService>().ShowError(Localization.Resources.NotValidURL); }; return CreateBaseLink(Media.DisplayUrl, Localization.Resources.CopyLink, Media.DisplayUrl, item); }
private void ProcessTwitterTweets(string blobText, T_CollectionTask t_newTask) { //1-Deserialize List <T_TwitterTweet> t_tweets = new List <T_TwitterTweet>(); List <T_TwitterGeoLocation> t_geoLocations = new List <T_TwitterGeoLocation>(); List <T_TwitterPlace> t_places = new List <T_TwitterPlace>(); List <T_TwitterHashTag> t_hashTags = new List <T_TwitterHashTag>(); List <T_TwitterMedia> t_medias = new List <T_TwitterMedia>(); List <T_TwitterMention> t_mentions = new List <T_TwitterMention>(); List <T_TwitterUrl> t_urls = new List <T_TwitterUrl>(); List <TwitterStatus> tweets = JsonConvert.DeserializeObject <List <TwitterStatus> >(blobText); #region Tweets foreach (TwitterStatus tweet in tweets) { T_TwitterTweet t_tweet = new T_TwitterTweet(); t_tweet.CollectionTaskId = t_newTask.Id; t_tweet.CreatedDate = tweet.CreatedDate; t_tweet.InReplayToTweetId = tweet.InReplyToStatusId; t_tweet.InReplayToUserId = tweet.InReplyToUserId; t_tweet.InReplyToScreenName = tweet.InReplyToScreenName; t_tweet.IsFavorited = tweet.IsFavorited; t_tweet.IsPossiblySensitive = tweet.IsPossiblySensitive; t_tweet.IsTruncated = tweet.IsTruncated; t_tweet.RetweetCount = tweet.RetweetCount; t_tweet.Source = tweet.Source; t_tweet.Text = tweet.Text; t_tweet.TweeterId = tweet.User.Id; t_tweet.TweeterScreenName = tweet.User.ScreenName; t_tweet.TweetId = tweet.Id; t_tweets.Add(t_tweet); if (tweet.Location != null) { T_TwitterGeoLocation t_geoLocation = new T_TwitterGeoLocation(); t_geoLocation.CollectionTaskId = t_newTask.Id; t_geoLocation.TweetId = t_tweet.TweetId; t_geoLocation.TweeterUserId = t_tweet.TweeterId; t_geoLocation.Longitude = Math.Round(Convert.ToDecimal(tweet.Location.Coordinates.Longitude), 6); t_geoLocation.Latitude = Math.Round(Convert.ToDecimal(tweet.Location.Coordinates.Latitude), 6); t_geoLocations.Add(t_geoLocation); } if (tweet.Place != null) { T_TwitterPlace t_place = new T_TwitterPlace(); t_place.CollectionTaskId = t_newTask.Id; t_place.TweetId = t_tweet.TweetId; t_place.TweeterUserId = t_tweet.TweeterId; t_place.Country = tweet.Place.Country; t_place.CountryCode = tweet.Place.CountryCode; t_place.FullName = tweet.Place.FullName; t_place.Name = tweet.Place.Name; t_place.PlaceId = tweet.Place.Id; t_place.PlaceType = tweet.Place.PlaceType.ToString(); t_place.Url = tweet.Place.Url; t_places.Add(t_place); } if (tweet.Entities != null) { if (tweet.Entities.Count <TwitterEntity>() > 0) { foreach (TwitterEntity entity in tweet.Entities) { switch (entity.EntityType) { case TwitterEntityType.HashTag: TwitterHashTag hashTag = (TwitterHashTag)entity; T_TwitterHashTag t_hashTag = new T_TwitterHashTag(); t_hashTag.CollectionTaskId = t_newTask.Id; t_hashTag.TweetId = t_tweet.TweetId; t_hashTag.TweeterUserId = t_tweet.TweeterId; t_hashTag.Text = hashTag.Text; t_hashTags.Add(t_hashTag); break; case TwitterEntityType.Media: TwitterMedia media = (TwitterMedia)entity; T_TwitterMedia t_media = new T_TwitterMedia(); t_media.CollectionTaskId = t_newTask.Id; t_media.TweetId = t_tweet.TweetId; t_media.TweeterUserId = t_tweet.TweeterId; t_media.DisplayUrl = media.DisplayUrl; t_media.ExpandedUrl = media.ExpandedUrl; t_media.MediaId = media.Id; t_media.MediaType = media.MediaType.ToString(); t_media.MediaUrl = media.MediaUrl; t_media.Url = media.Url; t_medias.Add(t_media); break; case TwitterEntityType.Mention: TwitterMention mention = (TwitterMention)entity; T_TwitterMention t_mention = new T_TwitterMention(); t_mention.CollectionTaskId = t_newTask.Id; t_mention.TweetId = t_tweet.TweetId; t_mention.TweeterUserId = t_tweet.TweeterId; t_mention.MentionId = mention.Id; t_mention.Name = mention.Name; t_mention.ScreenName = mention.ScreenName; t_mentions.Add(t_mention); break; case TwitterEntityType.Url: TwitterUrl url = (TwitterUrl)entity; T_TwitterUrl t_url = new T_TwitterUrl(); t_url.CollectionTaskId = t_newTask.Id; t_url.TweetId = t_tweet.TweetId; t_url.TweeterUserId = t_tweet.TweeterId; t_url.ExpandedValue = url.ExpandedValue; t_url.Value = url.Value; t_urls.Add(t_url); break; default: throw new NotImplementedException(); } } } } } #endregion //2-Validate //3-Update LinqToSqlAzureHaystackDataContext context = new LinqToSqlAzureHaystackDataContext(); context.T_TwitterTweets.InsertAllOnSubmit <T_TwitterTweet>(t_tweets); context.T_TwitterGeoLocations.InsertAllOnSubmit <T_TwitterGeoLocation>(t_geoLocations); context.T_TwitterPlaces.InsertAllOnSubmit <T_TwitterPlace>(t_places); context.T_TwitterHashTags.InsertAllOnSubmit <T_TwitterHashTag>(t_hashTags); context.T_TwitterMedias.InsertAllOnSubmit <T_TwitterMedia>(t_medias); context.T_TwitterMentions.InsertAllOnSubmit <T_TwitterMention>(t_mentions); context.T_TwitterUrls.InsertAllOnSubmit <T_TwitterUrl>(t_urls); context.SubmitChanges(); }
internal static async Task <VisionDescription> FetchVisionDescriptionAsync(TwitterStatus tweet, TwitterMedia media) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", GetEnvironmentVariable("AzureVisionApiSubscriptionKey")); string requestParameters = "visualFeatures=Categories,Description,Color&language=en"; string uri = GetEnvironmentVariable("AzureVisionUriBase") + "?" + requestParameters; var body = "{\"url\":\"" + media.MediaUrl + "\"}"; var content = new StringContent(body, Encoding.UTF8, "application/json"); HttpResponseMessage apiResponse = await client.PostAsync(uri, content); var result = await apiResponse.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <VisionDescription>(result)); }