private GetEntityAidedText ( EntityDisplayMode displayMode = EntityDisplayMode.DisplayText ) : string | ||
displayMode | EntityDisplayMode | |
Результат | string |
static void Instance_OnMentionReceived(TwitterStatus obj) { Show(new NormalNotificatorViewModel(MetroColors.Orange, obj.User, "mention from @" + obj.User.ScreenName, obj.GetEntityAidedText())); }
static void Instance_OnStatusReceived(TwitterStatus obj) { Show(new NormalNotificatorViewModel(MetroColors.Cyan, obj.User, "@" + obj.User.ScreenName, obj.GetEntityAidedText())); }
private StatusModel(TwitterStatus status) { this.Status = status; ImageResolver.Resolve(status.GetEntityAidedText(true)) .Aggregate(new List<Tuple<Uri, Uri>>(), (l, i) => { l.Add(i); return l; }) .Finally(() => { var subj = Interlocked.Exchange(ref this._imagesSubject, null); lock (subj) { subj.OnCompleted(); // WE SHOULD NOT CALL Dispose METHOD !!! // http://stackoverflow.com/questions/16540853/why-does-subjectt-dispose-does-not-dispose-current-suscriptions // subj.Dispose(); } }) .Subscribe(l => this.Images = l); }
/// <summary> /// Get attached images in status. <para /> /// Returns tuples of (original_uri, image_uri). /// </summary> /// <param name="status"></param> /// <returns></returns> public static IEnumerable<Tuple<Uri, Uri>> ResolveImages(TwitterStatus status) { var result = new List<Tuple<string, string>>(); // pick attached images status.Entities.Guard() .Where(e => e.EntityType == EntityType.Media) .ForEach(e => result.Add(Tuple.Create(e.OriginalUrl, e.MediaUrl))); // resolve url in status text var matches = UrlRegex.Matches(status.GetEntityAidedText(EntityDisplayMode.MediaUri)).Cast<Match>(); matches.Select(m => m.Value).ForEach(s => { if (SupportedExtents.Any(ext => s.EndsWith("." + ext))) { result.Add(Tuple.Create(s, s)); } else { var key = ResolveTable.Keys.FirstOrDefault(s.StartsWith); Func<string, string> resolver; if (key != null && ResolveTable.TryGetValue(key, out resolver)) { result.Add(Tuple.Create(s, resolver(s))); } } }); return result.Distinct(t => t.Item2) .Where(t => Uri.IsWellFormedUriString(t.Item1, UriKind.Absolute) && Uri.IsWellFormedUriString(t.Item2, UriKind.Absolute)) .Select(t => Tuple.Create(new Uri(t.Item1), new Uri(t.Item2))); }
private StatusModel(TwitterStatus status) { this.Status = status; ImageResolver.Resolve(status.GetEntityAidedText(true)) .Aggregate(new List<Tuple<Uri, Uri>>(), (l, i) => { l.Add(i); return l; }) .Finally(() => { var subj = Interlocked.Exchange(ref this._imagesSubject, null); lock (subj) { subj.OnCompleted(); subj.Dispose(); } }) .Subscribe(l => this.Images = l); }