public UserInfo(TwitterDataModel.User user) { this.Id = user.Id; this.Name = user.Name.Trim(); this.ScreenName = user.ScreenName; this.Location = user.Location; this.Description = user.Description; try { this.ImageUrl = new Uri(user.ProfileImageUrlHttps); } catch (Exception) { this.ImageUrl = null; } this.Url = user.Url; this.Protect = user.Protected; this.FriendsCount = user.FriendsCount; this.FollowersCount = user.FollowersCount; this.CreatedAt = MyCommon.DateTimeParse(user.CreatedAt); this.StatusesCount = user.StatusesCount; this.Verified = user.Verified; if (user.Status != null) { this.RecentPost = user.Status.Text; this.PostCreatedAt = MyCommon.DateTimeParse(user.Status.CreatedAt); this.PostSource = user.Status.Source; } }
public ListElement(TwitterDataModel.ListElementData listElementData, dynamic tw) { this.Description = listElementData.Description; this.Id = listElementData.Id; this.IsPublic = (listElementData.Mode == "public"); this.MemberCount = listElementData.MemberCount; this.Name = listElementData.Name; this.SubscriberCount = listElementData.SubscriberCount; this.Slug = listElementData.Slug; this.Nickname = listElementData.User.Name.Trim(); this.Username = listElementData.User.ScreenName; this.UserId = listElementData.User.Id; this._tw = tw; }
public string CreateHtmlAnchor(ref string Text, List<string> AtList, TwitterDataModel.Entities entities, Dictionary<string, string> media) { var ret = Text; if (entities != null) { var etInfo = new SortedList<int, EntityInfo>(); //URL if (entities.Urls != null) { foreach (var ent in entities.Urls) { if (string.IsNullOrEmpty(ent.DisplayUrl)) { etInfo.Add(ent.Indices[0], new EntityInfo {StartIndex = ent.Indices[0], EndIndex = ent.Indices[1], Text = ent.Url, Html = "<a href=\"" + ent.Url + "\">" + ent.Url + "</a>"}); } else { var expanded = ShortUrl.ResolveMedia(ent.ExpandedUrl, false); etInfo.Add(ent.Indices[0], new EntityInfo {StartIndex = ent.Indices[0], EndIndex = ent.Indices[1], Text = ent.Url, Html = "<a href=\"" + ent.Url + "\" title=\"" + expanded + "\">" + ent.DisplayUrl + "</a>", Display = ent.DisplayUrl}); if (media != null && !media.ContainsKey(ent.Url)) media.Add(ent.Url, expanded); } } } if (entities.Hashtags != null) { foreach (var ent in entities.Hashtags) { var hash = Text.Substring(ent.Indices[0], ent.Indices[1] - ent.Indices[0]); etInfo.Add(ent.Indices[0], new EntityInfo {StartIndex = ent.Indices[0], EndIndex = ent.Indices[1], Text = hash, Html = "<a href=\"" + _protocol + "twitter.com/search?q=%23" + ent.Text + "\">" + hash + "</a>"}); lock (LockObj) { _hashList.Add("#" + ent.Text); } } } if (entities.UserMentions != null) { foreach (var ent in entities.UserMentions) { var screenName = Text.Substring(ent.Indices[0] + 1, ent.Indices[1] - ent.Indices[0] - 1); etInfo.Add(ent.Indices[0] + 1, new EntityInfo {StartIndex = ent.Indices[0] + 1, EndIndex = ent.Indices[1], Text = ent.ScreenName, Html = "<a href=\"/" + ent.ScreenName + "\">" + screenName + "</a>"}); if (!AtList.Contains(ent.ScreenName.ToLower())) AtList.Add(ent.ScreenName.ToLower()); } } if (entities.Media != null) { foreach (var ent in entities.Media) { if (ent.Type == "photo") { etInfo.Add(ent.Indices[0], new EntityInfo {StartIndex = ent.Indices[0], EndIndex = ent.Indices[1], Text = ent.Url, Html = "<a href=\"" + ent.Url + "\" title=\"" + ent.ExpandedUrl + "\">" + ent.DisplayUrl + "</a>", Display = ent.DisplayUrl}); if (media != null && !media.ContainsKey(ent.Url)) media.Add(ent.Url, ent.MediaUrl); } } } if (etInfo.Count > 0) { try { var idx = 0; ret = string.Empty; foreach (var et in etInfo) { ret += Text.Substring(idx, et.Key - idx) + et.Value.Html; idx = et.Value.EndIndex; } ret += Text.Substring(idx); } catch(ArgumentOutOfRangeException) { //Twitterのバグで不正なエンティティ(Index指定範囲が重なっている)が返ってくる場合の対応 ret = Text; entities = null; if (media != null) media.Clear(); } } } ret = Regex.Replace(ret, "(^|[^a-zA-Z0-9_/&##@@>=.~])(sm|nm)([0-9]{1,10})", "$1<a href=\"http://www.nicovideo.jp/watch/$2$3\">$2$3</a>"); ret = AdjustHtml(ShortUrl.Resolve(PreProcessUrl(ret), false)); //IDN置換、短縮Uri解決、@リンクを相対→絶対にしてtarget属性付与 return ret; }
private string ReplaceTextFromApi(string text, TwitterDataModel.Entities entities) { if (entities != null) { if (entities.Urls != null) { foreach (var m in entities.Urls) { if (!string.IsNullOrEmpty(m.DisplayUrl)) text = text.Replace(m.Url, m.DisplayUrl); } } if (entities.Media != null) { foreach (var m in entities.Media) { if (!string.IsNullOrEmpty(m.DisplayUrl)) text = text.Replace(m.Url, m.DisplayUrl); } } } return text; }
private bool IsPostRestricted(TwitterDataModel.Status status) { var _current = new PostInfo(string.Empty, string.Empty, string.Empty, string.Empty); _current.CreatedAt = status.CreatedAt; _current.Id = status.IdStr; if (status.Text == null) { _current.Text = string.Empty; } else { _current.Text = status.Text; } _current.UserId = status.User.IdStr; if (_current.Equals(_prev)) { return true; } _prev.CreatedAt = _current.CreatedAt; _prev.Id = _current.Id; _prev.Text = _current.Text; _prev.UserId = _current.UserId; return false; }
private PostClass CreatePostsFromStatusData(TwitterDataModel.Status status) { var post = new PostClass(); TwitterDataModel.Entities entities; post.StatusId = status.Id; if (status.RetweetedStatus != null) { var retweeted = status.RetweetedStatus; post.CreatedAt = MyCommon.DateTimeParse(retweeted.CreatedAt); //Id post.RetweetedId = retweeted.Id; //本文 post.TextFromApi = retweeted.Text; entities = retweeted.Entities; //Source取得(htmlの場合は、中身を取り出し) post.Source = retweeted.Source; //Reply先 long inReplyToStatusId; long.TryParse(retweeted.InReplyToStatusId, out inReplyToStatusId); post.InReplyToStatusId = inReplyToStatusId; post.InReplyToUser = retweeted.InReplyToScreenName; long inReplyToUserId; long.TryParse(status.InReplyToUserId, out inReplyToUserId); post.InReplyToUserId = inReplyToUserId; //幻覚fav対策 var tc = TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites); post.IsFav = tc.Contains(post.RetweetedId); if (retweeted.Geo != null) post.PostGeo = new PostClass.StatusGeo {Lat = retweeted.Geo.Coordinates[0], Lng = retweeted.Geo.Coordinates[1]}; //以下、ユーザー情報 var user = retweeted.User; if (user.ScreenName == null || status.User.ScreenName == null) return null; post.UserId = user.Id; post.ScreenName = user.ScreenName; post.Nickname = user.Name.Trim(); post.ImageUrl = user.ProfileImageUrl; post.IsProtect = user.Protected; //Retweetした人 post.RetweetedBy = status.User.ScreenName; post.RetweetedByUserId = status.User.Id; post.IsMe = post.RetweetedBy.ToLower().Equals(_uname); } else { post.CreatedAt = MyCommon.DateTimeParse(status.CreatedAt); //本文 post.TextFromApi = status.Text; entities = status.Entities; //Source取得(htmlの場合は、中身を取り出し) post.Source = status.Source; long inReplyToStatusId; long.TryParse(status.InReplyToStatusId, out inReplyToStatusId); post.InReplyToStatusId = inReplyToStatusId; post.InReplyToUser = status.InReplyToScreenName; long inReplyToUserId; long.TryParse(status.InReplyToUserId, out inReplyToUserId); post.InReplyToUserId = inReplyToUserId; if (status.Geo != null) post.PostGeo = new PostClass.StatusGeo {Lat = status.Geo.Coordinates[0], Lng = status.Geo.Coordinates[1]}; //以下、ユーザー情報 var user = status.User; if (user.ScreenName == null) return null; post.UserId = user.Id; post.ScreenName = user.ScreenName; post.Nickname = user.Name.Trim(); post.ImageUrl = user.ProfileImageUrl; post.IsProtect = user.Protected; post.IsMe = post.ScreenName.ToLower().Equals(_uname); //幻覚fav対策 var tc = TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites); post.IsFav = tc.Contains(post.StatusId) && TabInformations.GetInstance()[post.StatusId].IsFav; } //HTMLに整形 string textFromApi = post.TextFromApi; post.Text = CreateHtmlAnchor(ref textFromApi, post.ReplyToList, entities, post.Media); post.TextFromApi = textFromApi; post.TextFromApi = this.ReplaceTextFromApi(post.TextFromApi, entities); post.TextFromApi = HttpUtility.HtmlDecode(post.TextFromApi); post.TextFromApi = post.TextFromApi.Replace("<3", "?"); //Source整形 CreateSource(ref post); post.IsReply = post.ReplyToList.Contains(_uname); post.IsExcludeReply = false; if (post.IsMe) { post.IsOwl = false; } else { if (followerId.Count > 0) post.IsOwl = !followerId.Contains(post.UserId); } post.IsDm = false; return post; }
public string GetUserInfo(string screenName, ref TwitterDataModel.User user) { if (MyCommon._endingFlag) return string.Empty; if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return string.Empty; HttpStatusCode res = HttpStatusCode.BadRequest; var content = string.Empty; user = null; try { res = twCon.ShowUserInfo(screenName, ref content); } catch(Exception ex) { return "Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")"; } switch (res) { case HttpStatusCode.OK: Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid; try { user = MyCommon.CreateDataFromJson<TwitterDataModel.User>(content); } catch (SerializationException ex) { MyCommon.TraceOut(ex.Message + Environment.NewLine + content); return "Err:Json Parse Error(DataContractJsonSerializer)"; } catch (Exception ex) { MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content); return "Err:Invalid Json!"; } return string.Empty; case HttpStatusCode.BadRequest: return "Err:API Limits?"; case HttpStatusCode.Unauthorized: Twitter.AccountState = MyCommon.ACCOUNT_STATE.Invalid; var errMsg = GetErrorMessageJson(content); if (string.IsNullOrEmpty(errMsg)) { return Properties.Resources.Unauthorized; } else { return "Auth err:" + errMsg; } default: return "Err:" + res.ToString() + "(" + MethodBase.GetCurrentMethod().Name + ")"; } }
private void doShowUserStatus(TwitterDataModel.User user) { using (ShowUserInfo userinfo = new ShowUserInfo()) { userinfo.Owner = this; userinfo.User = user; userinfo.ShowDialog(this); this.Activate(); this.BringToFront(); } }
private bool AnalizeUserInfo(TwitterDataModel.User user) { if ( user == null ) return false; try { _info.Id = user.Id; _info.Name = user.Name.Trim(); _info.ScreenName = user.ScreenName; _info.Location = user.Location; _info.Description = user.Description; _info.ImageUrl = new Uri (user.ProfileImageUrl); _info.Url = user.Url; _info.Protect = user.Protected; _info.FriendsCount = user.FriendsCount; _info.FollowersCount = user.FollowersCount; _info.FavoriteCount = user.FavouritesCount; _info.CreatedAt = MyCommon.DateTimeParse( user.CreatedAt ); _info.StatusesCount = user.StatusesCount; _info.Verified = user.Verified; try { _info.RecentPost = user.Status.Text; _info.PostCreatedAt = MyCommon.DateTimeParse( user.Status.CreatedAt ); _info.PostSource = user.Status.Source; if ( !_info.PostSource.Contains( "</a>" ) ) { _info.PostSource += "</a>"; } } catch ( Exception ) { _info.RecentPost = null; _info.PostCreatedAt = new DateTime (); _info.PostSource = null; } } catch ( Exception ) { return false; } return true; }
private PostClass CreatePostsFromSearchResultData(TwitterDataModel.SearchResultData status) { var post = new PostClass(); post.StatusId = status.Id; post.CreatedAt = MyCommon.DateTimeParse(status.CreatedAt); //本文 post.TextFromApi = status.Text; var entities = status.Entities; post.Source = WebUtility.HtmlDecode(status.Source); post.InReplyToStatusId = status.InReplyToStatusId; post.InReplyToUser = status.ToUser; post.InReplyToUserId = status.ToUserId; if (status.Geo != null) post.PostGeo = new PostClass.StatusGeo { Lat = status.Geo.Coordinates[0], Lng = status.Geo.Coordinates[1] }; if (status.FromUser == null) return null; post.UserId = status.FromUserId; post.ScreenName = status.FromUser; post.Nickname = status.FromUserName.Trim(); post.ImageUrl = status.ProfileImageUrl; post.IsProtect = false; post.IsMe = post.ScreenName.ToLower().Equals(this._uname); //幻覚fav対策 var tc = TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites); post.IsFav = tc.Contains(post.StatusId) && TabInformations.GetInstance()[post.StatusId].IsFav; //HTMLに整形 string textFromApi = post.TextFromApi; post.Text = this.CreateHtmlAnchor(ref textFromApi, post.ReplyToList, entities, post.Media); post.TextFromApi = this.ReplaceTextFromApi(post.TextFromApi, entities); post.TextFromApi = WebUtility.HtmlDecode(post.TextFromApi); post.TextFromApi = post.TextFromApi.Replace("<3", "\u2661"); //Source整形 this.CreateSource(post); post.IsReply = post.ReplyToList.Contains(this._uname); post.IsExcludeReply = false; post.IsOwl = false; post.IsDm = false; return post; }
public void UpdateFromApi(TwitterDataModel.RateLimitStatus limit) { if (limit == null) throw new ArgumentNullException(); this.AccessLimit = new ApiLimit(limit.HourlyLimit, limit.RemainingHits, MyCommon.DateTimeParse(limit.ResetTime)); var mediaLimit = limit.Photos; if (mediaLimit != null) { this.MediaUploadLimit = new ApiLimit(mediaLimit.DailyLimit, mediaLimit.RemainingHits, MyCommon.DateTimeParse(mediaLimit.ResetTime)); } }
public string GetUserInfo(string screenName, ref TwitterDataModel.User user) { if (MyCommon._endingFlag) return ""; if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return ""; user = null; HttpStatusCode res; var content = ""; try { res = twCon.ShowUserInfo(screenName, ref content); } catch(Exception ex) { return "Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")"; } var err = this.CheckStatusCode(res, content); if (err != null) return err; try { user = MyCommon.CreateDataFromJson<TwitterDataModel.User>(content); } catch (SerializationException ex) { MyCommon.TraceOut(ex.Message + Environment.NewLine + content); return "Err:Json Parse Error(DataContractJsonSerializer)"; } catch (Exception ex) { MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content); return "Err:Invalid Json!"; } return ""; }
public string CreateHtmlAnchor(string text, List<string> AtList, TwitterDataModel.Entities entities, Dictionary<string, string> media) { if (entities != null) { if (entities.Urls != null) { foreach (var ent in entities.Urls) { ent.ExpandedUrl = ShortUrl.ResolveMedia(ent.ExpandedUrl, false); if (media != null && !media.ContainsKey(ent.Url)) media.Add(ent.Url, ent.ExpandedUrl); } } if (entities.Hashtags != null) { lock (this.LockObj) { this._hashList.AddRange(entities.Hashtags.Select(x => "#" + x.Text)); } } if (entities.UserMentions != null) { foreach (var ent in entities.UserMentions) { var screenName = ent.ScreenName.ToLower(); if (!AtList.Contains(screenName)) AtList.Add(screenName); } } if (entities.Media != null) { foreach (var ent in entities.Media) { if (media != null && !media.ContainsKey(ent.Url)) media.Add(ent.Url, ent.MediaUrl); } } } text = TweetFormatter.AutoLinkHtml(text, entities); text = Regex.Replace(text, "(^|[^a-zA-Z0-9_/&##@@>=.~])(sm|nm)([0-9]{1,10})", "$1<a href=\"http://www.nicovideo.jp/watch/$2$3\">$2$3</a>"); text = PreProcessUrl(text); //IDN置換 return text; }
private async Task SetRecentStatusAsync(TwitterDataModel.Status status) { var atlist = new List<string>(); if (status != null) { var html = await this.Twitter.CreateHtmlAnchorAsync(status.Text, atlist, status.Entities, null); html = this.Owner.createDetailHtml(html + " Posted at " + MyCommon.DateTimeParse(status.CreatedAt) + " via " + status.Source); this.RecentPostBrowser.DocumentText = html; } else { this.RecentPostBrowser.DocumentText = Properties.Resources.ShowUserInfo2; } }
public string CreateHtmlAnchor(string text, List<string> AtList, TwitterDataModel.Entities entities, Dictionary<string, string> media) { return this.CreateHtmlAnchorAsync(text, AtList, entities, media).Result; }