public static ListViewItem GetRecordByStatus(TwitterStatus status, ref TwitterModelClass tmc) { ListViewItem item = new ListViewItem(); item.Text = status.Id.ToString(); item.Name = item.Text; item.SubItems.Add(status.User.ScreenName); item.SubItems.Add(WebUtility.HtmlDecode(GetTextWithReplacingURL(status))); item.Tag = status; if (isMentionToMe(status, ref tmc)) item.ImageIndex = 0; else if (status.User.Id == tmc.MyID) item.ImageIndex = 1; else if (status.RetweetedStatus != null) item.ImageIndex = 2; if (!tmc.FollowerID.Contains(status.User.Id)) item.ForeColor = Color.Blue; return item; }
private void Form1_Load(object sender, EventArgs e) { tabControl1.TabPages[0].Tag = listView1; tabControl1.TabPages[1].Tag = listView2; tabControl1.TabPages[2].Tag = listView3; StreamReader srApp = null; try { System.IO.Directory.SetCurrentDirectory(Application.StartupPath); srApp = new StreamReader("../../dataapp.pass", Encoding.Default); AppAccessToken = srApp.ReadLine(); AppAccessTokenSecret = srApp.ReadLine(); } catch (Exception) { String Err = "アプリケーションの秘密鍵ファイルが見当たりませんでした。" + "\nSearchDirectory:" + System.IO.Directory.GetCurrentDirectory(); MessageBox.Show(Err); Application.Exit(); } StreamReader srUser = null; try { srUser = new StreamReader("../../datauser.pass", Encoding.Default); UserAccessToken = srUser.ReadLine(); UserAccessTokenSecret = srUser.ReadLine(); } catch (Exception) { MessageBox.Show("ユーザーの秘密鍵ファイルが見当たりませんでした。"); Application.Exit(); } try { // ユーザー認証を行う tmc = new TwitterModelClass( AppAccessToken, AppAccessTokenSecret, UserAccessToken, UserAccessTokenSecret, this ); // 自分のタイムラインを取得する IEnumerable<TwitterStatus> pTimeline = tmc.service.ListTweetsOnHomeTimeline( new ListTweetsOnHomeTimelineOptions()); // 自分のタイムラインをリストに追加する foreach (TwitterStatus status in pTimeline) { listView1.Items.Add(TwitterViewClass.GetRecordByStatus(status, ref tmc)); } IEnumerable<TwitterStatus> mTimeline = tmc.service.ListTweetsMentioningMe( new ListTweetsMentioningMeOptions()); // 自分のタイムラインをリストに追加する foreach (TwitterStatus status in mTimeline) { listView2.Items.Add(TwitterViewClass.GetRecordByStatus(status, ref tmc)); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
public static void UpdateStatus(TextBox tb, ref TwitterModelClass tmc) { SendTweetOptions options = new SendTweetOptions(); tmc.service.SendTweet(options); if (tb.Tag != null) { // Mentionなら TwitterStatus mentionedStatus = (TwitterStatus)((ListViewItem)tb.Tag).Tag; options.InReplyToStatusId = mentionedStatus.Id; } options.Status = tb.Text; tmc.service.SendTweet(options); tb.Clear(); }
public static void SetAllMentionToTextBox(TextBox tb, ListViewItem item, ref TwitterModelClass tmc) { TwitterStatus status = (TwitterStatus)item.Tag; tb.Tag = item; tb.ResetText(); List<string> screenNameList = new List<string>(); screenNameList.Add(status.User.ScreenName); foreach (TwitterMention tm in status.Entities.Mentions) { screenNameList.Add(tm.ScreenName); } string MySName = tmc.MySName; screenNameList.RemoveAll((s => s == MySName)); foreach (string sname in screenNameList) { tb.Text = tb.Text + "@" + sname + " "; } tb.Focus(); tb.Select(tb.TextLength, 0); }
public static void PlaySoundOnTweet(TwitterStatus status, ref TwitterModelClass tmc) { if (isMentionToMe(status, ref tmc)) new System.Media.SoundPlayer(@"C:\WINDOWS\Media\tada.wav").Play(); else if ((ver.Major == 6 && ver.Minor >= 1) || ver.Major > 6) { // Windows 7 の機能を使用 new System.Media.SoundPlayer(@"C:\WINDOWS\Media\Windows Balloon.wav").Play(); } else { new System.Media.SoundPlayer(@"C:\WINDOWS\Media\Windows XP Balloon.wav").Play(); } }
public static void OfficialReTweet(ListViewItem item, ref TwitterModelClass tmc) { TwitterStatus status = (TwitterStatus)item.Tag; if( status.RetweetedStatus == null && TwitterControllerClass.isUserProtected(status.User)) { SystemSounds.Hand.Play(); return; } RetweetOptions options = new RetweetOptions(); options.Id = status.Id; tmc.service.Retweet(options); }
public static bool isMentionToMe(TwitterStatus status, ref TwitterModelClass tmc) { if (status.InReplyToUserId == null) return false; foreach (TwitterMention mention in status.Entities.Mentions) { if (mention.Id == tmc.MyID) return true; } return false; }
public static string GetToolTipDescription(ListViewItem item, ref TwitterModelClass tmc) { TwitterStatus status = (TwitterStatus)item.Tag; GetTweetOptions option = new GetTweetOptions(); option.Id = status.InReplyToStatusId.Value; TwitterStatus repstatus = tmc.service.GetTweet(option); string str = status.InReplyToScreenName + " says:\r\n" + repstatus.TextDecoded; return str; }