Tools refactoring

This commit is contained in:
Sergey Chebotar 2023-06-20 11:51:52 +03:00
parent 2c44c5d2df
commit b9cdad649a
7 changed files with 18 additions and 15 deletions

View File

@ -10,7 +10,7 @@ namespace RhSolutions.Tools;
#endif
internal class ConvertTool : Tool
{
public ConvertTool(IServiceProvider provider) : base(provider)
public ConvertTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
{
}

View File

@ -9,7 +9,7 @@ namespace RhSolutions.Tools;
#endif
internal class DxfTool : Tool
{
public DxfTool(IServiceProvider provider) : base(provider)
public DxfTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
{
}

View File

@ -9,7 +9,7 @@ namespace RhSolutions.Tools;
#endif
internal class ExportTool : Tool
{
public ExportTool(IServiceProvider provider) : base(provider)
public ExportTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
{
}

View File

@ -6,7 +6,7 @@ namespace RhSolutions.Tools;
internal class GuessTool : Tool
{
public GuessTool(IServiceProvider provider) : base(provider)
public GuessTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
{
}

View File

@ -9,7 +9,7 @@ namespace RhSolutions.Tools;
#endif
internal class MergeTool : Tool
{
public MergeTool(IServiceProvider provider) : base(provider)
public MergeTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
{
}

View File

@ -14,16 +14,16 @@ internal abstract class Tool : IDisposable
protected IReader _reader;
protected IWriter _writer;
public Tool(IServiceProvider provider)
public Tool(ReaderFactory readerFactory, WriterFactory writerFactory)
{
_readerFactory = provider.GetRequiredService<ReaderFactory>();
_writerFactory = provider.GetRequiredService<WriterFactory>();
_readerFactory = readerFactory;
_writerFactory = writerFactory;
}
public void Dispose()
{
_reader.Dispose();
_writer.Dispose();
_reader?.Dispose();
_writer?.Dispose();
}
public abstract void Execute();

View File

@ -2,15 +2,18 @@
internal class ToolFactory
{
static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService<ReaderFactory>();
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
public Tool GetTool(string toolName)
{
Tool tool = toolName switch
{
"export" => new ExportTool(RhSolutionsAddIn.ServiceProvider),
"convert" => new ConvertTool(RhSolutionsAddIn.ServiceProvider),
"merge" => new MergeTool(RhSolutionsAddIn.ServiceProvider),
"dxfexport" => new DxfTool(RhSolutionsAddIn.ServiceProvider),
"guess" => new GuessTool(RhSolutionsAddIn.ServiceProvider),
"export" => new ExportTool(readerFactory, writerFactory),
"convert" => new ConvertTool(readerFactory, writerFactory),
"merge" => new MergeTool(readerFactory, writerFactory),
"dxfexport" => new DxfTool(readerFactory, writerFactory),
"guess" => new GuessTool(readerFactory, writerFactory),
"fillsleeves" => new SleevesTool(RhSolutionsAddIn.ServiceProvider),
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
};