private bool ReachedTwitterLimits(ApplicationSettings.EraseTypes tweetsEraseType, out DateTime rateLimitReset)
        {
            var helpResponse =
                (from help in twitterCtx.Help
                     where help.Type == HelpType.RateLimits
                     select help)
                    .SingleOrDefault();

            if(helpResponse == null)
            {
                // fail quickly, assume limits are hit
                rateLimitReset = DateTime.Now.AddSeconds(15);   // retry in 15 seconds

                return true;
            }

            var favsRemainingLimits = helpResponse.RateLimits["favorites"].Where(limit => limit.Resource.ToLowerInvariant() == "/favorites/list").FirstOrDefault();
            var sentDMsRemainingLimits = helpResponse.RateLimits["direct_messages"].Where(limit => limit.Resource.ToLowerInvariant() == "/direct_messages/sent").FirstOrDefault();
            var receivedDMsRemainingLimits = helpResponse.RateLimits["direct_messages"].Where(limit => limit.Resource.ToLowerInvariant() == "/direct_messages").FirstOrDefault();

            // The following is OK since the app works only in one given mode: either fetching favorites or DMs
            if(favsRemainingLimits.Remaining == 0)
            {
                rateLimitReset = FromUnixTime(favsRemainingLimits.Reset);
                return true;
            }

            if (sentDMsRemainingLimits.Remaining == 0)
            {
                rateLimitReset = FromUnixTime(sentDMsRemainingLimits.Reset);
                return true;
            }

            if (receivedDMsRemainingLimits.Remaining == 0)
            {
                rateLimitReset = FromUnixTime(receivedDMsRemainingLimits.Reset);
                return true;
            }

            rateLimitReset = DateTime.UtcNow;
            return false;
        }
Ejemplo n.º 2
0
 public static void SetApplicationSettings(ApplicationSettings settings)
 {
     Application.Current.Properties["SETTINGS"] = settings;
 }