public void BeginResolve() { if (isBeginResolved) { return; } isBeginResolved = true; Task.Factory.StartNew(() => { if (Setting.Instance.TweetExperienceProperty.UrlResolveMode == Configuration.Settings.UrlResolve.OnPointed) { url = ShortenManager.Extract(url); } ResolvedUrl = url; ImageLinkUrl = UploaderManager.TryResolve(url); }); }
private void ResolvePhotos() { var tokens = Tokenizer.Tokenize(this.TweetText); var uris = tokens .Where(t => t.Kind == TokenKind.Url).ToArray(); if (uris.Length > 0) { IsPhotoResolving = true; _photoThumbUrls = uris .Select(t => UploaderManager.TryResolve(ShortenManager.Extract(t.Text))) .Where(u => u != null) .Select(s => new PhotoThumbnailViewModel(new Uri(s))) .ToArray(); IsPhotoResolving = false; RaisePropertyChanged(() => PhotoThumbnails); } else { _photoThumbUrls = new PhotoThumbnailViewModel[0]; IsPhotoResolving = false; } }
private static IEnumerable <Inline> GenerateSink(string text) { foreach (var tok in Tokenizer.Tokenize(text)) { var ctt = tok.Text; switch (tok.Kind) { case TokenKind.AtLink: yield return(TextElementGenerator.GenerateHyperlink(ctt, () => InternalLinkClicked(InternalLinkKind.User, ctt))); break; case TokenKind.Hashtag: var hashlink = TextElementGenerator.GenerateHyperlink(ctt, () => InternalLinkClicked(InternalLinkKind.Hash, ctt)); hashlink.ToolTip = new TextBlock(new Run("Ctrlキーを押しながらクリックすると、ブラウザを開いて検索します...")); yield return(hashlink); break; case TokenKind.Url: String resolved = null; try { resolved = new Uri(ctt).PunyDecode().OriginalString; } catch (UriFormatException) { } var urllink = Regex.IsMatch(ctt, TweetUrlRegex) ? TextElementGenerator.GenerateHyperlink( String.IsNullOrEmpty(resolved) ? ctt : resolved, () => InternalLinkClicked(InternalLinkKind.Tweet, ctt)) : TextElementGenerator.GenerateHyperlink( String.IsNullOrEmpty(resolved) ? ctt : resolved, () => ExternalLinkClicked(ctt)); switch (Setting.Instance.TweetExperienceProperty.UrlResolveMode) { case UrlResolve.OnPointed: case UrlResolve.Never: urllink.ToolTip = new UrlTooltip(ctt); break; case UrlResolve.OnReceived: string nurl = null; if ((nurl = UrlResolveCacheStorage.Lookup(ctt)) == null) { nurl = ShortenManager.Extract(ctt); if (nurl != ctt) { // resolved UrlResolveCacheStorage.AddResolved(ctt, nurl); } else { // unresolved UrlResolveCacheStorage.AddResolved(ctt, ctt); } } if (String.IsNullOrEmpty(nurl)) { urllink.ToolTip = new UrlTooltip(ctt); } else { urllink.ToolTip = new UrlTooltip(nurl); } break; } ToolTipService.SetShowDuration(urllink, Setting.Instance.TweetExperienceProperty.UrlTooltipShowLength); yield return(urllink); break; case TokenKind.Text: default: yield return(TextElementGenerator.GenerateRun(ctt)); break; } } }