Added identifier and fetch time product listings; Added persistence to AdafruitShop.
Implemented in AdafruitShop. AdafruitShop Product listing data now persisted. AdafruitShop configuration now persisted.
This commit is contained in:
@@ -31,40 +31,52 @@ namespace Props.Data
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<ResultsPreferences>()
|
||||
.Property(e => e.Order)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, null),
|
||||
v => JsonSerializer.Deserialize<List<ResultsPreferences.Category>>(v, null),
|
||||
new ValueComparer<IList<ResultsPreferences.Category>>(
|
||||
(a, b) => a.SequenceEqual(b),
|
||||
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
|
||||
c => (IList<ResultsPreferences.Category>)c.ToList()
|
||||
)
|
||||
);
|
||||
.Property(e => e.Order)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, null),
|
||||
v => JsonSerializer.Deserialize<List<ResultsPreferences.Category>>(v, null),
|
||||
new ValueComparer<IList<ResultsPreferences.Category>>(
|
||||
(a, b) => a.SequenceEqual(b),
|
||||
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
|
||||
c => (IList<ResultsPreferences.Category>)c.ToList()
|
||||
)
|
||||
);
|
||||
|
||||
modelBuilder.Entity<SearchOutline>()
|
||||
.Property(e => e.Enabled)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, null),
|
||||
v => JsonSerializer.Deserialize<SearchOutline.ShopsDisabled>(v, null),
|
||||
new ValueComparer<SearchOutline.ShopsDisabled>(
|
||||
(a, b) => a.Equals(b),
|
||||
c => c.GetHashCode(),
|
||||
c => c.Copy()
|
||||
)
|
||||
);
|
||||
.Property(e => e.Enabled)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, null),
|
||||
v => JsonSerializer.Deserialize<SearchOutline.ShopsDisabled>(v, null),
|
||||
new ValueComparer<SearchOutline.ShopsDisabled>(
|
||||
(a, b) => a.Equals(b),
|
||||
c => c.GetHashCode(),
|
||||
c => c.Copy()
|
||||
)
|
||||
);
|
||||
|
||||
modelBuilder.Entity<SearchOutline>()
|
||||
.Property(e => e.Filters)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, null),
|
||||
v => JsonSerializer.Deserialize<Filters>(v, null),
|
||||
new ValueComparer<Filters>(
|
||||
(a, b) => a.Equals(b),
|
||||
c => c.GetHashCode(),
|
||||
c => c.Copy()
|
||||
)
|
||||
);
|
||||
.Property(e => e.Filters)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, null),
|
||||
v => JsonSerializer.Deserialize<Filters>(v, null),
|
||||
new ValueComparer<Filters>(
|
||||
(a, b) => a.Equals(b),
|
||||
c => c.GetHashCode(),
|
||||
c => c.Copy()
|
||||
)
|
||||
);
|
||||
|
||||
modelBuilder.Entity<ProductListingInfo>()
|
||||
.Property(e => e.ProductListing)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, null),
|
||||
v => JsonSerializer.Deserialize<ProductListing>(v, null),
|
||||
new ValueComparer<ProductListing>(
|
||||
(a, b) => a.Equals(b),
|
||||
c => c.GetHashCode(),
|
||||
c => c.Copy()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ using Props.Data;
|
||||
namespace Props.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20210805055109_InitialCreate")]
|
||||
[Migration("20210809194646_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -185,13 +185,10 @@ namespace Props.Data.Migrations
|
||||
b.Property<uint>("Hits")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
b.Property<string>("ProductListing")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ProductUrl")
|
||||
b.Property<string>("ProductListingIdentifier")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ShopName")
|
@@ -68,9 +68,8 @@ namespace Props.Data.Migrations
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
ShopName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Hits = table.Column<uint>(type: "INTEGER", nullable: false),
|
||||
LastUpdated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
ProductUrl = table.Column<string>(type: "TEXT", nullable: true),
|
||||
ProductName = table.Column<string>(type: "TEXT", nullable: true)
|
||||
ProductListing = table.Column<string>(type: "TEXT", nullable: true),
|
||||
ProductListingIdentifier = table.Column<string>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
@@ -183,13 +183,10 @@ namespace Props.Data.Migrations
|
||||
b.Property<uint>("Hits")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
b.Property<string>("ProductListing")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ProductUrl")
|
||||
b.Property<string>("ProductListingIdentifier")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Props.Shop.Framework;
|
||||
|
||||
namespace Props.Extensions
|
||||
@@ -10,5 +11,7 @@ namespace Props.Extensions
|
||||
int purchaseFactor = productListing.PurchaseCount.HasValue ? productListing.PurchaseCount.Value : 1;
|
||||
return (productListing.Rating * (reviewFactor > purchaseFactor ? reviewFactor : purchaseFactor)) / (productListing.LowerPrice * productListing.UpperPrice);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -11,10 +11,8 @@ namespace Props.Models.Search
|
||||
|
||||
public uint Hits { get; set; }
|
||||
|
||||
public DateTime LastUpdated { get; set; }
|
||||
public ProductListing ProductListing { get; set; }
|
||||
|
||||
public string ProductUrl { get; set; }
|
||||
|
||||
public string ProductName { get; set; }
|
||||
public string ProductListingIdentifier { get; set; }
|
||||
}
|
||||
}
|
@@ -68,16 +68,15 @@ namespace Props.Services.Modules
|
||||
{
|
||||
ProductListingInfo productListingInfo =
|
||||
(from info in dbContext.ProductListingInfos
|
||||
where info.ProductUrl.Equals(productListing.URL)
|
||||
where info.ProductListingIdentifier.Equals(productListing.Identifier)
|
||||
select info).SingleOrDefault() ?? new ProductListingInfo();
|
||||
if (productListingInfo.Hits == 0)
|
||||
{
|
||||
dbContext.Add(productListingInfo);
|
||||
}
|
||||
productListingInfo.ShopName = shopName;
|
||||
productListingInfo.ProductName = productListing.Name;
|
||||
productListingInfo.ProductUrl = productListing.URL;
|
||||
productListingInfo.LastUpdated = DateTime.UtcNow;
|
||||
productListingInfo.ProductListing = productListing;
|
||||
productListingInfo.ProductListingIdentifier = productListing.Identifier;
|
||||
productListingInfo.Hits += 1;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
@@ -55,7 +55,6 @@ namespace Props.Services.Modules
|
||||
|
||||
public void LoadShops()
|
||||
{
|
||||
// TODO: Figure out how to best call this.
|
||||
string shopsDir = options.ModulesDir;
|
||||
string shopRegex = options.ShopRegex;
|
||||
bool recursiveLoad = options.RecursiveLoad;
|
||||
@@ -87,7 +86,8 @@ namespace Props.Services.Modules
|
||||
IShop shop = Activator.CreateInstance(type) as IShop;
|
||||
if (shop != null)
|
||||
{
|
||||
DirectoryInfo dataDir = Directory.CreateDirectory(Path.Combine(options.ModuleDataDir, file));
|
||||
DirectoryInfo dataDir = Directory.CreateDirectory(Path.Combine(options.ModuleDataDir, file.Substring(file.IndexOf(Path.DirectorySeparatorChar) + 1)));
|
||||
logger.LogDebug("Checking data directory for \"{0}\" at \"{1}\"", Path.GetFileName(file), dataDir.FullName);
|
||||
shop.Initialize(dataDir.FullName, loggerFactory);
|
||||
success += 1;
|
||||
if (!shops.TryAdd(shop.ShopName, shop))
|
||||
@@ -105,8 +105,6 @@ namespace Props.Services.Modules
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.LogDebug("Waiting for all shops to finish asynchronous initialization.");
|
||||
logger.LogDebug("All shops finished asynchronous initialization.");
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
@@ -117,7 +115,7 @@ namespace Props.Services.Modules
|
||||
{
|
||||
foreach (string shopName in shops.Keys)
|
||||
{
|
||||
// TODO: Get shop data to persist.
|
||||
shops[shopName].SaveData().AsTask().Wait();
|
||||
shops[shopName].Dispose();
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user