diff --git a/RhSolutions.AddIn/Controllers/RibbonController.cs b/RhSolutions.AddIn/Controllers/RibbonController.cs index 0e82060..efc0d15 100644 --- a/RhSolutions.AddIn/Controllers/RibbonController.cs +++ b/RhSolutions.AddIn/Controllers/RibbonController.cs @@ -63,7 +63,7 @@ public class RibbonController : ExcelRibbon { try { - ToolBase tool = control.Id switch + using ToolBase tool = control.Id switch { "export" => new ExportTool(), "convert" => new ConvertTool(), diff --git a/RhSolutions.AddIn/Services/IExcelReader.cs b/RhSolutions.AddIn/Services/IExcelReader.cs index a134e4c..897d452 100644 --- a/RhSolutions.AddIn/Services/IExcelReader.cs +++ b/RhSolutions.AddIn/Services/IExcelReader.cs @@ -1,8 +1,9 @@ namespace RhSolutions.Services; -public interface IExcelReader +public interface IExcelReader : IDisposable { public Dictionary ReadProducts(Range range); public List<(string, Dictionary)> ReadProducts(IEnumerable worksheets); public List<(string, Dictionary)> ReadProducts(string[] files); + new void Dispose(); } diff --git a/RhSolutions.AddIn/Services/IExcelWriter.cs b/RhSolutions.AddIn/Services/IExcelWriter.cs index 5d2ea29..ea6bf5a 100644 --- a/RhSolutions.AddIn/Services/IExcelWriter.cs +++ b/RhSolutions.AddIn/Services/IExcelWriter.cs @@ -1,7 +1,8 @@ namespace RhSolutions.Services; -public interface IExcelWriter +public interface IExcelWriter : IDisposable { public void WriteProducts(IEnumerable<(string, Dictionary)> products); public void WriteProducts(Dictionary products); + new void Dispose(); } diff --git a/RhSolutions.AddIn/Tools/ToolBase.cs b/RhSolutions.AddIn/Tools/ToolBase.cs index 9c37bc3..518cefe 100644 --- a/RhSolutions.AddIn/Tools/ToolBase.cs +++ b/RhSolutions.AddIn/Tools/ToolBase.cs @@ -7,7 +7,7 @@ namespace RhSolutions.Tools; #if !NET472 [SupportedOSPlatform("windows")] #endif -internal abstract class ToolBase +internal abstract class ToolBase : IDisposable { protected readonly IExcelReader _reader; protected readonly IExcelWriter _writer; @@ -18,5 +18,11 @@ internal abstract class ToolBase _writer = RhSolutionsAddIn.ServiceProvider.GetRequiredService(); } + public void Dispose() + { + _reader.Dispose(); + _writer.Dispose(); + } + public abstract void Execute(); } \ No newline at end of file