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

25 lines
902 B
C#

namespace RhSolutions.Tools;
internal class FittingsTool : ReaderWriterTool, ITool
{
private readonly FittingsCalculatorFactory _factory = RhSolutionsAddIn.ServiceProvider.GetService<FittingsCalculatorFactory>();
private string _calculatorName;
public FittingsTool(string calculatorName)
{
_calculatorName = calculatorName;
}
public void Execute()
{
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);
}
}