using System; using System.Collections.Generic; namespace Buypeeb { internal class Settings { public int updateInterval { get; set; } = 10 * 60; public int favouriteUpdateInterval { get; set; } = 5 * 60; public int updateIntervalCritical { get; set; } = 60; public int favouriteUpdateIntervalCritical { get; set; } = 30; public bool showSecondsInListView { get; set; } = true; public bool autosave { get; set; } = true; public bool showFavouritesAtTopOfList { get; set; } = true; public Dictionary watchlist { get; set; } public Settings() { // create a new watchlist from an empty dictionary if it's null, which should only happen if either this is the // first time the program has been run, or there's something wrong with userdata.json watchlist ??= new Dictionary(); } public YahooAuctionsItem Watch(string url, string name) { var id = BuypeebApp.IDFromURL(url); Console.WriteLine(id); watchlist[id] = new YahooAuctionsItem(id, name); return watchlist[id]; } // TRUE if the item hasn't been updated for at least interval seconds // for example, if the interval is 10, and the item hasn't been updated since 20 seconds ago, this will be TRUE public bool ItemNotUpdatedSinceInterval(YahooAuctionsItem item) { int seconds; if (item.favourite) { seconds = item.endingSoon ? favouriteUpdateIntervalCritical : favouriteUpdateInterval; } else { seconds = item.endingSoon ? updateIntervalCritical : updateInterval; } var later = item.LastUpdated.AddSeconds(seconds); return DateTime.Compare(later, DateTime.UtcNow) < 0; } } }