Tools refactoring
This commit is contained in:
parent
2c44c5d2df
commit
b9cdad649a
@ -10,7 +10,7 @@ namespace RhSolutions.Tools;
|
|||||||
#endif
|
#endif
|
||||||
internal class ConvertTool : Tool
|
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
|
#endif
|
||||||
internal class DxfTool : Tool
|
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
|
#endif
|
||||||
internal class ExportTool : Tool
|
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
|
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
|
#endif
|
||||||
internal class MergeTool : Tool
|
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 IReader _reader;
|
||||||
protected IWriter _writer;
|
protected IWriter _writer;
|
||||||
|
|
||||||
public Tool(IServiceProvider provider)
|
public Tool(ReaderFactory readerFactory, WriterFactory writerFactory)
|
||||||
{
|
{
|
||||||
_readerFactory = provider.GetRequiredService<ReaderFactory>();
|
_readerFactory = readerFactory;
|
||||||
_writerFactory = provider.GetRequiredService<WriterFactory>();
|
_writerFactory = writerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_reader.Dispose();
|
_reader?.Dispose();
|
||||||
_writer.Dispose();
|
_writer?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void Execute();
|
public abstract void Execute();
|
||||||
|
@ -2,15 +2,18 @@
|
|||||||
|
|
||||||
internal class ToolFactory
|
internal class ToolFactory
|
||||||
{
|
{
|
||||||
|
static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService<ReaderFactory>();
|
||||||
|
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
|
||||||
|
|
||||||
public Tool GetTool(string toolName)
|
public Tool GetTool(string toolName)
|
||||||
{
|
{
|
||||||
Tool tool = toolName switch
|
Tool tool = toolName switch
|
||||||
{
|
{
|
||||||
"export" => new ExportTool(RhSolutionsAddIn.ServiceProvider),
|
"export" => new ExportTool(readerFactory, writerFactory),
|
||||||
"convert" => new ConvertTool(RhSolutionsAddIn.ServiceProvider),
|
"convert" => new ConvertTool(readerFactory, writerFactory),
|
||||||
"merge" => new MergeTool(RhSolutionsAddIn.ServiceProvider),
|
"merge" => new MergeTool(readerFactory, writerFactory),
|
||||||
"dxfexport" => new DxfTool(RhSolutionsAddIn.ServiceProvider),
|
"dxfexport" => new DxfTool(readerFactory, writerFactory),
|
||||||
"guess" => new GuessTool(RhSolutionsAddIn.ServiceProvider),
|
"guess" => new GuessTool(readerFactory, writerFactory),
|
||||||
"fillsleeves" => new SleevesTool(RhSolutionsAddIn.ServiceProvider),
|
"fillsleeves" => new SleevesTool(RhSolutionsAddIn.ServiceProvider),
|
||||||
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user