Fix bar disposing

This commit is contained in:
Sergey Chebotar 2023-04-07 07:19:49 +03:00
parent f7eec55b4a
commit dfd0db9133
4 changed files with 12 additions and 4 deletions

View File

@ -63,7 +63,7 @@ public class RibbonController : ExcelRibbon
{ {
try try
{ {
ToolBase tool = control.Id switch using ToolBase tool = control.Id switch
{ {
"export" => new ExportTool(), "export" => new ExportTool(),
"convert" => new ConvertTool(), "convert" => new ConvertTool(),

View File

@ -1,8 +1,9 @@
namespace RhSolutions.Services; namespace RhSolutions.Services;
public interface IExcelReader public interface IExcelReader : IDisposable
{ {
public Dictionary<Product, double> ReadProducts(Range range); public Dictionary<Product, double> ReadProducts(Range range);
public List<(string, Dictionary<Product, double>)> ReadProducts(IEnumerable<Worksheet> worksheets); public List<(string, Dictionary<Product, double>)> ReadProducts(IEnumerable<Worksheet> worksheets);
public List<(string, Dictionary<Product, double>)> ReadProducts(string[] files); public List<(string, Dictionary<Product, double>)> ReadProducts(string[] files);
new void Dispose();
} }

View File

@ -1,7 +1,8 @@
namespace RhSolutions.Services; namespace RhSolutions.Services;
public interface IExcelWriter public interface IExcelWriter : IDisposable
{ {
public void WriteProducts(IEnumerable<(string, Dictionary<Product, double>)> products); public void WriteProducts(IEnumerable<(string, Dictionary<Product, double>)> products);
public void WriteProducts(Dictionary<Product, double> products); public void WriteProducts(Dictionary<Product, double> products);
new void Dispose();
} }

View File

@ -7,7 +7,7 @@ namespace RhSolutions.Tools;
#if !NET472 #if !NET472
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
#endif #endif
internal abstract class ToolBase internal abstract class ToolBase : IDisposable
{ {
protected readonly IExcelReader _reader; protected readonly IExcelReader _reader;
protected readonly IExcelWriter _writer; protected readonly IExcelWriter _writer;
@ -18,5 +18,11 @@ internal abstract class ToolBase
_writer = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IExcelWriter>(); _writer = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IExcelWriter>();
} }
public void Dispose()
{
_reader.Dispose();
_writer.Dispose();
}
public abstract void Execute(); public abstract void Execute();
} }