Refactored repo organization. Added Jenkinsfile.

This commit is contained in:
2022-04-24 00:01:55 -05:00
parent 44e072a723
commit 9cc55e516d
36 changed files with 169 additions and 81 deletions

View File

@@ -0,0 +1,8 @@
namespace Props.Shop.Framework
{
public enum Currency
{
CAD,
USD
}
}

View File

@@ -0,0 +1,108 @@
using System;
namespace Props.Shop.Framework
{
public class Filters
{
public Currency Currency { get; set; } = Currency.CAD;
private float minRatingNormalized = 0.8f;
public int MinRating
{
get
{
return (int)(minRatingNormalized * 100f);
}
set
{
if (value < 0 || value > 100) return;
minRatingNormalized = value / 100f;
}
}
public bool KeepUnrated { get; set; } = true;
public bool EnableUpperPrice { get; set; } = false;
private int upperPrice;
public int UpperPrice
{
get
{
return upperPrice;
}
set
{
if (EnableUpperPrice) upperPrice = value;
}
}
public int LowerPrice { get; set; }
public int MinPurchases { get; set; }
public bool KeepUnknownPurchaseCount { get; set; } = true;
public int MinReviews { get; set; }
public bool KeepUnknownReviewCount { get; set; } = true;
public bool EnableMaxShipping { get; set; }
private int maxShippingFee;
public int MaxShippingFee
{
get
{
return maxShippingFee;
}
set
{
if (EnableMaxShipping) maxShippingFee = value;
}
}
public bool KeepUnknownShipping { get; set; } = true;
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
Filters other = (Filters)obj;
return
Currency == other.Currency &&
MinRating == other.MinRating &&
KeepUnrated == other.KeepUnrated &&
EnableUpperPrice == other.EnableUpperPrice &&
UpperPrice == other.UpperPrice &&
LowerPrice == other.LowerPrice &&
MinPurchases == other.MinPurchases &&
KeepUnknownPurchaseCount == other.KeepUnknownPurchaseCount &&
MinReviews == other.MinReviews &&
KeepUnknownReviewCount == other.KeepUnknownReviewCount &&
EnableMaxShipping == other.EnableMaxShipping &&
MaxShippingFee == other.MaxShippingFee &&
KeepUnknownShipping == other.KeepUnknownShipping;
}
public override int GetHashCode()
{
return HashCode.Combine(
Currency,
MinRating,
UpperPrice,
LowerPrice,
MinPurchases,
MinReviews,
MaxShippingFee);
}
public Filters Copy()
{
return (Filters)this.MemberwiseClone();
}
public bool Validate(ProductListing listing)
{
if (listing.Shipping == null && !KeepUnknownShipping || (EnableMaxShipping && listing.Shipping > MaxShippingFee)) return false;
float shippingDifference = listing.Shipping != null ? listing.Shipping.Value : 0;
if (!(listing.LowerPrice + shippingDifference >= LowerPrice && (!EnableUpperPrice || listing.UpperPrice + shippingDifference <= UpperPrice))) return false;
if ((listing.Rating == null && !KeepUnrated) && MinRating > (listing.Rating == null ? 0 : listing.Rating)) return false;
if ((listing.PurchaseCount == null && !KeepUnknownPurchaseCount) || MinPurchases > (listing.PurchaseCount == null ? 0 : listing.PurchaseCount)) return false;
if ((listing.ReviewCount == null && !KeepUnknownReviewCount) || MinReviews > (listing.ReviewCount == null ? 0 : listing.ReviewCount)) return false;
return true;
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
namespace Props.Shop.Framework
{
public interface IOption
{
public string Name { get; }
public string Description { get; }
public bool Required { get; }
public string GetValue();
public bool SetValue(string value);
public Type Type { get; }
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace Props.Shop.Framework
{
public interface IShop : IAsyncDisposable
{
string ShopName { get; }
string ShopDescription { get; }
string ShopModuleAuthor { get; }
public IAsyncEnumerable<ProductListing> Search(string query, Filters filters);
public Task<ProductListing> GetProductFromIdentifier(string identifier);
ValueTask Initialize(string workspaceDir, ILoggerFactory loggerFactory);
public SupportedFeatures SupportedFeatures { get; }
}
}

View File

@@ -0,0 +1,55 @@
using System;
namespace Props.Shop.Framework
{
public class ProductListing
{
public float LowerPrice { get; set; }
public float UpperPrice { get; set; }
public float? Shipping { get; set; }
public string Name { get; set; }
public string URL { get; set; }
public string ImageURL { get; set; }
public float? Rating { get; set; }
public int? PurchaseCount { get; set; }
public int? ReviewCount { get; set; }
public bool ConvertedPrices { get; set; }
public bool? InStock { get; set; }
public string Identifier { get; set; }
public DateTime TimeFetchedUtc { get; set; }
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
ProductListing other = obj as ProductListing;
return
this.LowerPrice == other.LowerPrice &&
this.UpperPrice == other.UpperPrice &&
this.Shipping == other.Shipping &&
this.Name == other.Name &&
this.URL == other.URL &&
this.ImageURL == other.ImageURL &&
this.Rating == other.Rating &&
this.PurchaseCount == other.PurchaseCount &&
this.ReviewCount == other.ReviewCount &&
this.ConvertedPrices == other.ConvertedPrices &&
this.InStock == other.InStock &&
this.Identifier == other.Identifier &&
this.TimeFetchedUtc == other.TimeFetchedUtc;
}
public override int GetHashCode()
{
return (Name, URL, UpperPrice, LowerPrice, ImageURL).GetHashCode();
}
public ProductListing Copy()
{
return MemberwiseClone() as ProductListing;
}
}
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,20 @@
namespace Props.Shop.Framework
{
public class SupportedFeatures
{
bool Shipping { get; }
bool Rating { get; }
bool ReviewCount { get; }
bool PurchaseCount { get; }
bool InStock { get; }
public SupportedFeatures(bool shipping, bool rating, bool reviewCount, bool purchaseCount, bool inStock)
{
this.Shipping = shipping;
this.Rating = rating;
this.ReviewCount = reviewCount;
this.PurchaseCount = purchaseCount;
this.InStock = inStock;
}
}
}