private bool UnderThreshold() { TimeSpan itemAge = DateTime.UtcNow - Settings.Instance.LastUsageCheck; TimeSpan age = new TimeSpan(1, 0, 0, 0); if (itemAge > age || Settings.Instance.LastUsageCheck == DateTime.MinValue) { ApiCounts counts = WallpaperAbyssApiV2.WallpaperAbyss.GetCounts(); Settings.Instance.LastUsage = counts.Count; Settings.Instance.LastUsageCheck = DateTime.Now; } if (Settings.Instance.LastUsage > Settings.Instance.MaxQueries * 0.9) { return(false); } string[] files = Directory.GetFiles(Settings.Instance.CacheDirectory); long size = 0; foreach (string file in files) { size += new FileInfo(file).Length; } if (size / 1048576 > Settings.Instance.MaxCacheSize * 0.9) { return(false); } itemAge = DateTime.UtcNow - Settings.Instance.LastFetch; age = new TimeSpan(0, 0, 10, 0); if (itemAge < age) { return(false); } return(true); }
/// <summary> /// Checks the Wallpaper Abyss API calls and how many have been made. /// Ensures we don't go over API the threshold. /// </summary> /// <returns>true if still under the max queries for the month.</returns> private bool UnderThreshold() { try { TimeSpan itemAge = DateTime.UtcNow - Settings.Instance.LastUsageCheck; TimeSpan age = new TimeSpan(1, 0, 0, 0); if (itemAge > age || Settings.Instance.LastUsageCheck == DateTime.MinValue) { ApiCounts counts = WallpaperAbyssApiV2.WallpaperAbyss.GetCounts(); Settings.Instance.LastUsage = counts.Count; Settings.Instance.LastUsageCheck = DateTime.Now; } if (Settings.Instance.LastUsage > Settings.Instance.MaxQueries * 0.9) { return(false); } int size = Settings.Instance.CacheSize(); if (size > Settings.Instance.MaxCacheSize * 0.9) { return(false); } itemAge = DateTime.UtcNow - Settings.Instance.LastFetch; age = new TimeSpan(0, 0, 10, 0); if (itemAge < age && size > Settings.Instance.MaxCacheSize * 0.3) { return(false); } } catch (Exception) { } return(true); }