RhSolutions-AddIn/RhSolutions.AddIn/Tools/FittingsTool.cs

25 lines
902 B
C#
Raw Permalink Normal View History

2023-11-09 23:34:52 +03:00
namespace RhSolutions.Tools;
2024-11-09 22:59:46 +03:00
internal class FittingsTool : ReaderWriterTool, ITool
2023-11-09 23:34:52 +03:00
{
2024-11-09 22:59:46 +03:00
private readonly FittingsCalculatorFactory _factory = RhSolutionsAddIn.ServiceProvider.GetService<FittingsCalculatorFactory>();
2023-11-09 23:34:52 +03:00
private string _calculatorName;
2024-11-09 22:59:46 +03:00
public FittingsTool(string calculatorName)
2023-11-09 23:34:52 +03:00
{
_calculatorName = calculatorName;
}
2024-11-09 22:59:46 +03:00
public void Execute()
2023-11-09 23:34:52 +03:00
{
Application app = RhSolutionsAddIn.Excel.Application;
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
_reader = _readerFactory.GetReader("Excel");
var products = _reader.ReadProducts(new[] { worksheet });
var calculator = _factory.GetFittingsCalculator(_calculatorName);
var fittings = calculator.Calculate(products.Select(p => p.Item2).First());
_writer = _writerFactory.GetWriter("CurrentPrice");
_writer.WriteProducts(fittings);
}
}