public void GetRates()
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    RateLimits limits = api.GetRateLimits();

                    Log.WriteLine("Finished getting new rate limits");

                    Dispatcher.Invoke((Action)(() =>
                    {
                        SetRateLimits(limits);
                    }));
                }
                catch (RateLimitHitException rex)
                {
                    Log.WriteLine("Failed to get rate limits because of the rate limits on rate limits checking.");

                    // Glorious invocation
                    Dispatcher.Invoke((Action)(() =>
                    {
                        TemporaryTextBox.SelectAll();

                        TemporaryTextBox.Selection.Text = "Rate limits are currently unavailable.";
                    }));
                }
            });
        }
예제 #2
0
        private List <long> GetIDs(string action_name, string screen_name)
        {
            Log.WriteLine("Started getting IDs - " + action_name);

            long        cursor = -1;
            List <long> ids    = new List <long>();

            Func <string, long, JObject> action = actions[action_name];

            bool done = false;

            RunOnUiThread(() =>
            {
                mainWin.AppStatusLabel.Content = String.Format("{0} - Getting IDs ({1})", screen_name, action_name);
            });

            while (!done)
            {
                try
                {
                    Log.WriteLine("Still getting IDs. Current cursor is : " + cursor.ToString() + " and we have a total of " + ids.Count + " ids thus far.");

                    JObject result = action(screen_name, cursor);

                    JArray json_ids    = result["ids"].Value <JArray>();
                    long   next_cursor = result["next_cursor"].Value <long>();

                    foreach (long id in json_ids)
                    {
                        ids.Add(id);
                    }

                    if (cursor == 0)
                    {
                        done = true;
                    }

                    cursor = next_cursor;
                }
                catch (RateLimitHitException rex)
                {
                    RateLimits limits = api.GetRateLimits();

                    RunOnUiThread(() => mainWin.rlWin.SetRateLimits(limits));

                    Log.WriteLine("Waiting for rate limits to reset.");

                    if (action_name == "friends" && limits.friendsIds.remaining == 0)
                    {
                        Wait(limits.friendsIds.resetTime, "Waiting for friends IDs rate to reset.");
                    }
                    else if (action_name == "friends" && limits.friendsIds.remaining == 0)
                    {
                        Wait(limits.friendsIds.resetTime, "Waiting for followers IDs rate to reset.");
                    }
                }
            }

            Log.WriteLine("Finished getting IDs");

            RunOnUiThread(() =>
            {
                mainWin.AppStatusLabel.Content = "Finished getting IDs for " + screen_name;
            });

            return(ids);
        }