Пример #1
0
        private async Task <long> GetMyTweets_Backfill()
        {
            long smallestid    = 0;
            long largestid     = 0;
            int  backfillQuota = 50;
            int  backofftimer  = 30;

            do
            {
                var hometl = await UserSession.GetUserTimeline(userId : UserSession.TwitterCredentials.UserID, count : _pagingSize, maxId : smallestid);

                if (hometl.OK)
                {
                    smallestid = long.MaxValue;
                    if (hometl.Count < backfillQuota)
                    {
                        backfillQuota = hometl.Count;
                    }
                    foreach (var tweet in hometl)
                    {
                        _mytweets.OnNext(tweet);
                        if (tweet.Id < smallestid)
                        {
                            smallestid = tweet.Id;
                        }
                        if (tweet.Id > largestid)
                        {
                            largestid = tweet.Id;
                        }
                        backfillQuota--;
                    }
                    await Task.Delay(_multiFetchBackoffTimer);
                }
                else
                {
                    // The Backoff will trigger 7 times before just giving up
                    // once at 30s, 60s, 1m, 2m, 4m, 8m and then 16m
                    // note that the last call into this will be 1m above the 15 "rate limit reset" window
                    await Task.Delay(TimeSpan.FromSeconds(backofftimer));

                    if (backofftimer > _maxbackoff)
                    {
                        break;
                    }
                    backofftimer = backofftimer * 2;
                }
            } while (backfillQuota > 0);
            return(largestid);
        }