Compare commits

..

No commits in common. "1b72c00b1e2c29117616dcd3da83e1fea68b892d" and "d999a0b98a6923a8027eead46a43bcd50ca8d713" have entirely different histories.

11 changed files with 36 additions and 36 deletions

View File

@ -25,7 +25,7 @@ public sealed class RhSolutionsAddIn : IExcelAddIn
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
.AddSingleton<IDatabaseClient, DatabaseClient>()
.AddSingleton<ICurrencyClient, CurrencyClient>()
.AddSingleton<IFittingsCalculator, SleevesCalculator>()
.AddSingleton<ISleevesCalculator, SleevesCalculator>()
.AddTransient<IFileDialog, FileDialog>();
Services.AddSingleton<WriterFactory>();

View File

@ -1,26 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="RhSolutions Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
<ExternalLibrary Path="RhSolutions.AddIn.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" />
<Reference Path="ExcelDna.IntelliSense.dll" Pack="true" />
<Reference Path="Microsoft.AspNetCore.Http.Abstractions.dll" Pack="true" />
<Reference Path="Microsoft.AspNetCore.Http.Extensions.dll" Pack="true" />
<Reference Path="Microsoft.AspNetCore.Http.Features.dll" Pack="true" />
<Reference Path="Microsoft.Bcl.AsyncInterfaces.dll" Pack="true" />
<Reference Path="Microsoft.Bcl.HashCode.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Caching.Abstractions.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Caching.Memory.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.DependencyInjection.Abstractions.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.DependencyInjection.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.FileProviders.Abstractions.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Http.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Logging.Abstractions.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Logging.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Options.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Primitives.dll" Pack="true" />
<Reference Path="ExcelDna.IntelliSense.dll" Pack="true" />
<Reference Path="Newtonsoft.Json.dll" Pack="true" />
<Reference Path="Microsoft.Net.Http.Headers.dll" Pack="true" />
<Reference Path="netDxf.dll" Pack="true" />
<Reference Path="Newtonsoft.Json.dll" Pack="true" />
<Reference Path="RhSolutions.ProductSku.dll" Pack="true" />
<Reference Path="System.Buffers.dll" Pack="true" />
<Reference Path="System.Diagnostics.DiagnosticSource.dll" Pack="true" />
<Reference Path="System.Memory.dll" Pack="true" />
<Reference Path="System.Numerics.Vectors.dll" Pack="true" />
<Reference Path="System.Runtime.CompilerServices.Unsafe.dll" Pack="true" />
<Reference Path="System.Text.Encodings.Web.dll" Pack="true" />
<Reference Path="System.Threading.Tasks.Extensions.dll" Pack="true" />
<Reference Path="System.ValueTuple.dll" Pack="true" />
</DnaLibrary>

View File

@ -32,6 +32,7 @@
<PackageReference Include="ExcelDna.Integration" Version="1.6.0" />
<PackageReference Include="ExcelDna.IntelliSense" Version="1.6.0" />
<PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />

View File

@ -1,9 +0,0 @@
namespace RhSolutions.Services;
public class CouplingsCalculator : IFittingsCalculator
{
public Dictionary<Product, double> Calculate(Dictionary<Product, double> products)
{
throw new NotImplementedException();
}
}

View File

@ -1,8 +1,10 @@
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
using System.Web;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.Services;
@ -54,11 +56,11 @@ public class DatabaseClient : IDatabaseClient
else
{
UriBuilder builder = new(@"https://rh.cebotari.ru/api/search")
QueryBuilder qb = new()
{
Query = $"query={line.Replace("&", "%26")}"
{"query", line}
};
string request = builder.Uri.AbsoluteUri;
string request = @"https://rh.cebotari.ru/api/search" + qb.ToQueryString();
if (!_memoryCache.TryGetValue(line, out IEnumerable<Product> products))
{

View File

@ -1,6 +0,0 @@
namespace RhSolutions.Services;
public interface IFittingsCalculator
{
public Dictionary<Product, double> Calculate(Dictionary<Product, double> products);
}

View File

@ -0,0 +1,6 @@
namespace RhSolutions.Services;
public interface ISleevesCalculator
{
public Dictionary<Product, double> CalculateSleeves(Dictionary<Product, double> products);
}

View File

@ -2,14 +2,14 @@
namespace RhSolutions.Services;
public class SleevesCalculator : IFittingsCalculator
public class SleevesCalculator : ISleevesCalculator
{
private const string doublePattern =
@"((?i)равнопроходная|угольник\s+90|угольник\s+45|Т-образная|Комплект\s+трубок(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+";
private const string singlePattern =
@"((?i)муфта|тройник|переходник|угольник|штуцер|Г-образная|заглушка(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+";
public Dictionary<Product, double> Calculate(Dictionary<Product, double> products)
public Dictionary<Product, double> CalculateSleeves(Dictionary<Product, double> products)
{
Dictionary<string, double> result = new()
{

View File

@ -2,9 +2,9 @@
internal class SleevesTool : Tool
{
private readonly IFittingsCalculator _sleevesCaluculator;
private readonly ISleevesCalculator _sleevesCaluculator;
public SleevesTool(ReaderFactory readerFactory, WriterFactory writerFactory, IFittingsCalculator sleevesCaluculator) : base(readerFactory, writerFactory)
public SleevesTool(ReaderFactory readerFactory, WriterFactory writerFactory, ISleevesCalculator sleevesCaluculator) : base(readerFactory, writerFactory)
{
_sleevesCaluculator = sleevesCaluculator;
}
@ -15,7 +15,7 @@ internal class SleevesTool : Tool
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
_reader = _readerFactory.GetReader("Excel");
var products = _reader.ReadProducts(new[] { worksheet });
var sleeves = _sleevesCaluculator.Calculate(products.Select(p => p.Item2).First());
var sleeves = _sleevesCaluculator.CalculateSleeves(products.Select(p => p.Item2).First());
_writer = _writerFactory.GetWriter("CurrentPrice");
_writer.WriteProducts(sleeves);
}

View File

@ -4,7 +4,7 @@ internal class ToolFactory
{
static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService<ReaderFactory>();
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
static IFittingsCalculator sleevesCaluculator = RhSolutionsAddIn.ServiceProvider.GetService<IFittingsCalculator>();
static ISleevesCalculator sleevesCaluculator = RhSolutionsAddIn.ServiceProvider.GetService<ISleevesCalculator>();
public Tool GetTool(string toolName)
{

View File

@ -6,7 +6,7 @@ namespace RhSolutions.Tests;
public class CanFillSleeves : IDisposable
{
private RhSolutionsAddIn _addIn;
private IFittingsCalculator _calculator;
private ISleevesCalculator _calculator;
private IReader _reader;
private IWriter _writer;
private Worksheet _worksheet;
@ -25,7 +25,7 @@ public class CanFillSleeves : IDisposable
public void CanCalculateSleeves()
{
var products = _reader.ReadProducts(new[] { _worksheet });
var sleeves = _calculator.Calculate(products.First().Item2);
var sleeves = _calculator.CalculateSleeves(products.First().Item2);
_writer.WriteProducts(sleeves);
Assert.Equal(25, _worksheet.Range["E2"].Value);