From d9a4349a0a323b173e80e41d180708890850ac70 Mon Sep 17 00:00:00 2001 From: Lynne Date: Sun, 6 Sep 2020 13:10:00 +1000 Subject: [PATCH] don't serialise some unecessary stuff --- MainWindow.cs | 1 + YahooAuctionsItem.cs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/MainWindow.cs b/MainWindow.cs index 43ec28d..a0cfb43 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -573,6 +573,7 @@ namespace Buypeeb { try { using (var writer = new StreamWriter(sd.Filename)) using (var csv = new CsvWriter(writer, System.Globalization.CultureInfo.InvariantCulture)) { + csv.WriteRecords(this.settings.watchlist); } } diff --git a/YahooAuctionsItem.cs b/YahooAuctionsItem.cs index 7418ca9..2bedee8 100644 --- a/YahooAuctionsItem.cs +++ b/YahooAuctionsItem.cs @@ -3,6 +3,8 @@ using System.Globalization; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Text.Json; +using System.Text.Json.Serialization; +using CsvHelper.Configuration.Attributes; namespace Buypeeb { class YahooAuctionsItem { @@ -23,6 +25,7 @@ namespace Buypeeb { // the id *must* be saved! // i'm also saving the original name to make it easier to tell what the items are in the userdata.json // there's not really a need for it i guess but it's my program and i can do what i want + [Ignore] public string id { get; set; } public string name { get; set; } private int price = 0; @@ -38,6 +41,7 @@ namespace Buypeeb { public bool ready; public bool available; + [Ignore, JsonIgnore] public bool updatedRecently { get { var later = this.lastUpdated.AddSeconds(15); @@ -45,15 +49,21 @@ namespace Buypeeb { } } - // TODO: don't serialise this stuff + [JsonIgnore] public string priceJPY { get { return $"¥{this.price}"; } } + [JsonIgnore] public string winPriceJPY { get { return $"¥{this.winPrice}"; } } + [Ignore, JsonIgnore] public string priceAUD { get { return $"${(this.price / 75.0):f2}"; } } + [Ignore, JsonIgnore] public string winPriceAUD { get { return $"${(this.winPrice / 75.0):f2}"; } } + [Ignore, JsonIgnore] public bool endingToday { get { return this.endDate.DayOfYear == DateTime.UtcNow.DayOfYear; } } + [Ignore, JsonIgnore] 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 + [Ignore, JsonIgnore] public bool endingSoon { get { return DateTime.Compare(DateTime.UtcNow.AddMinutes(10), this.endDate) > 0; } } + 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;