Compare commits
2 commits
49119fc6dc
...
82c666296a
Author | SHA1 | Date | |
---|---|---|---|
82c666296a | |||
987a28c747 |
3 changed files with 60 additions and 7 deletions
|
@ -55,6 +55,7 @@ namespace Buypeeb {
|
||||||
static SemaphoreSlim taskLimit = new SemaphoreSlim(6);
|
static SemaphoreSlim taskLimit = new SemaphoreSlim(6);
|
||||||
private Queue<string> updateQueue = new Queue<string>();
|
private Queue<string> updateQueue = new Queue<string>();
|
||||||
private IEnumerable<YahooAuctionsItem> filterQuery;
|
private IEnumerable<YahooAuctionsItem> filterQuery;
|
||||||
|
private IEnumerable<YahooAuctionsItem> outdatedItemQuery;
|
||||||
|
|
||||||
private YahooAuctionsItem selectedItem {
|
private YahooAuctionsItem selectedItem {
|
||||||
get {
|
get {
|
||||||
|
@ -115,6 +116,14 @@ namespace Buypeeb {
|
||||||
this.filterChecks[name].Active = false;
|
this.filterChecks[name].Active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only returns items that meet all of the following:
|
||||||
|
// - marked as "ready", as in, they aren't in the process of updating
|
||||||
|
// - not updated since the interval
|
||||||
|
this.outdatedItemQuery =
|
||||||
|
from item in this.settings.watchlist.Values.ToList()
|
||||||
|
where item.ready && this.settings.ItemNotUpdatedSinceInterval(item)
|
||||||
|
select item;
|
||||||
|
|
||||||
// father forgive me for i have lynned
|
// father forgive me for i have lynned
|
||||||
this.filterQuery =
|
this.filterQuery =
|
||||||
from item in this.settings.watchlist.Values.ToList()
|
from item in this.settings.watchlist.Values.ToList()
|
||||||
|
@ -155,6 +164,7 @@ namespace Buypeeb {
|
||||||
this.RenderList();
|
this.RenderList();
|
||||||
this.UpdateItems();
|
this.UpdateItems();
|
||||||
GLib.Timeout.Add(1000, new GLib.TimeoutHandler(UpdateSelectionEndTime));
|
GLib.Timeout.Add(1000, new GLib.TimeoutHandler(UpdateSelectionEndTime));
|
||||||
|
GLib.Timeout.Add(10000, new GLib.TimeoutHandler(AutoUpdateItems));
|
||||||
|
|
||||||
DeleteEvent += WindowShutdown;
|
DeleteEvent += WindowShutdown;
|
||||||
}
|
}
|
||||||
|
@ -193,11 +203,11 @@ namespace Buypeeb {
|
||||||
if (!Directory.Exists(this.location)) {
|
if (!Directory.Exists(this.location)) {
|
||||||
Directory.CreateDirectory(this.location);
|
Directory.CreateDirectory(this.location);
|
||||||
}
|
}
|
||||||
if (!File.Exists(p)) {
|
|
||||||
var fs = File.CreateText(p);
|
using (StreamWriter fs = File.CreateText(p)) {
|
||||||
fs.Close();
|
fs.Write(j);
|
||||||
}
|
}
|
||||||
File.WriteAllText(System.IO.Path.Combine(this.location, "userdata.json"), j);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateThread(string id) {
|
private void UpdateThread(string id) {
|
||||||
|
@ -519,10 +529,10 @@ namespace Buypeeb {
|
||||||
if (sd.Run() == (int)ResponseType.Accept) {
|
if (sd.Run() == (int)ResponseType.Accept) {
|
||||||
try {
|
try {
|
||||||
if (!File.Exists(sd.Filename)) {
|
if (!File.Exists(sd.Filename)) {
|
||||||
var fs = File.CreateText(sd.Filename);
|
using (StreamWriter fs = File.CreateText(sd.Filename)) {
|
||||||
fs.Close();
|
fs.Write(JsonSerializer.Serialize(this.settings, jsonOptions));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
File.WriteAllText(sd.Filename, JsonSerializer.Serialize(this.settings, jsonOptions));
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Console.WriteLine(e);
|
Console.WriteLine(e);
|
||||||
|
@ -674,6 +684,24 @@ namespace Buypeeb {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool AutoUpdateItems() {
|
||||||
|
if (this.queueActive) {
|
||||||
|
// don't autoupdate if the queue is active
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var item in this.outdatedItemQuery) {
|
||||||
|
updateQueue.Enqueue(item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateQueue.TryPeek(out string _)) {
|
||||||
|
// there's at least one item in the queue
|
||||||
|
this.ProcessUpdateQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// column renderers
|
// column renderers
|
||||||
|
|
||||||
private void RenderColumnFavourite(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
private void RenderColumnFavourite(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
||||||
|
|
24
Settings.cs
24
Settings.cs
|
@ -27,5 +27,29 @@ namespace Buypeeb {
|
||||||
this.watchlist[id] = new YahooAuctionsItem(id, name);
|
this.watchlist[id] = new YahooAuctionsItem(id, name);
|
||||||
return this.watchlist[id];
|
return this.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 = 1000;
|
||||||
|
if (item.favourite) {
|
||||||
|
if (item.endingSoon) {
|
||||||
|
seconds = this.favouriteUpdateIntervalCritical;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
seconds = this.favouriteUpdateInterval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (item.endingSoon) {
|
||||||
|
seconds = this.updateIntervalCritical;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
seconds = this.updateInterval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var later = item.lastUpdated.AddSeconds(seconds);
|
||||||
|
return DateTime.Compare(later, DateTime.UtcNow) < 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace Buypeeb {
|
||||||
public bool endingToday { get { return this.endDate.DayOfYear == DateTime.UtcNow.DayOfYear; } }
|
public bool endingToday { get { return this.endDate.DayOfYear == DateTime.UtcNow.DayOfYear; } }
|
||||||
public bool hasWinPrice { get { return this.winPrice != 0; } }
|
public bool hasWinPrice { get { return this.winPrice != 0; } }
|
||||||
private bool success { get; set; } // TODO: custom setter that throws an exception if set to false or something idk
|
private bool success { get; set; } // TODO: custom setter that throws an exception if set to false or something idk
|
||||||
|
public bool endingSoon { get { return DateTime.Compare(DateTime.UtcNow.AddMinutes(10), this.endDate) > 0; } }
|
||||||
|
|
||||||
public YahooAuctionsItem(string id, string name) {
|
public YahooAuctionsItem(string id, string name) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
Loading…
Reference in a new issue