Example #1
0
        //-------------------------------------------------------------------------------
        //
        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;
        }
Example #2
0
        //-------------------------------------------------------------------------------
        /// <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;
        }
Example #3
0
        //-------------------------------------------------------------------------------
        /// <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;
        }