code cleanup, replace WebClient w/ HttpClient
This commit is contained in:
parent
6977f74d6e
commit
5298a97c18
6 changed files with 162 additions and 164 deletions
|
@ -2,9 +2,6 @@ using Gtk;
|
||||||
|
|
||||||
namespace Buypeeb {
|
namespace Buypeeb {
|
||||||
internal class AddItemDialogue : Dialog {
|
internal class AddItemDialogue : Dialog {
|
||||||
public Entry entryURL { get; }
|
|
||||||
public Entry entryName { get; }
|
|
||||||
|
|
||||||
public AddItemDialogue() : this(new Builder("add.glade")) { }
|
public AddItemDialogue() : this(new Builder("add.glade")) { }
|
||||||
|
|
||||||
private AddItemDialogue(Builder builder) : base(builder.GetObject("DialogueAdd").Handle) {
|
private AddItemDialogue(Builder builder) : base(builder.GetObject("DialogueAdd").Handle) {
|
||||||
|
@ -15,6 +12,9 @@ namespace Buypeeb {
|
||||||
DeleteEvent += Window_Shutdown;
|
DeleteEvent += Window_Shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Entry entryURL { get; }
|
||||||
|
public Entry entryName { get; }
|
||||||
|
|
||||||
private static void Window_Shutdown(object sender, DeleteEventArgs args) {
|
private static void Window_Shutdown(object sender, DeleteEventArgs args) {
|
||||||
Application.Quit();
|
Application.Quit();
|
||||||
}
|
}
|
||||||
|
|
201
MainWindow.cs
201
MainWindow.cs
|
@ -24,6 +24,7 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
@ -39,65 +40,28 @@ using Timeout = GLib.Timeout;
|
||||||
namespace Buypeeb {
|
namespace Buypeeb {
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
internal class MainWindow : Window {
|
internal class MainWindow : Window {
|
||||||
private readonly string location;
|
// ...to here.
|
||||||
private readonly JsonSerializerOptions jsonOptions;
|
|
||||||
|
private static readonly SemaphoreSlim TaskLimit = new(6);
|
||||||
|
private readonly Builder builder;
|
||||||
|
private readonly Label endingLabel;
|
||||||
|
private readonly Dictionary<string, CheckButton> filterChecks = new();
|
||||||
|
private readonly HttpClient httpClient;
|
||||||
|
|
||||||
private readonly ListStore items;
|
private readonly ListStore items;
|
||||||
private Settings settings;
|
|
||||||
private readonly TreeView itemTreeView;
|
private readonly TreeView itemTreeView;
|
||||||
private readonly Builder builder;
|
private readonly JsonSerializerOptions jsonOptions;
|
||||||
|
private readonly string location;
|
||||||
|
private readonly SearchEntry searchEntry;
|
||||||
|
|
||||||
// TODO: whenever we get something from the builder, cache it for later
|
// TODO: whenever we get something from the builder, cache it for later
|
||||||
// that way we don't need to constantly do "builder.GetObject"s
|
// that way we don't need to constantly do "builder.GetObject"s
|
||||||
// when that is done, you can use the cache array to replace everything from here...
|
// when that is done, you can use the cache array to replace everything from here...
|
||||||
|
|
||||||
private readonly Box selectionViewBox;
|
private readonly Box selectionViewBox;
|
||||||
private readonly Label endingLabel;
|
private readonly Queue<string> updateQueue = new();
|
||||||
private bool queueActive;
|
private bool queueActive;
|
||||||
private readonly SearchEntry searchEntry;
|
private Settings settings;
|
||||||
private readonly Dictionary<string, CheckButton> filterChecks = new Dictionary<string, CheckButton>();
|
|
||||||
|
|
||||||
// ...to here.
|
|
||||||
|
|
||||||
private static readonly SemaphoreSlim TaskLimit = new SemaphoreSlim(6);
|
|
||||||
private readonly Queue<string> updateQueue = new Queue<string>();
|
|
||||||
|
|
||||||
private IEnumerable<YahooAuctionsItem> filterQuery =>
|
|
||||||
// father forgive me for i have lynned
|
|
||||||
from item in settings.watchlist.Values.ToList()
|
|
||||||
where (item.favourite != filterChecks["Favourites"].Active ||
|
|
||||||
item.favourite == filterChecks["NonFavourites"].Active) &&
|
|
||||||
(item.Available != filterChecks["Active"].Active ||
|
|
||||||
item.Available == filterChecks["Ended"].Active) &&
|
|
||||||
(item.endingToday != filterChecks["EndingToday"].Active ||
|
|
||||||
item.endingToday == filterChecks["EndingAfterToday"].Active) &&
|
|
||||||
(item.hasWinPrice != filterChecks["WithWinPrice"].Active ||
|
|
||||||
item.hasWinPrice == filterChecks["WithNoWinPrice"].Active) &&
|
|
||||||
(string.IsNullOrWhiteSpace(searchEntry.Text) ||
|
|
||||||
item.name.ToLower().Contains(searchEntry.Text.ToLower()) ||
|
|
||||||
item.originalName.ToLower().Contains(searchEntry.Text.ToLower()))
|
|
||||||
select item;
|
|
||||||
|
|
||||||
private IEnumerable<YahooAuctionsItem> outdatedItemQuery =>
|
|
||||||
// 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
|
|
||||||
// - hasn't already ended
|
|
||||||
from item in settings.watchlist.Values.ToList()
|
|
||||||
where item.Ready && settings.ItemNotUpdatedSinceInterval(item) && item.endDate.CompareTo(DateTime.UtcNow) > 0
|
|
||||||
select item;
|
|
||||||
|
|
||||||
private YahooAuctionsItem selectedItem {
|
|
||||||
get {
|
|
||||||
if (itemTreeView.Selection.CountSelectedRows() == 0) {
|
|
||||||
// avoids incurring the wrath of Gtk-CRITICAL **
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemTreeView.Selection.GetSelected(out var iter);
|
|
||||||
return (YahooAuctionsItem) itemTreeView.Model.GetValue(iter, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MainWindow() : this(new Builder("main.glade")) {
|
public MainWindow() : this(new Builder("main.glade")) {
|
||||||
}
|
}
|
||||||
|
@ -108,16 +72,20 @@ namespace Buypeeb {
|
||||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
|
if (Environment.OSVersion.Platform ==
|
||||||
// C:\Users\Beebus\AppData\Roaming\Lynnear Software\buypeeb
|
PlatformID.Win32NT) // C:\Users\Beebus\AppData\Roaming\Lynnear Software\buypeeb
|
||||||
|
{
|
||||||
location = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
location = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
"Lynnear Software", "buypeeb");
|
"Lynnear Software", "buypeeb");
|
||||||
} else {
|
} else // ~/.config/Lynnear Software/buypeeb
|
||||||
// ~/.config/Lynnear Software/buypeeb
|
{
|
||||||
location = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config",
|
location = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config",
|
||||||
"Lynnear Software", "buypeeb");
|
"Lynnear Software", "buypeeb");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialise http client
|
||||||
|
httpClient = new HttpClient();
|
||||||
|
|
||||||
var userdata = System.IO.Path.Combine(location, "userdata.json");
|
var userdata = System.IO.Path.Combine(location, "userdata.json");
|
||||||
if (File.Exists(userdata)) {
|
if (File.Exists(userdata)) {
|
||||||
try {
|
try {
|
||||||
|
@ -188,6 +156,43 @@ namespace Buypeeb {
|
||||||
DeleteEvent += WindowShutdown;
|
DeleteEvent += WindowShutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<YahooAuctionsItem> filterQuery =>
|
||||||
|
// father forgive me for i have lynned
|
||||||
|
from item in settings.watchlist.Values.ToList()
|
||||||
|
where (item.favourite != filterChecks["Favourites"].Active ||
|
||||||
|
item.favourite == filterChecks["NonFavourites"].Active) &&
|
||||||
|
(item.Available != filterChecks["Active"].Active ||
|
||||||
|
item.Available == filterChecks["Ended"].Active) &&
|
||||||
|
(item.endingToday != filterChecks["EndingToday"].Active ||
|
||||||
|
item.endingToday == filterChecks["EndingAfterToday"].Active) &&
|
||||||
|
(item.hasWinPrice != filterChecks["WithWinPrice"].Active ||
|
||||||
|
item.hasWinPrice == filterChecks["WithNoWinPrice"].Active) &&
|
||||||
|
(string.IsNullOrWhiteSpace(searchEntry.Text) ||
|
||||||
|
item.name.ToLower().Contains(searchEntry.Text.ToLower()) ||
|
||||||
|
item.originalName.ToLower().Contains(searchEntry.Text.ToLower()))
|
||||||
|
select item;
|
||||||
|
|
||||||
|
private IEnumerable<YahooAuctionsItem> outdatedItemQuery =>
|
||||||
|
// 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
|
||||||
|
// - hasn't already ended
|
||||||
|
from item in settings.watchlist.Values.ToList()
|
||||||
|
where item.Ready && settings.ItemNotUpdatedSinceInterval(item) && item.endDate.CompareTo(DateTime.UtcNow) > 0
|
||||||
|
select item;
|
||||||
|
|
||||||
|
private YahooAuctionsItem selectedItem {
|
||||||
|
get {
|
||||||
|
if (itemTreeView.Selection.CountSelectedRows() == 0) // avoids incurring the wrath of Gtk-CRITICAL **
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemTreeView.Selection.GetSelected(out var iter);
|
||||||
|
return (YahooAuctionsItem) itemTreeView.Model.GetValue(iter, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void WindowShutdown(object sender, DeleteEventArgs args) {
|
private void WindowShutdown(object sender, DeleteEventArgs args) {
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
Application.Quit();
|
Application.Quit();
|
||||||
|
@ -196,7 +201,7 @@ namespace Buypeeb {
|
||||||
// general behaviour
|
// general behaviour
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// gets the path and iter for a given item id.
|
/// gets the path and iter for a given item id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">the item id to find in the treeview</param>
|
/// <param name="id">the item id to find in the treeview</param>
|
||||||
/// <returns>a tuple of (TreePath, TreeIter)</returns>
|
/// <returns>a tuple of (TreePath, TreeIter)</returns>
|
||||||
|
@ -219,7 +224,7 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// saves the settings to userdata.json.
|
/// saves the settings to userdata.json.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void SaveSettings() {
|
private void SaveSettings() {
|
||||||
var j = JsonSerializer.Serialize(settings, jsonOptions);
|
var j = JsonSerializer.Serialize(settings, jsonOptions);
|
||||||
|
@ -234,10 +239,10 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// updates the item with the given id. this method blocks and is intended to be run from a task.
|
/// updates the item with the given id. this method blocks and is intended to be run from a task.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">the id of the item to update</param>
|
/// <param name="id">the id of the item to update</param>
|
||||||
private void UpdateThread(string id) {
|
private async void UpdateThread(string id) {
|
||||||
var item = settings.watchlist[id];
|
var item = settings.watchlist[id];
|
||||||
// Console.WriteLine($"Updating {id}...");
|
// Console.WriteLine($"Updating {id}...");
|
||||||
// set item.ready to false to show that it's still being updated
|
// set item.ready to false to show that it's still being updated
|
||||||
|
@ -253,18 +258,13 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
using (var client = new WebClient()) {
|
try {
|
||||||
// TODO: download should have timeout
|
item.Update(await httpClient.GetStringAsync(item.url));
|
||||||
try {
|
} catch (HttpRequestException e) {
|
||||||
// item.Update(client.DownloadString("http://10.0.0.10/poop"));
|
if (e.StatusCode == HttpStatusCode.NotFound) {
|
||||||
item.Update(client.DownloadString(item.url));
|
item.AuctionEnded();
|
||||||
} catch (WebException e) {
|
} else {
|
||||||
if (((HttpWebResponse) e.Response).StatusCode == HttpStatusCode.NotFound) {
|
Console.WriteLine($"Failed to update item ${id}! Status code ${e.StatusCode}: ${e.Message}");
|
||||||
// the auction has ended (or otherwise been removed)
|
|
||||||
item.AuctionEnded();
|
|
||||||
} else {
|
|
||||||
Console.WriteLine($"Failed to update item ${id}!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// processes the update queue. this is a blocking function.
|
/// processes the update queue. this is a blocking function.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ProcessUpdateQueue() {
|
private void ProcessUpdateQueue() {
|
||||||
queueActive = true;
|
queueActive = true;
|
||||||
|
@ -297,7 +297,7 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// updates an item with the given id with a new task.
|
/// updates an item with the given id with a new task.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">the id of the task to update</param>
|
/// <param name="id">the id of the task to update</param>
|
||||||
/// <param name="renderListWhenDone">whether or not to call this.RenderList() after updating the item</param>
|
/// <param name="renderListWhenDone">whether or not to call this.RenderList() after updating the item</param>
|
||||||
|
@ -319,8 +319,8 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// add every item in the watchlist to the update queue. if the update queue is already being processed
|
/// add every item in the watchlist to the update queue. if the update queue is already being processed
|
||||||
/// (this.queueActive), this will do nothing.
|
/// (this.queueActive), this will do nothing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateItems() {
|
private void UpdateItems() {
|
||||||
if (queueActive) {
|
if (queueActive) {
|
||||||
|
@ -347,7 +347,7 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// updates the selection view, displaying the id, name, etc. for the currently selected item.
|
/// updates the selection view, displaying the id, name, etc. for the currently selected item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateSelectionView() {
|
private void UpdateSelectionView() {
|
||||||
// get the currently selected item
|
// get the currently selected item
|
||||||
|
@ -397,7 +397,7 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// opens a URL in the user's browser.
|
/// opens a URL in the user's browser.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url">the url to open</param>
|
/// <param name="url">the url to open</param>
|
||||||
private static void OpenUrl(string url) {
|
private static void OpenUrl(string url) {
|
||||||
|
@ -409,7 +409,7 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a simple MessageDialog constructor.
|
/// a simple MessageDialog constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">the MessageDialog's format</param>
|
/// <param name="message">the MessageDialog's format</param>
|
||||||
/// <param name="buttonsType">the MessageDialog's bt</param>
|
/// <param name="buttonsType">the MessageDialog's bt</param>
|
||||||
|
@ -427,7 +427,7 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// show a simple entry dialogue that allows the user to enter text and either cancel or submit it.
|
/// show a simple entry dialogue that allows the user to enter text and either cancel or submit it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="title">the title of the entry dialogue</param>
|
/// <param name="title">the title of the entry dialogue</param>
|
||||||
/// <param name="message">the prompt that should be presented to the user</param>
|
/// <param name="message">the prompt that should be presented to the user</param>
|
||||||
|
@ -470,7 +470,7 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// gets the sort type selected by the user - "NameDescending", "EndingAscending", etc.
|
/// gets the sort type selected by the user - "NameDescending", "EndingAscending", etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>the id of the radiobutton without the "Sort" prefix</returns>
|
/// <returns>the id of the radiobutton without the "Sort" prefix</returns>
|
||||||
private string GetSortType() {
|
private string GetSortType() {
|
||||||
|
@ -487,8 +487,8 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// clears the treeview's liststore and adds everything in the watchlist to it, obeying sort order. tries to
|
/// clears the treeview's liststore and adds everything in the watchlist to it, obeying sort order. tries to
|
||||||
/// reselect the item that the user had selected, if possible.
|
/// reselect the item that the user had selected, if possible.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void RenderList() {
|
private void RenderList() {
|
||||||
string id = null;
|
string id = null;
|
||||||
|
@ -498,21 +498,15 @@ namespace Buypeeb {
|
||||||
|
|
||||||
items.Clear();
|
items.Clear();
|
||||||
var values = settings.watchlist.Values;
|
var values = settings.watchlist.Values;
|
||||||
IOrderedEnumerable<YahooAuctionsItem> sorted;
|
|
||||||
var type = GetSortType();
|
var type = GetSortType();
|
||||||
if (type == "NameDescending") {
|
var sorted = type switch {
|
||||||
sorted = values.OrderByDescending(item => item.name);
|
"NameDescending" => values.OrderByDescending(item => item.name),
|
||||||
} else if (type == "NameAscending") {
|
"NameAscending" => values.OrderBy(item => item.name),
|
||||||
sorted = values.OrderBy(item => item.name);
|
"PriceDescending" => values.OrderByDescending(item => item.Price),
|
||||||
} else if (type == "PriceDescending") {
|
"PriceAscending" => values.OrderBy(item => item.Price),
|
||||||
sorted = values.OrderByDescending(item => item.Price);
|
"EndingDescending" => values.OrderByDescending(item => item.endDate),
|
||||||
} else if (type == "PriceAscending") {
|
_ => values.OrderBy(item => item.endDate),
|
||||||
sorted = values.OrderBy(item => item.Price);
|
};
|
||||||
} else if (type == "EndingDescending") {
|
|
||||||
sorted = values.OrderByDescending(item => item.endDate);
|
|
||||||
} else {
|
|
||||||
sorted = values.OrderBy(item => item.endDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.showFavouritesAtTopOfList) {
|
if (settings.showFavouritesAtTopOfList) {
|
||||||
foreach (var item in sorted.Where(item => item.favourite)) {
|
foreach (var item in sorted.Where(item => item.favourite)) {
|
||||||
|
@ -753,9 +747,7 @@ namespace Buypeeb {
|
||||||
private void ButtonSelectedRemoveClicked(object sender, EventArgs a) {
|
private void ButtonSelectedRemoveClicked(object sender, EventArgs a) {
|
||||||
var item = selectedItem;
|
var item = selectedItem;
|
||||||
|
|
||||||
var md = MsgBox(
|
var md = MsgBox($"Are you sure you want to remove the item \"{item.name}\"?");
|
||||||
$"Are you sure you want to remove the item \"{item.name}\"?"
|
|
||||||
);
|
|
||||||
|
|
||||||
var response = (ResponseType) md.Run();
|
var response = (ResponseType) md.Run();
|
||||||
md.Dispose();
|
md.Dispose();
|
||||||
|
@ -815,7 +807,8 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TextViewSelectedNotesFocusOut(object sender, FocusOutEventArgs args) {
|
private void TextViewSelectedNotesFocusOut(object sender, FocusOutEventArgs args) {
|
||||||
// the "save" button does nothing, however, when you click the save button, you transfer focus to it, firing this event!
|
// the "save" button does nothing, however, when you click the save button, you transfer focus to it, firing this
|
||||||
|
// event!
|
||||||
// how very sneaky
|
// how very sneaky
|
||||||
var noteBuffer = (TextBuffer) builder.GetObject("TextBufferSelectedNotes");
|
var noteBuffer = (TextBuffer) builder.GetObject("TextBufferSelectedNotes");
|
||||||
if (selectedItem != null) {
|
if (selectedItem != null) {
|
||||||
|
@ -834,7 +827,7 @@ namespace Buypeeb {
|
||||||
// timers
|
// timers
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// updates the end time displayed in the selection box. runs every second to update the countdown timer.
|
/// updates the end time displayed in the selection box. runs every second to update the countdown timer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>true</returns>
|
/// <returns>true</returns>
|
||||||
private bool UpdateSelectionEndTime() {
|
private bool UpdateSelectionEndTime() {
|
||||||
|
@ -870,7 +863,7 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// updates all items that need updating. runs every ten seconds.
|
/// updates all items that need updating. runs every ten seconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>true</returns>
|
/// <returns>true</returns>
|
||||||
private bool AutoUpdateItems() {
|
private bool AutoUpdateItems() {
|
||||||
|
@ -965,10 +958,10 @@ namespace Buypeeb {
|
||||||
// first, check to see if any filters are set that would exclude everything, such as hiding both active and ended auctions
|
// first, check to see if any filters are set that would exclude everything, such as hiding both active and ended auctions
|
||||||
// if so, there's no need to run the more expensive linq query
|
// if so, there's no need to run the more expensive linq query
|
||||||
if (
|
if (
|
||||||
(Filtered("Favourites") && Filtered("NonFavourites")) ||
|
Filtered("Favourites") && Filtered("NonFavourites") ||
|
||||||
(Filtered("Active") && Filtered("Ended")) ||
|
Filtered("Active") && Filtered("Ended") ||
|
||||||
(Filtered("EndingToday") && Filtered("EndingAfterToday")) ||
|
Filtered("EndingToday") && Filtered("EndingAfterToday") ||
|
||||||
(Filtered("WithWinPrice") && Filtered("WithNoWinPrice"))
|
Filtered("WithWinPrice") && Filtered("WithNoWinPrice")
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
12
Settings.cs
12
Settings.cs
|
@ -3,6 +3,12 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Buypeeb {
|
namespace Buypeeb {
|
||||||
internal class Settings {
|
internal class Settings {
|
||||||
|
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<string, YahooAuctionsItem>();
|
||||||
|
}
|
||||||
|
|
||||||
public int updateInterval { get; set; } = 10 * 60;
|
public int updateInterval { get; set; } = 10 * 60;
|
||||||
public int favouriteUpdateInterval { get; set; } = 5 * 60;
|
public int favouriteUpdateInterval { get; set; } = 5 * 60;
|
||||||
public int updateIntervalCritical { get; set; } = 60;
|
public int updateIntervalCritical { get; set; } = 60;
|
||||||
|
@ -13,12 +19,6 @@ namespace Buypeeb {
|
||||||
|
|
||||||
public Dictionary<string, YahooAuctionsItem> watchlist { get; set; }
|
public Dictionary<string, YahooAuctionsItem> 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<string, YahooAuctionsItem>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public YahooAuctionsItem Watch(string url, string name) {
|
public YahooAuctionsItem Watch(string url, string name) {
|
||||||
var id = BuypeebApp.IDFromURL(url);
|
var id = BuypeebApp.IDFromURL(url);
|
||||||
Console.WriteLine(id);
|
Console.WriteLine(id);
|
||||||
|
|
|
@ -7,15 +7,16 @@ using Gtk;
|
||||||
|
|
||||||
namespace Buypeeb {
|
namespace Buypeeb {
|
||||||
internal class SettingsWindow : Window {
|
internal class SettingsWindow : Window {
|
||||||
private readonly List<Switch> generalSwitches = new List<Switch>();
|
|
||||||
private readonly List<Entry> updateIntervalEntries = new List<Entry>();
|
|
||||||
private readonly Settings settings;
|
|
||||||
private readonly Builder builder;
|
private readonly Builder builder;
|
||||||
|
private readonly List<Switch> generalSwitches = new();
|
||||||
|
|
||||||
private readonly List<string> generalSwitchNames = new List<string>
|
private readonly List<string> generalSwitchNames =
|
||||||
{"ShowSecondsInListView", "Autosave", "ShowFavouritesAtTopOfList"};
|
new() {"ShowSecondsInListView", "Autosave", "ShowFavouritesAtTopOfList"};
|
||||||
|
|
||||||
private readonly List<string> updateIntervalEntryNames = new List<string>
|
private readonly Settings settings;
|
||||||
|
private readonly List<Entry> updateIntervalEntries = new();
|
||||||
|
|
||||||
|
private readonly List<string> updateIntervalEntryNames = new()
|
||||||
{"UpdateInterval", "UpdateIntervalCritical", "FavouriteUpdateInterval", "FavouriteUpdateIntervalCritical"};
|
{"UpdateInterval", "UpdateIntervalCritical", "FavouriteUpdateInterval", "FavouriteUpdateIntervalCritical"};
|
||||||
|
|
||||||
public SettingsWindow(Settings settings) : this(new Builder("settings.glade"), settings) {
|
public SettingsWindow(Settings settings) : this(new Builder("settings.glade"), settings) {
|
||||||
|
@ -41,11 +42,11 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
|
|
||||||
private T GetSetting<T>(string property) {
|
private T GetSetting<T>(string property) {
|
||||||
return (T) settings.GetType().GetProperty(property).GetValue(settings, null);
|
return (T) settings.GetType().GetProperty(property)?.GetValue(settings, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetSetting<T>(string property, T value) {
|
private void SetSetting<T>(string property, T value) {
|
||||||
settings.GetType().GetProperty(property).SetValue(settings, value);
|
settings.GetType().GetProperty(property)?.SetValue(settings, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string PropertyName(string property) {
|
private string PropertyName(string property) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
@ -9,6 +10,25 @@ using CsvHelper.Configuration.Attributes;
|
||||||
|
|
||||||
namespace Buypeeb {
|
namespace Buypeeb {
|
||||||
internal class YahooAuctionsItem {
|
internal class YahooAuctionsItem {
|
||||||
|
public bool AutoExtension;
|
||||||
|
public bool Available;
|
||||||
|
public int Bids;
|
||||||
|
public DateTime LastUpdated;
|
||||||
|
public int Price;
|
||||||
|
public bool Ready;
|
||||||
|
public DateTime StartDate;
|
||||||
|
public bool UpdateFailed;
|
||||||
|
public int WinPrice;
|
||||||
|
|
||||||
|
public YahooAuctionsItem(string id, string name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public YahooAuctionsItem() {
|
||||||
|
// parameterless constructor for deserialisation
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore] public string url => $"https://page.auctions.yahoo.co.jp/jp/auction/{id}";
|
[JsonIgnore] public string url => $"https://page.auctions.yahoo.co.jp/jp/auction/{id}";
|
||||||
|
|
||||||
[JsonIgnore] public string buyeeUrl => $"https://buyee.jp/item/yahoo/auction/{id}";
|
[JsonIgnore] public string buyeeUrl => $"https://buyee.jp/item/yahoo/auction/{id}";
|
||||||
|
@ -25,21 +45,13 @@ namespace Buypeeb {
|
||||||
// you also don't want to private any of the setters, which will have a similar effect.
|
// you also don't want to private any of the setters, which will have a similar effect.
|
||||||
[Ignore] public string id { get; set; }
|
[Ignore] public string id { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
public int Price;
|
|
||||||
public int WinPrice;
|
|
||||||
public string originalName { get; set; }
|
public string originalName { get; set; }
|
||||||
public string notes { get; set; }
|
public string notes { get; set; }
|
||||||
public bool favourite { get; set; }
|
public bool favourite { get; set; }
|
||||||
public DateTime StartDate;
|
|
||||||
public DateTime endDate { get; set; }
|
public DateTime endDate { get; set; }
|
||||||
public DateTime LastUpdated;
|
|
||||||
public int Bids;
|
|
||||||
public bool AutoExtension;
|
|
||||||
public bool Ready;
|
|
||||||
public bool Available;
|
|
||||||
public bool UpdateFailed;
|
|
||||||
|
|
||||||
[Ignore, JsonIgnore]
|
[Ignore]
|
||||||
|
[JsonIgnore]
|
||||||
public bool updatedRecently {
|
public bool updatedRecently {
|
||||||
get {
|
get {
|
||||||
var later = LastUpdated.AddSeconds(15);
|
var later = LastUpdated.AddSeconds(15);
|
||||||
|
@ -51,27 +63,18 @@ namespace Buypeeb {
|
||||||
|
|
||||||
[JsonIgnore] public string winPriceJpy => $"¥{WinPrice}";
|
[JsonIgnore] public string winPriceJpy => $"¥{WinPrice}";
|
||||||
|
|
||||||
[Ignore, JsonIgnore] public string priceAud => $"${(Price / 75.0):f2}";
|
[Ignore] [JsonIgnore] public string priceAud => $"${Price / 75.0:f2}";
|
||||||
|
|
||||||
[Ignore, JsonIgnore] public string winPriceAud => $"${(WinPrice / 75.0):f2}";
|
[Ignore] [JsonIgnore] public string winPriceAud => $"${WinPrice / 75.0:f2}";
|
||||||
|
|
||||||
[Ignore, JsonIgnore] public bool endingToday => endDate.DayOfYear == DateTime.UtcNow.DayOfYear;
|
[Ignore] [JsonIgnore] public bool endingToday => endDate.DayOfYear == DateTime.UtcNow.DayOfYear;
|
||||||
|
|
||||||
[Ignore, JsonIgnore] public bool hasWinPrice => WinPrice != 0;
|
[Ignore] [JsonIgnore] public bool hasWinPrice => WinPrice != 0;
|
||||||
|
|
||||||
[Ignore, JsonIgnore] public bool endingSoon => DateTime.Compare(DateTime.UtcNow.AddMinutes(10), endDate) > 0;
|
[Ignore] [JsonIgnore] public bool endingSoon => DateTime.Compare(DateTime.UtcNow.AddMinutes(10), endDate) > 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 YahooAuctionsItem(string id, string name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public YahooAuctionsItem() {
|
|
||||||
// parameterless constructor for deserialisation
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AuctionEnded() {
|
public void AuctionEnded() {
|
||||||
// the page 404'd. this probably means that the auction has ended, and the page has been removed.
|
// the page 404'd. this probably means that the auction has ended, and the page has been removed.
|
||||||
Available = false;
|
Available = false;
|
||||||
|
@ -81,8 +84,8 @@ namespace Buypeeb {
|
||||||
|
|
||||||
public void Update(string html) {
|
public void Update(string html) {
|
||||||
// TODO: handle all the parsing errors and weird interpretation that could possibly happen here
|
// TODO: handle all the parsing errors and weird interpretation that could possibly happen here
|
||||||
var rx = new Regex(@"var pageData ?= ?(\{.+?\});",
|
// TODO: maybe compile and match the regex in another thread
|
||||||
RegexOptions.Singleline); // TODO: maybe compile and match the regex in another thread
|
var rx = new Regex(@"var pageData ?= ?(\{.+?\});", RegexOptions.Singleline);
|
||||||
var m = rx.Match(html);
|
var m = rx.Match(html);
|
||||||
|
|
||||||
Dictionary<string, Dictionary<string, string>> jFull;
|
Dictionary<string, Dictionary<string, string>> jFull;
|
||||||
|
@ -98,6 +101,7 @@ namespace Buypeeb {
|
||||||
var jst = TimeZoneInfo.CreateCustomTimeZone("JST", new TimeSpan(9, 0, 0), "Japan Standard Time",
|
var jst = TimeZoneInfo.CreateCustomTimeZone("JST", new TimeSpan(9, 0, 0), "Japan Standard Time",
|
||||||
"Japan Standard Time");
|
"Japan Standard Time");
|
||||||
|
|
||||||
|
Debug.Assert(jFull != null, nameof(jFull) + " != null");
|
||||||
var j = jFull["items"];
|
var j = jFull["items"];
|
||||||
originalName = j["productName"];
|
originalName = j["productName"];
|
||||||
StartDate = TimeZoneInfo.ConvertTimeToUtc(
|
StartDate = TimeZoneInfo.ConvertTimeToUtc(
|
||||||
|
@ -122,7 +126,7 @@ namespace Buypeeb {
|
||||||
// whether or not it's equal to "ari" (japanese for "yes").
|
// whether or not it's equal to "ari" (japanese for "yes").
|
||||||
rx = new Regex(@"自動延長.+\n.+>(.+)<");
|
rx = new Regex(@"自動延長.+\n.+>(.+)<");
|
||||||
m = rx.Match(html);
|
m = rx.Match(html);
|
||||||
AutoExtension = (m.Groups[1].Value == "あり");
|
AutoExtension = m.Groups[1].Value == "あり";
|
||||||
|
|
||||||
UpdateFailed = false;
|
UpdateFailed = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>netcoreapp5.0</TargetFramework>
|
<TargetFramework>netcoreapp5.0</TargetFramework>
|
||||||
<StartupObject>Buypeeb.BuypeebApp</StartupObject>
|
<StartupObject>Buypeeb.BuypeebApp</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="**\*.glade" />
|
<None Remove="**\*.glade"/>
|
||||||
<EmbeddedResource Include="**\*.glade">
|
<EmbeddedResource Include="**\*.glade">
|
||||||
<LogicalName>%(Filename)%(Extension)</LogicalName>
|
<LogicalName>%(Filename)%(Extension)</LogicalName>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<None Remove="yahoo.html" />
|
<None Remove="yahoo.html"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CsvHelper" Version="27.1.1" />
|
<PackageReference Include="CsvHelper" Version="27.1.1"/>
|
||||||
<PackageReference Include="GtkSharp" Version="3.24.24.34" />
|
<PackageReference Include="GtkSharp" Version="3.24.24.34"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in a new issue