//------------------------------------------------------------------------------- /// <summary> /// より新しいツイートを取得します。 /// </summary> /// <param name="uctldisp">更新を行うUctlDispTwit</param> /// <returns>取得に成功したか</returns> private bool GetMoreRecentTweets(UctlDispTwit uctldisp, long since_id) { IEnumerable<TwitData> d; try { if (uctldisp == uctlDispHome) { d = Twitter.statuses_home_timeline(count: SettingsData.RenewGetNum_Home, since_id: since_id); if (_friendIDSet != null) { d = d.Where(twitdata => StatusFilter.ThroughFilters(twitdata, SettingsData.Filters, CheckIncludeFriendIDs)); } } else if (uctldisp == uctlDispReply) { d = Twitter.statuses_mentions_timeline(count: SettingsData.RenewGetNum_Reply, since_id: since_id); } else if (uctldisp == uctlDispHistory) { d = Twitter.statuses_user_timeline(count: SettingsData.RenewGetNum_History, since_id: since_id, include_rts: true); } else if (uctldisp == uctlDispDirect) { d = Twitter.direct_messages(count: SettingsData.RenewGetNum_Direct, since_id: since_id) .Concat(Twitter.direct_messages_sent(count: SettingsData.RenewGetNum_Direct, since_id: since_id)) .OrderByDescending(twdata => twdata.StatusID); } else { TabData tabdata; lock (SettingsData.TabDataDic) { tabdata = SettingsData.TabDataDic[(string)uctldisp.Tag]; } switch (tabdata.SearchType) { case TabSearchType.Keyword: var ret = Twitter.search_tweets(q: tabdata.SearchWord, count: tabdata.RenewGetNum, since_id: since_id); d = ret.Item1; break; case TabSearchType.User: d = Twitter.statuses_user_timeline(screen_name: tabdata.SearchWord, count: tabdata.RenewGetNum, since_id: since_id, include_rts: true); break; case TabSearchType.List: d = Twitter.lists_statuses(slug: tabdata.SearchWord, owner_screen_name: tabdata.ListOwner, count: tabdata.RenewGetNum, since_id: since_id, include_rts: true); break; default: Debug.Assert(false, "異常な検索タイプ"); d = new TwitData[0]; break; } } } catch (TwitterAPIException ex) { tssLabel.SetText(Twitter.MakeTwitterAPIExceptionStr(ex), ERROR_STATUSBAR_DISP_TIMES); SYSTEMSOUND.Play(); return false; } this.Invoke((Action)(() => { uctldisp.AddData(d, true); /* tsslRestAPI.Text = string.Format(REST_API_FORMAT, Twitter.API_Rest, Twitter.API_Max); */ })); return true; }
//------------------------------------------------------------------------------- /// <summary> /// UctlDispTwitのイベントを登録します。 /// </summary> /// <param name="uctlDisp"></param> public void RegisterUctlDispTwitEvent(UctlDispTwit uctlDisp) { uctlDisp.RowContextMenu_Click += TwitMenu_RowContextmenu_Click; uctlDisp.EntityEvent += TwitMenu_EntityEvent; uctlDisp.TweetItemClick += DispTwit_TweetItemClick; }
//------------------------------------------------------------------------------- /// <summary> /// タブと表示コントロールの設定を行います。SettingsData設定後に行ってください。 /// </summary> /// <param name="tabpage"></param> /// <param name="uctlDisp"></param> private void ConfigTabAndUserDispControl(TabPageEx tabpage, UctlDispTwit uctlDisp) { uctlDisp.ImageListWrapper = imageListWrapper; uctlDisp.CheckIncludeFollowerFunc = CheckIncludeFollowerIDs; _dispTwitDic.Add(tabpage, uctlDisp); RegisterUctlDispTwitEvent(uctlDisp); SetAutoRenewData(uctlDisp); }
//------------------------------------------------------------------------------- // private void SetAutoRenewData(UctlDispTwit dispTwit) { AutoRenewData data = new AutoRenewData() { IsForce = true, Standard = DateTime.Now, }; if (dispTwit == uctlDispHome) { data.Interval = new TimeSpan(0, 0, SettingsData.GetInterval_Home); } else if (dispTwit == uctlDispReply) { data.Interval = new TimeSpan(0, 0, SettingsData.GetInterval_Reply); } else if (dispTwit == uctlDispHistory) { data.Interval = new TimeSpan(0, 0, SettingsData.GetInterval_History); } else if (dispTwit == uctlDispDirect) { data.Interval = new TimeSpan(0, 0, SettingsData.GetInterval_Direct); } else { lock (SettingsData.TabDataDic) { data.Interval = new TimeSpan(0, 0, SettingsData.TabDataDic[(string)dispTwit.Tag].GetInterval); } } tssLabel.SetText(STR_WAITING_AUTORENEWDATA); LockAndProcess(_autoRenewDic, () => { tssLabel.RemoveText(STR_WAITING_AUTORENEWDATA); _autoRenewDic.Add(dispTwit, data); }); }
//------------------------------------------------------------------------------- /// <summary> /// <para>タブとその内部の作成と設定を行います。</para> /// <para>SettingsDataへの辞書項目追加を行ってからこのメソッドを行えばタブ作成が完了します。</para> /// </summary> /// <param name="tabdata"></param> /// <param name="selectTab">タブを選択するか</param> private void MakeTab(TabData tabdata, bool selectTab) { TabPageEx newtabpg = new TabPageEx(tabdata.TabName) { Tag = tabdata.TabName }; UctlDispTwit newDispTwit = new UctlDispTwit() { AutoScroll = true, BorderStyle = BorderStyle.FixedSingle, Dock = DockStyle.Fill, Tag = tabdata.TabName }; newtabpg.Controls.Add(newDispTwit); tabTwitDisp.TabPages.Add(newtabpg); lock (SettingsData.TabDataDic) { newtabpg.ToolTipText = TabDataToString(SettingsData.TabDataDic[(string)newtabpg.Tag]); } ConfigTabAndUserDispControl(newtabpg, newDispTwit); if (selectTab) { tabTwitDisp.SelectedTab = newtabpg; } }
//------------------------------------------------------------------------------- /// <summary> /// 発言取得を別スレッドで行います /// </summary> /// <param name="getFunc">取得関数</param> /// <param name="uctlDisp">取得対象コントロール</param> /// <param name="invokingMsg">処理中表示メッセージ</param> private void InvokeTweetGet(Func<UctlDispTwit, long, bool> getFunc, long standard_id, UctlDispTwit uctlDisp, string invokingMsg) { tssLabel.SetText(invokingMsg); Utilization.InvokeTransaction( () => { try { getFunc(uctlDisp, standard_id); } catch (TwitterAPIException ex) { tssLabel.SetText(Twitter.MakeTwitterAPIExceptionStr(ex), ERROR_STATUSBAR_DISP_TIMES); SYSTEMSOUND.Play(); return; } }, () => tssLabel.RemoveText(invokingMsg) ); }
//------------------------------------------------------------------------------- // private bool GetSpecifyTimeTweets(UctlDispTwit uctldisp, bool useFromDateTime, DateTime dtFrom, bool useToDateTime, DateTime dtTo) { const int MAX_HOME = 800; const int MAX_MENTION = 800; const int MAX_USER = 3200; const int MAX_SEARCH = 1500; const int MAX_LIST = 800; if (useFromDateTime && useToDateTime && dtFrom.CompareTo(dtTo) > 0) { DateTime tmp = dtFrom; dtFrom = dtTo; dtTo = dtFrom; } // 間にあるかを判別する関数 Func<DateTime, DateTime, DateTime, bool> dtbetween = (dt, dtfrom, dtto) => (dt.CompareTo(dtfrom) >= 0) && (dt.CompareTo(dtto) <= 0); Func<DateTime, bool> inbetween = (dt) => !(useFromDateTime && dt.CompareTo(dtFrom) < 0) && !(useToDateTime && dt.CompareTo(dtTo) > 0); List<TwitData> datalist = new List<TwitData>(); try { bool findStart = false; int i = 1; long max_id = -1; long max_id2 = -1; while (true) { IEnumerable<TwitData> d = null; if (uctldisp == uctlDispHome) { if (i == MAX_HOME / 200 + 1) { break; } // 800まで d = Twitter.statuses_home_timeline(count: 200, max_id: max_id - 1); max_id = d.Min(td => td.StatusID); if (_friendIDSet != null) { d = d.Where(twitdata => StatusFilter.ThroughFilters(twitdata, SettingsData.Filters, CheckIncludeFriendIDs)); } } else if (uctldisp == uctlDispReply) { if (i == MAX_MENTION / 200 + 1) { break; } // 800まで d = Twitter.statuses_mentions_timeline(count: 200, max_id: max_id - 1); max_id = d.Min(td => td.StatusID); } else if (uctldisp == uctlDispHistory) { if (i == MAX_USER / 200 + 1) { break; } // 3200まで d = Twitter.statuses_user_timeline(count: 200, max_id: max_id - 1, include_rts: true); max_id = d.Min(td => td.StatusID); } else if (uctldisp == uctlDispDirect) { // ?まで(暫定200) var d1 = Twitter.direct_messages(count: 200, max_id: max_id - 1); max_id = d1.Min(td => td.StatusID); var d2 = Twitter.direct_messages_sent(count: 200, max_id: max_id2 - 1); max_id2 = d2.Min(td => td.StatusID); d = d1.Concat(d2) .OrderByDescending(twdata => twdata.StatusID); break; } else { TabData tabdata; lock (SettingsData.TabDataDic) { tabdata = SettingsData.TabDataDic[(string)uctldisp.Tag]; } bool isBreak = false; switch (tabdata.SearchType) { case TabSearchType.Keyword: if (i == MAX_SEARCH / 100 + 1) { isBreak = true; break; }// 1500まで var ret = Twitter.search_tweets(q: tabdata.SearchWord, count: 100, max_id: max_id - 1); d = ret.Item1; max_id = d.Min(td => td.StatusID); break; case TabSearchType.User: if (i == MAX_USER / 200 + 1) { isBreak = true; break; }// 3200まで d = Twitter.statuses_user_timeline(screen_name: tabdata.SearchWord, count: 200, max_id: max_id - 1, include_rts: true); max_id = d.Min(td => td.StatusID); break; case TabSearchType.List: if (i == MAX_LIST / 200 + 1) { isBreak = true; break; }// 800まで d = Twitter.lists_statuses(slug: tabdata.SearchWord, owner_screen_name: tabdata.ListOwner, count: 200, max_id: max_id - 1, include_rts: true); max_id = d.Min(td => td.StatusID); break; default: Debug.Assert(false, "異常な検索タイプ"); isBreak = true; break; } if (isBreak) { break; } } if (d.DefaultIfEmpty() == default(TwitData)) { break; } if (!findStart) { findStart = !useToDateTime || dtbetween(dtTo, d.Last().Time, d.First().Time); } datalist.AddRange(d); if (findStart && useFromDateTime && dtbetween(dtFrom, d.Last().Time, d.First().Time)) { break; } i++; /* this.Invoke((Action)(() => tsslRestAPI.Text = string.Format(REST_API_FORMAT, Twitter.API_Rest, Twitter.API_Max))); */ } } catch (TwitterAPIException ex) { tssLabel.SetText(Twitter.MakeTwitterAPIExceptionStr(ex), ERROR_STATUSBAR_DISP_TIMES); SYSTEMSOUND.Play(); return false; } finally { this.Invoke((Action)(() => { uctldisp.AddData(datalist.Where((td) => inbetween(td.Time)).ToArray()); /* tsslRestAPI.Text = string.Format(REST_API_FORMAT, Twitter.API_Rest, Twitter.API_Max); */ })); } return true; }
//------------------------------------------------------------------------------- /// <summary> /// 最新のツイートを取得します。 /// </summary> /// <param name="uctldisp">更新を行うUctlDispTwit</param> /// <returns>取得に成功したか</returns> private bool GetMostRecentTweets(UctlDispTwit uctldisp) { IEnumerable<TwitData> d; bool isFirst = (uctldisp.MaxTweetID == -1); try { //if (uctldisp == uctlDispPublic) { // d = _twitter.statuses_public_timeline(); //} //else if (uctldisp == uctlDispHome) { int iCount = (isFirst) ? SettingsData.FirstGetNum_Home : SettingsData.RenewGetNum_Home; d = Twitter.statuses_home_timeline(count: iCount); if (_friendIDSet != null) { d = d.Where(twitdata => StatusFilter.ThroughFilters(twitdata, SettingsData.Filters, CheckIncludeFriendIDs)); } } else if (uctldisp == uctlDispReply) { int iCount = (isFirst) ? SettingsData.FirstGetNum_Reply : SettingsData.RenewGetNum_Reply; d = Twitter.statuses_mentions_timeline(count: iCount); } else if (uctldisp == uctlDispHistory) { int iCount = (isFirst) ? SettingsData.FirstGetNum_History : SettingsData.RenewGetNum_History; d = Twitter.statuses_user_timeline(count: iCount, include_rts: true); } else if (uctldisp == uctlDispDirect) { int iCount = (isFirst) ? SettingsData.FirstGetNum_Direct : SettingsData.RenewGetNum_Direct; d = Twitter.direct_messages(count: iCount) .Concat(Twitter.direct_messages_sent(count: iCount)) .OrderByDescending(twdata => twdata.StatusID); } else { TabData tabdata; lock (SettingsData.TabDataDic) { tabdata = SettingsData.TabDataDic[(string)uctldisp.Tag]; } int iCount = (isFirst) ? tabdata.FirstGetNum : tabdata.RenewGetNum; switch (tabdata.SearchType) { case TabSearchType.Keyword: var ret = Twitter.search_tweets(q: tabdata.SearchWord, count: iCount); d = ret.Item1; break; case TabSearchType.User: d = Twitter.statuses_user_timeline(screen_name: tabdata.SearchWord, count: iCount, include_rts: true); break; case TabSearchType.List: d = Twitter.lists_statuses(slug: tabdata.SearchWord, owner_screen_name: tabdata.ListOwner, count: iCount, include_rts: true); break; default: Debug.Assert(false, "異常な検索タイプ"); d = new TwitData[0]; break; } } } catch (TwitterAPIException ex) { tssLabel.SetText(Twitter.MakeTwitterAPIExceptionStr(ex), ERROR_STATUSBAR_DISP_TIMES); SYSTEMSOUND.Play(); return false; } this.Invoke((Action)(() => { string baloontext = uctldisp.AddData(d); /* tsslRestAPI.Text = string.Format(REST_API_FORMAT, Twitter.API_Rest, Twitter.API_Max); */ // バルーン設定 if (!isFirst) { if (uctldisp == uctlDispReply && SettingsData.DisplayReplyBaloon) { PopupTasktrayReply(baloontext); } else if (uctldisp == uctlDispDirect && SettingsData.DisplayDMBaloon) { PopupTasktrayDM(baloontext); } } })); return true; }