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:
2021-08-09 13:32:16 -05:00
parent 38ffb3c7e1
commit 0b507b90a1
28 changed files with 251 additions and 349 deletions

View File

@@ -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();
}

View File

@@ -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();
}
}