Tools refactoring
This commit is contained in:
parent
2c44c5d2df
commit
b9cdad649a
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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}"),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user