Compare commits
No commits in common. "46e547e3e26dd80ef15d02f09b24578d37bf1104" and "627195fafedcdc0b5aeb9004415e50057db68f90" have entirely different histories.
46e547e3e2
...
627195fafe
@ -21,62 +21,36 @@ public class DatabaseClient : IDatabaseClient
|
||||
public async Task<IEnumerable<Product>> GetProducts(string line)
|
||||
{
|
||||
string request;
|
||||
IEnumerable<Product> products;
|
||||
|
||||
if (ProductSku.TryParse(line, out var skus))
|
||||
{
|
||||
ProductSku sku = skus.FirstOrDefault();
|
||||
request = @"https://rh.cebotari.ru/api/products/" + sku.ToString();
|
||||
|
||||
if (!_memoryCache.TryGetValue(sku, out products))
|
||||
{
|
||||
var response = await _httpClient.GetAsync(request);
|
||||
|
||||
try
|
||||
{
|
||||
response.EnsureSuccessStatusCode();
|
||||
string json = await response.Content.ReadAsStringAsync();
|
||||
products = JsonConvert.DeserializeObject<IEnumerable<Product>>(json) ?? Enumerable.Empty<Product>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
StatusCode = response.StatusCode;
|
||||
}
|
||||
|
||||
var cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||
.SetSlidingExpiration(TimeSpan.FromHours(1));
|
||||
_memoryCache.Set(sku, products, cacheEntryOptions);
|
||||
}
|
||||
request = @"https://rh.cebotari.ru/api/products/" + skus.FirstOrDefault().ToString();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
request = @"https://rh.cebotari.ru/api/search?query=" + line;
|
||||
|
||||
if (!_memoryCache.TryGetValue(line, out products))
|
||||
}
|
||||
|
||||
if (!_memoryCache.TryGetValue(line, out IEnumerable<Product> products))
|
||||
{
|
||||
var response = await _httpClient.GetAsync(request);
|
||||
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetAsync(request);
|
||||
|
||||
try
|
||||
{
|
||||
response.EnsureSuccessStatusCode();
|
||||
string json = await response.Content.ReadAsStringAsync();
|
||||
products = JsonConvert.DeserializeObject<IEnumerable<Product>>(json) ?? Enumerable.Empty<Product>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
StatusCode = response.StatusCode;
|
||||
}
|
||||
|
||||
var cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||
.SetSlidingExpiration(TimeSpan.FromHours(1));
|
||||
_memoryCache.Set(line, products, cacheEntryOptions);
|
||||
if (products.Count() > 0)
|
||||
{
|
||||
_memoryCache.Set(products.First(), products, cacheEntryOptions);
|
||||
}
|
||||
response.EnsureSuccessStatusCode();
|
||||
string json = await response.Content.ReadAsStringAsync();
|
||||
products = JsonConvert.DeserializeObject<IEnumerable<Product>>(json) ?? Enumerable.Empty<Product>();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
StatusCode = response.StatusCode;
|
||||
}
|
||||
|
||||
var cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||
.SetSlidingExpiration(TimeSpan.FromHours(1));
|
||||
_memoryCache.Set(line, products, cacheEntryOptions);
|
||||
}
|
||||
|
||||
return products;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public class ExcelReader : IReader, IDisposable
|
||||
ProductLineCell = worksheet.Cells.Find(headers["ProductLine"]),
|
||||
NameCell = worksheet.Cells.Find(headers["Name"]),
|
||||
MeasureCell = worksheet.Cells.Find(headers["Measure"]);
|
||||
var lastRowIndex = worksheet.Cells[worksheet.Rows.Count, SkuCell.Column]
|
||||
var lastRowIndex = worksheet.Cells[worksheet.Rows.Count, AmountCell.Column]
|
||||
.End[XlDirection.xlUp].Row;
|
||||
|
||||
Dictionary<Product, double> readResult = new();
|
||||
|
Loading…
x
Reference in New Issue
Block a user